Added user ban function
authorMarcel Werk <burntime@woltlab.com>
Thu, 2 May 2013 20:45:47 +0000 (22:45 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 2 May 2013 20:45:47 +0000 (22:45 +0200)
com.woltlab.wcf/clipboardAction.xml
wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/lib/data/user/UserAction.class.php
wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 2be2193f025e81e08f2891fd39b3dc72e417e3f9..42bc692bb9a432174130ce63363411ad473c913d 100644 (file)
@@ -9,25 +9,33 @@
                        </pages>
                </action>
                
-               <action name="sendMail">
+               <action name="delete">
                        <actionclassname><![CDATA[wcf\system\clipboard\action\UserClipboardAction]]></actionclassname>
                        <showorder>2</showorder>
                        <pages>
                                <page><![CDATA[wcf\acp\page\UserListPage]]></page>
                        </pages>
                </action>
-
-               <action name="delete">
+               
+               <action name="ban">
                        <actionclassname><![CDATA[wcf\system\clipboard\action\UserClipboardAction]]></actionclassname>
                        <showorder>3</showorder>
                        <pages>
                                <page><![CDATA[wcf\acp\page\UserListPage]]></page>
                        </pages>
                </action>
+               
+               <action name="sendMail">
+                       <actionclassname><![CDATA[wcf\system\clipboard\action\UserClipboardAction]]></actionclassname>
+                       <showorder>4</showorder>
+                       <pages>
+                               <page><![CDATA[wcf\acp\page\UserListPage]]></page>
+                       </pages>
+               </action>
 
                <action name="exportMailAddress">
                        <actionclassname><![CDATA[wcf\system\clipboard\action\UserClipboardAction]]></actionclassname>
-                       <showorder>4</showorder>
+                       <showorder>5</showorder>
                        <pages>
                                <page><![CDATA[wcf\acp\page\UserListPage]]></page>
                        </pages>
index 22f58eb772566858480556d9ef1362812ab5bb52..9fe1300af9fa5c7e9272dd5e53997a5389c58479 100644 (file)
@@ -1775,6 +1775,30 @@ WCF.ACP.User.BanHandler = {
                                this.ban([ $button.data('objectID') ]);
                        }
                }, this));
+               
+               // bind listener
+               $('.jsClipboardEditor').each($.proxy(function(index, container) {
+                       var $container = $(container);
+                       var $types = eval($container.data('types'));
+                       if (WCF.inArray('com.woltlab.wcf.user', $types)) {
+                               $container.on('clipboardAction', $.proxy(this._execute, this));
+                               return false;
+                       }
+               }, this));
+       },
+       
+       /**
+        * Handles clipboard actions.
+        * 
+        * @param       object          event
+        * @param       string          type
+        * @param       string          actionName
+        * @param       object          parameters
+        */
+       _execute: function(event, type, actionName, parameters) {
+               if (actionName == 'com.woltlab.wcf.user.ban') {
+                       this.ban(parameters.objectIDs);
+               }
        },
        
        /**
@@ -1834,5 +1858,7 @@ WCF.ACP.User.BanHandler = {
                
                var $notification = new WCF.System.Notification();
                $notification.show();
+               
+               WCF.Clipboard.reload();
        }
 };
\ No newline at end of file
index 5d1f762752a839c9fc2c5576c342c546558f8ab6..4ca3e19ed96263bf92b3a8b1ab487da5bdcbfa8c 100644 (file)
@@ -163,6 +163,8 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                $statement->execute(
                        array_merge(array(1, $this->parameters['banReason']), $conditionBuilder->getParameters())               
                );
+               
+               $this->unmarkItems();
        }
        
        /**
@@ -329,4 +331,19 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
        public function unmarkAll() {
                ClipboardHandler::getInstance()->removeItems(ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user'));
        }
+       
+       /**
+        * Unmarks users.
+        *
+        * @param       array<integer>          $userIDs
+        */
+       protected function unmarkItems(array $userIDs = array()) {
+               if (empty($userIDs)) {
+                       $userIDs = $this->objectIDs;
+               }
+       
+               if (!empty($userIDs)) {
+                       ClipboardHandler::getInstance()->unmark($userIDs, ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user'));
+               }
+       }
 }
