Support copying all user groups
authorMatthias Schmidt <gravatronics@live.com>
Sun, 7 Jun 2020 11:19:15 +0000 (13:19 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 7 Jun 2020 11:57:56 +0000 (13:57 +0200)
See #3238

wcfsetup/install/files/acp/templates/userGroupAdd.tpl
wcfsetup/install/files/lib/data/user/group/UserGroup.class.php
wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php

index 4827efa5163baea8ed847d63138ae5ab9ae6a735..a7e2ba314184edd6549c58cca1316d3d570bb9c3 100644 (file)
@@ -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 @@
                                        </li>
                                {/if}
                                
-                               {if $__wcf->session->getPermission('admin.user.canAddGroup') && $group->groupType == 4}
+                               {if $group->canCopy()}
                                        <li><a class="jsButtonUserGroupCopy button"><span class="icon icon16 fa-copy"></span> <span>{lang}wcf.acp.group.button.copy{/lang}</span></a></li>
                                {/if}
                        {/if}
index 451b4b3470971a1d1313ef6af3c7f60dfa1c9689..c0382946e4a57d5764f54827a88a2bf8e3e8737c 100644 (file)
@@ -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.
         * 
index 5d24644c3367d126ecd5e00cd4e838bae63b61c4..30d03db4a6391f5e6ee8f6f5a807b6f73ed6f865 100644 (file)
@@ -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,
+                       ]),
                ];
        }