From 0ca67c14fe280684392764f3b4b7e573b6606ed5 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Tue, 14 Jan 2025 11:53:14 +0600 Subject: [PATCH] pkp/pkp-lib#10788 User group create/update/remove fix --- .../settings/roles/UserGroupGridHandler.php | 3 +-- .../settings/roles/form/UserGroupForm.php | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/controllers/grid/settings/roles/UserGroupGridHandler.php b/controllers/grid/settings/roles/UserGroupGridHandler.php index 1781b8c9110..51aa258b492 100644 --- a/controllers/grid/settings/roles/UserGroupGridHandler.php +++ b/controllers/grid/settings/roles/UserGroupGridHandler.php @@ -346,10 +346,9 @@ public function removeUserGroup($args, $request) $user = $request->getUser(); $userGroup = $this->_userGroup; - $contextId = $this->_getContextId(); $notificationMgr = new NotificationManager(); - $usersAssignedToUserGroupCount = $userGroup->usersInContext($contextId)->count(); + $usersAssignedToUserGroupCount = $userGroup->userUserGroups()->count(); if ($usersAssignedToUserGroupCount == 0) { if ($userGroup->isDefault) { diff --git a/controllers/grid/settings/roles/form/UserGroupForm.php b/controllers/grid/settings/roles/form/UserGroupForm.php index 5bfa54a65fe..7009b30f521 100644 --- a/controllers/grid/settings/roles/form/UserGroupForm.php +++ b/controllers/grid/settings/roles/form/UserGroupForm.php @@ -232,11 +232,11 @@ public function execute(...$functionParams) if (in_array($userGroup->roleId, Repo::userGroup()::NOT_CHANGE_METADATA_EDIT_PERMISSION_ROLES)) { $userGroup->permitMetadataEdit = true; } else { - $userGroup->permitMetadataEdit = $this->getData('permitMetadataEdit') ?? false; + $userGroup->permitMetadataEdit = (bool) $this->getData('permitMetadataEdit'); } $userGroup->recommendOnly = $this->getData('recommendOnly') && in_array($userGroup->roleId, $this->getRecommendOnlyRoles()); - $userGroup->masthead = $this->getData('masthead') ?? false; + $userGroup->masthead = (bool) $this->getData('masthead'); // set localized fields $userGroup = $this->_setUserGroupLocaleFields($userGroup, $request); @@ -251,7 +251,7 @@ public function execute(...$functionParams) // update localized fields $userGroup = $this->_setUserGroupLocaleFields($userGroup, $request); $userGroup->permitSettings = $this->getData('permitSettings') && $userGroup->getRoleId() == Role::ROLE_ID_MANAGER; - $userGroup->showTitle = $this->getData('showTitle') ?? false; + $userGroup->showTitle = (bool) $this->getData('showTitle'); $userGroup->permitSelfRegistration = $this->getData('permitSelfRegistration') && in_array($userGroup->roleId, $this->getPermitSelfRegistrationRoles()); $previousPermitMetadataEdit = $userGroup->permitMetadataEdit; @@ -276,7 +276,7 @@ public function execute(...$functionParams) } $userGroup->recommendOnly = $this->getData('recommendOnly') && in_array($userGroup->roleId, $this->getRecommendOnlyRoles()); - $userGroup->masthead = $this->getData('masthead') ?? false; + $userGroup->masthead = (bool) $this->getData('masthead'); $userGroup->save(); } @@ -355,22 +355,27 @@ public function _setUserGroupLocaleFields($userGroup, $request): \PKP\userGroup\ $supportedLocales = $context->getSupportedLocales(); $name = $this->getData('name'); $abbrev = $this->getData('abbrev'); + $userGroupNames = $userGroup->name; + $userGroupAbbrevs = $userGroup->abbrev; if (!empty($supportedLocales)) { foreach ($supportedLocales as $localeKey) { if (isset($name[$localeKey])) { - $userGroup->name[$localeKey] = $name[$localeKey]; + $userGroupNames[$localeKey] = $name[$localeKey]; } if (isset($abbrev[$localeKey])) { - $userGroup->abbrev[$localeKey] = $abbrev[$localeKey]; + $userGroupAbbrevs[$localeKey] = $abbrev[$localeKey]; } } } else { $localeKey = Locale::getLocale(); - $userGroup->name[$localeKey] = $name[$localeKey] ?? ''; - $userGroup->abbrev[$localeKey] = $abbrev[$localeKey] ?? ''; + $userGroupNames[$localeKey] = $name[$localeKey] ?? ''; + $userGroupAbbrevs[$localeKey] = $abbrev[$localeKey] ?? ''; } + $userGroup->name = $userGroupNames; + $userGroup->abbrev = $userGroupAbbrevs; + return $userGroup; } }