Skip to content

Commit

Permalink
pkp#10788 User group create/update/remove fix
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Jan 14, 2025
1 parent c5ebc05 commit 0ca67c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions controllers/grid/settings/roles/UserGroupGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 13 additions & 8 deletions controllers/grid/settings/roles/form/UserGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 0ca67c1

Please sign in to comment.