Added user ban function
authorMarcel Werk <burntime@woltlab.com>
Thu, 2 May 2013 13:45:48 +0000 (15:45 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 2 May 2013 13:45:48 +0000 (15:45 +0200)
wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/userList.tpl
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/acp/page/UserListPage.class.php
wcfsetup/install/files/lib/data/user/UserAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 81d70fade3069ec4877bd292f54615a065f49d93..22f58eb772566858480556d9ef1362812ab5bb52 100644 (file)
@@ -1729,3 +1729,110 @@ WCF.ACP.Search = WCF.Search.Base.extend({
                window.location = this._list.find('li.dropdownNavigationItem > a').attr('href');
        }
 });
+
+/**
+ * Namespace for user management.
+ */
+WCF.ACP.User = { };
+
+/**
+ * Generic implementation to ban users.
+ */
+WCF.ACP.User.BanHandler = {
+       /**
+        * callback object
+        * @var object
+        */
+       _callback: null,
+       
+       /**
+        * dialog overlay
+        * @var jQuery
+        */
+       _dialog: null,
+       
+       /**
+        * action proxy
+        * @var WCF.Action.Proxy
+        */
+       _proxy: null,
+       
+       /**
+        * Initializes WCF.ACP.User.BanHandler on first use.
+        */
+       init: function() {
+               this._dialog = $('<div />').hide().appendTo(document.body);
+               this._proxy = new WCF.Action.Proxy({
+                       success: $.proxy(this._success, this)
+               });
+               
+               $('.jsBanButton').click($.proxy(function(event) {
+                       var $button = $(event.currentTarget);
+                       if ($button.data('banned')) {
+                               this.unban([ $button.data('objectID') ]);
+                       }
+                       else {
+                               this.ban([ $button.data('objectID') ]);
+                       }
+               }, this));
+       },
+       
+       /**
+        * Unbans users.
+        * 
+        * @param       array<integer>  userIDs
+        */
+       unban: function(userIDs) {
+               this._proxy.setOption('data', {
+                       actionName: 'unban',
+                       className: 'wcf\\data\\user\\UserAction',
+                       objectIDs: userIDs
+               });
+               this._proxy.sendRequest();
+       },
+       
+       /**
+        * Bans users.
+        * 
+        * @param       array<integer>  userIDs
+        */
+       ban: function(userIDs) {
+               WCF.System.Confirmation.show(WCF.Language.get('wcf.acp.user.ban.sure'), $.proxy(function(action) {
+                       if (action === 'confirm') {
+                               this._proxy.setOption('data', {
+                                       actionName: 'ban',
+                                       className: 'wcf\\data\\user\\UserAction',
+                                       objectIDs: userIDs,
+                                       parameters: {
+                                               banReason: $('#userBanReason').val()
+                                       }
+                               });
+                               this._proxy.sendRequest();
+                       }
+               }, this), '', $('<fieldset><dl><dt><label for="userBanReason">' + WCF.Language.get('wcf.acp.user.banReason') + '</label></dt><dd><textarea id="userBanReason" cols="40" rows="3" /><small>' + WCF.Language.get('wcf.acp.user.banReason.description') + '</small></dd></dl></fieldset>'));
+       },
+       
+       /**
+        * Handles successful AJAX calls.
+        * 
+        * @param       object          data
+        * @param       string          textStatus
+        * @param       jQuery          jqXHR
+        */
+       _success: function(data, textStatus, jqXHR) {
+               $('.jsBanButton').each(function(index, button) {
+                       var $button = $(button);
+                       if (WCF.inArray($button.data('objectID'), data.objectIDs)) {
+                               if (data.actionName == 'unban') {
+                                       $button.data('banned', false).data('tooltip', $button.data('banMessage')).removeClass('icon-lock').addClass('icon-unlock');
+                               }
+                               else {
+                                       $button.data('banned', true).data('tooltip', $button.data('unbanMessage')).removeClass('icon-unlock').addClass('icon-lock');
+                               }
+                       }
+               });
+               
+               var $notification = new WCF.System.Notification();
+               $notification.show();
+       }
+};
\ No newline at end of file
index 6014197b3ae64bdd4f6570e43eef87251eb121e0..e5728c81c107bc4a2e4e2faf1e48f8822a613a9c 100644 (file)
                {/if}
                
                new WCF.Table.EmptyTableHandler($('#userTableContainer'), 'jsUserRow', options);
