Make `UserAction::prepareRemoveContent()` work with multiple users
authorjoshuaruesweg <ruesweg@woltlab.com>
Wed, 16 Dec 2020 15:25:59 +0000 (16:25 +0100)
committerjoshuaruesweg <ruesweg@woltlab.com>
Wed, 6 Jan 2021 14:31:51 +0000 (15:31 +0100)
wcfsetup/install/files/lib/data/user/UserAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 881bfda5cbae94fa8e8033adcc7fc5f09d019e98..38b8d2fbf8c36f9eb7bd3096234aa0e77ab4dc0b 100644 (file)
@@ -1008,8 +1008,10 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                return [
                        'template' => WCF::getTPL()->fetch('removeUserContentDialog', 'wcf', [
                                'knownContentProvider' => $knownContentProvider,
-                               'userID' => $this->parameters['userID'],
-                               'user' => $this->parameters['user']
+                               'userIDs' => $this->parameters['userIDs'],
+                               'users' => $this->parameters['users'],
+                               'userID' => $this->parameters['userID'] ?? null,
+                               'user' => $this->parameters['user'] ?? null,
                        ])
                ];
        }
@@ -1020,14 +1022,35 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
         * @since       5.2
         */
        public function validatePrepareRemoveContent() {
-               if (!isset($this->parameters['userID'])) {
-                       throw new \InvalidArgumentException("userID missing");
+               if (!isset($this->parameters['userIDs']) && isset($this->parameters['userID'])) {
+                       $this->parameters['userIDs'] = [$this->parameters['userID']];
                }
                
-               $this->parameters['user'] = new User($this->parameters['userID']);
+               if (!isset($this->parameters['userIDs']) || !is_array($this->parameters['userIDs'])) {
+                       throw new \InvalidArgumentException("Parameter 'userIDs' is missing or invalid.");
+               }
                
-               if ($this->parameters['user']->userID && !$this->parameters['user']->canEdit()) {
-                       throw new PermissionDeniedException();
+               $userList = new UserList();
+               $userList->setObjectIDs($this->parameters['userIDs']);
+               $userList->readObjects();
+               $userObjects = $userList->getObjects();
+               
+               $this->parameters['users'] = [];
+               foreach ($this->parameters['userIDs'] as $userID) {
+                       if (!isset($userObjects[$userID])) {
+                               throw new \InvalidArgumentException("The userID '". $userID ."' is unknown.");
+                       }
+                       
+                       if (!$userObjects[$userID]->canEdit()) {
+                               throw new PermissionDeniedException();
+                       }
+                       
+                       $this->parameters['users'][] = $userObjects[$userID];
+               }
+               
+               if (count($this->parameters['userIDs']) === 1) {
+                       $this->parameters['userID'] = reset($this->parameters['userIDs']);
+                       $this->parameters['user'] = reset($this->parameters['users']); 
                }
        }
        
index 8f31c119965ef57700f444e67bff61ad4111f27f..5b95ebf0930b19a87cba5edce6d7eb61099ff00e 100644 (file)
        <category name="wcf.acp.content">
                <item name="wcf.acp.content.removeContent"><![CDATA[Inhalte des Benutzers löschen]]></item>
                <item name="wcf.acp.content.provider.removeContentSectionTitle"><![CDATA[Inhalte]]></item>
-               <item name="wcf.acp.content.provider.removeContentInfo"><![CDATA[Bitte {if LANGUAGE_USE_INFORMAL_VARIANT}wähle{else}wählen Sie{/if} aus, welche Inhalte vom Benutzer „<a href="{link controller='UserEdit' id=$user->userID}{/link}">{$user->username}</a>“ gelöscht werden sollen.]]></item>
+               <item name="wcf.acp.content.provider.removeContentInfo"><![CDATA[Bitte {if LANGUAGE_USE_INFORMAL_VARIANT}wähle{else}wählen Sie{/if} aus, welche Inhalte {if $users|count == 1}vom Benutzer „<a href="{link controller='UserEdit' id=$user->userID}{/link}">{$user->username}</a>“{else}von {#$users|count} Benutzern{/if} gelöscht werden sollen.]]></item>
                <item name="wcf.acp.content.provider.removeContentWarning"><![CDATA[<strong>Achtung</strong>: Der ausgewählte Inhalt wird nach dem Absenden <strong>unwiderruflich und ohne zusätzliche Sicherheitsabfrage</strong> gelöscht!]]></item>
                <item name="wcf.acp.content.provider.com.woltlab.wcf.comment"><![CDATA[Kommentare]]></item>
                <item name="wcf.acp.content.provider.com.woltlab.wcf.commentResponse"><![CDATA[Antworten auf Kommentare]]></item>
index 4ca3a662839eeda93f475776d5346de01bca24f7..5016fae1259b63b66de8fc655bd059b3917df4a9 100644 (file)
@@ -3453,7 +3453,7 @@ Attachments:
        <category name="wcf.acp.content">
                <item name="wcf.acp.content.removeContent"><![CDATA[Delete User’s Content]]></item>
                <item name="wcf.acp.content.provider.removeContentSectionTitle"><![CDATA[Content]]></item>
-               <item name="wcf.acp.content.provider.removeContentInfo"><![CDATA[Select which types of content created by “<a href="{link controller='UserEdit' id=$user->userID}{/link}">{$user->username}</a>” should be deleted.]]></item>
+               <item name="wcf.acp.content.provider.removeContentInfo"><![CDATA[Select which types of content created by {if $users|count == 1}“<a href="{link controller='UserEdit' id=$user->userID}{/link}">{$user->username}</a>”{else}{#$users|count} users{/if} should be deleted.]]></item>
                <item name="wcf.acp.content.provider.removeContentWarning"><![CDATA[<strong>Heads up</strong>: The content will be deleted irrevocably and without any further confirmation prompt!]]></item>
                <item name="wcf.acp.content.provider.com.woltlab.wcf.comment"><![CDATA[Comments]]></item>
                <item name="wcf.acp.content.provider.com.woltlab.wcf.commentResponse"><![CDATA[Comment Responses]]></item>