index 0b0fe57652ee3c5b74e1b07b18e7bcf53aff67fc..e3acc404441e10a0d73c7ca67c84a2660e537cf6 100644 (file)
@@ -24,7 +24,7 @@ class UserClipboardAction extends AbstractClipboardAction {
        /**
         * @see wcf\system\clipboard\action\AbstractClipboardAction::$supportedActions
         */
-       protected $supportedActions = array('assignToGroup', 'delete', 'exportMailAddress', 'sendMail');
+       protected $supportedActions = array('assignToGroup', 'ban', 'delete', 'exportMailAddress', 'sendMail');
        
        /**
         * @see wcf\system\clipboard\action\IClipboardAction::execute()
@@ -82,14 +82,37 @@ class UserClipboardAction extends AbstractClipboardAction {
        protected function validateDelete() {
                // check permissions
                if (!WCF::getSession()->getPermission('admin.user.canDeleteUser')) {
-                       return 0;
+                       return array();
                }
                
-               // user cannot delete itself
-               $userIDs = array_keys($this->objects);
-               foreach ($userIDs as $index => $userID) {
-                       if ($userID == WCF::getUser()->userID) {
-                               unset($userIDs[$index]);
+               return $this->__validateAccessibleGroups(array_keys($this->objects));
+       }
+       
+       /**
+        * Returns the ids of the users which can be banned.
+        *
+        * @return      array<integer>
+        */
+       protected function validateBan() {
+               // check permissions
+               if (!WCF::getSession()->getPermission('admin.user.canBanUser')) {
+                       return array();
+               }
+               
+               return $this->__validateAccessibleGroups(array_keys($this->objects));
+       }
+       
+       /**
+        * Validates accessible groups.
+        *
+        * @return      array<integer>
+        */
+       protected function __validateAccessibleGroups(array $userIDs, $ignoreOwnUser = true) {
+               if ($ignoreOwnUser) {
+                       foreach ($userIDs as $index => $userID) {
+                               if ($userID == WCF::getUser()->userID) {
+                                       unset($userIDs[$index]);
+                               }
                        }
                }
                
@@ -111,7 +134,7 @@ class UserClipboardAction extends AbstractClipboardAction {
                        if (!isset($userToGroup[$row['userID']])) {
                                $userToGroup[$row['userID']] = array();
                        }
-                       
+                               
                        $userToGroup[$row['userID']][] = $row['groupID'];
                }
                
index f11e5ff74a5b5df606375b464b2ecd8a63b05ee5..48948bba98979721004c2c9312c5600a214da343 100644 (file)
        <category name="wcf.clipboard">
                <item name="wcf.clipboard.item.unmarkAll"><![CDATA[Demarkieren]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.user.assignToGroup"><![CDATA[Benutzergruppe zuweisen]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.ban"><![CDATA[Sperren ({#$count})]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.user.delete"><![CDATA[Löschen ({#$count})]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.user.delete.confirmMessage"><![CDATA[{if $count == 1}Einen{else}{#$count}{/if} Benutzer löschen?]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.user.exportMailAddress"><![CDATA[E-Mail-Adressen exportieren]]></item>
index 70166774adafe398e6bde0ecfec6094e902c3f2a..7dc991b309e255940059510a41288dca322219d3 100644 (file)
        <category name="wcf.clipboard">
                <item name="wcf.clipboard.item.unmarkAll"><![CDATA[Unmark All]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.user.assignToGroup"><![CDATA[Assign to User Group]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.ban"><![CDATA[TODO: Sperren ({#$count})]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.user.delete"><![CDATA[Delete ({#$count})]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.user.delete.confirmMessage"><![CDATA[Do you really want to delete {#$count} user{if $count != 1}s{/if}?]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.user.exportMailAddress"><![CDATA[Export Email addresses]]></item>