+               
+               WCF.Language.addObject({
+                       'wcf.acp.user.banReason': '{lang}wcf.acp.user.banReason{/lang}',
+                       'wcf.acp.user.banReason.description': '{lang}wcf.acp.user.banReason.description{/lang}',
+                       'wcf.acp.user.ban.sure': '{lang}wcf.acp.user.ban.sure{/lang}'
+               });
+               WCF.ACP.User.BanHandler.init();
        });
        //]]>
 </script>
                                                        {else}
                                                                <span class="icon icon16 icon-remove disabled" title="{lang}wcf.global.button.delete{/lang}"></span>
                                                        {/if}
+                                                       {if $user->bannable}
+                                                               <span class="icon icon16 icon-{if $user->banned}lock{else}unlock{/if} jsBanButton jsTooltip pointer" title="{lang}wcf.acp.user.{if $user->banned}unban{else}ban{/if}{/lang}" data-object-id="{@$user->userID}" data-ban-message="{lang}wcf.acp.user.ban{/lang}" data-unban-message="{lang}wcf.acp.user.unban{/lang}" data-banned="{if $user->banned}true{else}false{/if}"></span>
+                                                       {else}
+                                                               <span class="icon icon16 icon-{if $user->banned}lock{else}unlock{/if} disabled" title="{lang}wcf.acp.user.{if $user->banned}unban{else}ban{/if}{/lang}"></span>
+                                                       {/if}
                                                        
                                                        {event name='rowButtons'}
                                                </td>
