From: Matthias Schmidt Date: Sun, 7 Jun 2020 11:19:15 +0000 (+0200) Subject: Support copying all user groups X-Git-Tag: 5.3.0_Alpha_1~226^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=44c314609b17d5c36bbfe04ec514427f8c17b42f;p=GitHub%2FWoltLab%2FWCF.git Support copying all user groups See #3238 --- diff --git a/wcfsetup/install/files/acp/templates/userGroupAdd.tpl b/wcfsetup/install/files/acp/templates/userGroupAdd.tpl index 4827efa516..a7e2ba3141 100644 --- a/wcfsetup/install/files/acp/templates/userGroupAdd.tpl +++ b/wcfsetup/install/files/acp/templates/userGroupAdd.tpl @@ -4,7 +4,7 @@ $(function() { new WCF.Option.Handler(); - {if $action == 'edit' && $group->groupType == 4 && $__wcf->session->getPermission('admin.user.canAddGroup')} + {if $action == 'edit' && $group->canCopy()} WCF.Language.addObject({ 'wcf.acp.group.copy.confirmMessage': '{lang}wcf.acp.group.copy.confirmMessage{/lang}', 'wcf.acp.group.copy.copyACLOptions': '{lang}wcf.acp.group.copy.copyACLOptions{/lang}', @@ -53,7 +53,7 @@ {/if} - {if $__wcf->session->getPermission('admin.user.canAddGroup') && $group->groupType == 4} + {if $group->canCopy()}
  • {lang}wcf.acp.group.button.copy{/lang}
  • {/if} {/if} diff --git a/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php b/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php index 451b4b3470..c0382946e4 100644 --- a/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php +++ b/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php @@ -227,13 +227,23 @@ class UserGroup extends DatabaseObject implements ITitledObject { /** * Returns true if this is the 'Owner' group. * - * @return bool - * @since 5.2 + * @return bool + * @since 5.2 */ public function isOwner() { return $this->groupType == self::OWNER; } + /** + * Returns `true` if the active user can copy this user group. + * + * @return bool + * @since 5.3 + */ + public function canCopy() { + return WCF::getSession()->getPermission('admin.user.canAddGroup') && $this->isAccessible(); + } + /** * Returns true if the given groups are accessible for the active user. * diff --git a/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php b/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php index 5d24644c33..30d03db4a6 100644 --- a/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php +++ b/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php @@ -94,7 +94,7 @@ class UserGroupAction extends AbstractDatabaseObjectAction { $this->readBoolean('copyUserGroupOptions'); $this->groupEditor = $this->getSingleObject(); - if (!$this->groupEditor->isAccessible() || $this->groupEditor->groupType != UserGroup::OTHER) { + if (!$this->groupEditor->canCopy()) { throw new PermissionDeniedException(); } } @@ -120,18 +120,25 @@ class UserGroupAction extends AbstractDatabaseObjectAction { $optionValues = $statement->fetchMap('optionID', 'optionValue'); - $groupAction = new UserGroupAction([], 'create', [ + $groupType = $this->groupEditor->groupType; + // When copying special user groups of which only one may exist, + // change the group type to 'other'. + if (in_array($groupType, [UserGroup::EVERYONE, UserGroup::GUESTS, UserGroup::USERS, UserGroup::OWNER])) { + $groupType = UserGroup::OTHER; + } + + /** @var UserGroup $group */ + $group = (new UserGroupAction([], 'create', [ 'data' => [ 'groupName' => $this->groupEditor->groupName, 'groupDescription' => $this->groupEditor->groupDescription, 'priority' => $this->groupEditor->priority, 'userOnlineMarking' => $this->groupEditor->userOnlineMarking, - 'showOnTeamPage' => $this->groupEditor->showOnTeamPage + 'showOnTeamPage' => $this->groupEditor->showOnTeamPage, + 'groupType' => $groupType, ], - 'options' => $optionValues - ]); - $returnValues = $groupAction->executeAction(); - $group = $returnValues['returnValues']; + 'options' => $optionValues, + ]))->executeAction()['returnValues']; $groupEditor = new UserGroupEditor($group); // update group name @@ -169,7 +176,7 @@ class UserGroupAction extends AbstractDatabaseObjectAction { $groupEditor->update([ 'groupDescription' => $groupDescription, - 'groupName' => $groupName + 'groupName' => $groupName, ]); // copy members @@ -209,8 +216,8 @@ class UserGroupAction extends AbstractDatabaseObjectAction { return [ 'groupID' => $group->groupID, 'redirectURL' => LinkHandler::getInstance()->getLink('UserGroupEdit', [ - 'id' => $group->groupID - ]) + 'id' => $group->groupID, + ]), ]; }