From bbef7ed8c4c68d531179896ea25d1468005e92b9 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 2 May 2013 22:45:47 +0200 Subject: [PATCH] Added user ban function --- com.woltlab.wcf/clipboardAction.xml | 16 ++++++-- wcfsetup/install/files/acp/js/WCF.ACP.js | 26 +++++++++++++ .../files/lib/data/user/UserAction.class.php | 17 ++++++++ .../action/UserClipboardAction.class.php | 39 +++++++++++++++---- wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 6 files changed, 88 insertions(+), 12 deletions(-) diff --git a/com.woltlab.wcf/clipboardAction.xml b/com.woltlab.wcf/clipboardAction.xml index 2be2193f02..42bc692bb9 100644 --- a/com.woltlab.wcf/clipboardAction.xml +++ b/com.woltlab.wcf/clipboardAction.xml @@ -9,25 +9,33 @@ - + 2 - - + + 3 + + + + 4 + + + + - 4 + 5 diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 22f58eb772..9fe1300af9 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -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 diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index 5d1f762752..4ca3e19ed9 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -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 $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')); + } + } } diff --git a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php index 0b0fe57652..e3acc40444 100644 --- a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php @@ -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 + */ + 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 + */ + 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']; } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index f11e5ff74a..48948bba98 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -793,6 +793,7 @@ + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 70166774ad..7dc991b309 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -793,6 +793,7 @@ + -- 2.20.1