index a8ca282a0e7ee7a81d4e6fe9867696b8a7c1f2c7..f6d799849e59b2c994637b4a655b274d88e2b55b 100755 (executable)
@@ -5430,7 +5430,7 @@ WCF.System.Notification = Class.extend({
         */
        init: function(message, cssClassNames) {
                this._cssClassNames = cssClassNames || 'success';
-               this._message = message;
+               this._message = message || WCF.Language.get('wcf.global.success');
                this._overlay = $('#systemNotification');
                
                if (!this._overlay.length) {
index 456a8299ba046af5ea8122b29dd21515dcfcea09..a2416a43d6719ad97ff7d1cabeab967a678e71d9 100755 (executable)
@@ -245,6 +245,7 @@ class UserListPage extends SortablePage {
                                $row['accessible'] = $accessible;
                                $row['deletable'] = ($accessible && WCF::getSession()->getPermission('admin.user.canDeleteUser') && $row['userID'] != WCF::getUser()->userID) ? 1 : 0;
                                $row['editable'] = ($accessible && WCF::getSession()->getPermission('admin.user.canEditUser')) ? 1 : 0;
+                               $row['bannable'] = ($accessible && WCF::getSession()->getPermission('admin.user.canBanUser') && $row['userID'] != WCF::getUser()->userID) ? 1 : 0;
                                $row['isMarked'] = intval(in_array($row['userID'], $this->markedUsers));
                                
                                $this->users[] = new User(null, $row);
index 13b40954aabf20320e43b2f94bb28280faf33897..5d1f762752a839c9fc2c5576c342c546558f8ab6 100644 (file)
@@ -55,30 +55,28 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
        }
        
        /**
-        * Validates permissions and parameters.
+        * Validates accessible groups.
+        * 
+        * @param       boolean         $ignoreOwnUser
         */
-       public function validateDelete() {
-               // read and validate user objects
-               parent::validateDelete();
-               
-               $userIDs = array();
-               foreach ($this->objects as $user) {
-                       // you cannot delete yourself
-                       if ($user->userID == WCF::getUser()->userID) {
-                               continue;
+       protected function __validateAccessibleGroups($ignoreOwnUser = true) {
+               if ($ignoreOwnUser) {
+                       if (in_array(WCF::getUser()->userID, $this->objectIDs)) {
+                               unset($this->objectIDs[array_search(WCF::getUser()->userID, $this->objectIDs)]);
+                               if (isset($this->objects[WCF::getUser()->userID])) {
+                                       unset($this->objects[WCF::getUser()->userID]);
+                               }
                        }
-                       
-                       $userIDs[] = $user->userID;
                }
                
                // list might be empty because only our own user id was given
-               if (empty($userIDs)) {
+               if (empty($this->objectIDs)) {
                        throw new UserInputException('objectIDs');
                }
                
                // validate groups
                $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add("userID IN (?)", array($userIDs));
+               $conditions->add("userID IN (?)", array($this->objectIDs));
                
                $sql = "SELECT  DISTINCT groupID
                        FROM    wcf".WCF_N."_user_to_group
@@ -96,6 +94,16 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                }
        }
        
+       /**
+        * Validates permissions and parameters.
+        */
+       public function validateDelete() {
+               // read and validate user objects
+               parent::validateDelete();
+               
+               $this->__validateAccessibleGroups();
+       }
+       
        /**
         * Validates permissions and parameters.
         */
@@ -125,6 +133,51 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                }
        }
        
+       /**
+        * Validates the ban action.
+        */
+       public function validateBan() {
+               WCF::getSession()->checkPermissions(array('admin.user.canBanUser'));
+               
+               $this->__validateAccessibleGroups();
+       }
+       
+       /**
+        * Validates the unban action.
+        */
+       public function validateUnban() {
+               $this->validateBan();
+       }
+       
+       /**
+        * Bans users.
+        */
+       public function ban() {
+               $conditionBuilder = new PreparedStatementConditionBuilder();
+               $conditionBuilder->add('userID IN (?)', array($this->objectIDs));
+               $sql = "UPDATE  wcf".WCF_N."_user
+                       SET     banned = ?,
+                               banReason = ?
+                       ".$conditionBuilder;
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(
+                       array_merge(array(1, $this->parameters['banReason']), $conditionBuilder->getParameters())               
+               );
+       }
+       
+       /**
+        * Unbans users.
+        */
+       public function unban() {
+               $conditionBuilder = new PreparedStatementConditionBuilder();
+               $conditionBuilder->add('userID IN (?)', array($this->objectIDs));
+               $sql = "UPDATE  wcf".WCF_N."_user
+                       SET     banned = 0
+                       ".$conditionBuilder;
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute($conditionBuilder->getParameters());
+       }
+       
        /**
         * Creates a new user.
         * 
index 42bac98394f8f02b4dfa428c08c5092b64fe0d53..f11e5ff74a5b5df606375b464b2ecd8a63b05ee5 100644 (file)
                <item name="wcf.acp.user.banUser.description"><![CDATA[Der Benutzer wird dauerhaft von der Nutzung aller Funktionen ausgeschlossen und erhält beim Aufruf der Seite eine entsprechende Fehlermeldung.]]></item>
                <item name="wcf.acp.user.banReason"><![CDATA[Begründung]]></item>
                <item name="wcf.acp.user.banReason.description"><![CDATA[Die Begründung wird dem gesperrten Benutzer beim Aufruf der Seite angezeigt.]]></item>
+               <item name="wcf.acp.user.ban"><![CDATA[Sperren]]></item>
+               <item name="wcf.acp.user.unban"><![CDATA[Sperrung aufheben]]></item>
+               <item name="wcf.acp.user.ban.sure"><![CDATA[Wollen Sie den/die Benutzer wirklich sperren?]]></item>
                <item name="wcf.acp.user.delete.sure"><![CDATA[Wollen Sie Benutzer „{$user->username}“ wirklich löschen?]]></item>
                <item name="wcf.acp.user.edit"><![CDATA[Benutzer bearbeiten]]></item>
                <item name="wcf.acp.user.edit.warning.selfEdit"><![CDATA[Sie bearbeiten Ihr eigenes Benutzerkonto. Änderungen an den Mitgliedschaften in Benutzergruppen können womöglich dazu führen, dass Sie aus der Administrationsoberfläche ausgeschlossen werden. Bitte seien Sie entsprechend vorsichtig!]]></item>
index 5a1e4d304cf3da44cb6a63dcbe451b6dc10471c0..70166774adafe398e6bde0ecfec6094e902c3f2a 100644 (file)
                <item name="wcf.acp.user.banUser.description"><![CDATA[TODO: Der Benutzer wird dauerhaft von der Nutzung aller Funktionen ausgeschlossen und erhält beim Aufruf der Seite eine entsprechende Fehlermeldung.]]></item>
                <item name="wcf.acp.user.banReason"><![CDATA[TODO: Begründung]]></item>
                <item name="wcf.acp.user.banReason.description"><![CDATA[TODO: Die Begründung wird dem gesperrten Benutzer beim Aufruf der Seite angezeigt.]]></item>
+               <item name="wcf.acp.user.ban"><![CDATA[TODO: Sperren]]></item>
+               <item name="wcf.acp.user.unban"><![CDATA[TODO: Sperrung aufheben]]></item>
+               <item name="wcf.acp.user.ban.sure"><![CDATA[TODO: Wollen Sie den/die Benutzer wirklich sperren?]]></item>
                <item name="wcf.acp.user.delete.sure"><![CDATA[Do you really want to delete the user “{$user->username}”?]]></item>
                <item name="wcf.acp.user.edit"><![CDATA[Edit User]]></item>
                <item name="wcf.acp.user.edit.warning.selfEdit"><![CDATA[Heads up! You’re editing your own user account and changes might result in yourself being locked out from the Administration Control Panel.]]></item>