Added wildcard support for ACL categories
authorAlexander Ebert <ebert@woltlab.com>
Mon, 18 Feb 2013 12:45:33 +0000 (13:45 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 18 Feb 2013 12:45:33 +0000 (13:45 +0100)
Fixes #1142

wcfsetup/install/files/js/WCF.ACL.js
wcfsetup/install/files/lib/data/acl/option/ACLOptionAction.class.php
wcfsetup/install/files/lib/system/acl/ACLHandler.class.php

index 91b0c449fbab032d73fbc69452ab895b4dce7da5..1dd3743dd4e48f1a9f9794cb5ba35e4c30a64b1a 100644 (file)
@@ -155,11 +155,9 @@ WCF.ACL.List = Class.extend({
                        actionName: 'loadAll',
                        className: 'wcf\\data\\acl\\option\\ACLOptionAction',
                        parameters: {
-                               data: {
-                                       categoryName: this._categoryName,
-                                       objectID: this._objectID,
-                                       objectTypeID: this._objectTypeID
-                               }
+                               categoryName: this._categoryName,
+                               objectID: this._objectID,
+                               objectTypeID: this._objectTypeID
                        }
                });
                this._proxy.sendRequest();
index 4890f9561e0f4dc2f76fd82593b1b8e6a396fadc..690b737208d974eb894b88eec4dda55e75fe0883 100644 (file)
@@ -2,13 +2,12 @@
 namespace wcf\data\acl\option;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\system\acl\ACLHandler;
-use wcf\system\exception\UserInputException;
 
 /**
  * Executes acl option-related actions.
  * 
- * @author     Marcel Werk
- * @copyright  2001-2012 WoltLab GmbH
+ * @author     Alexander Ebert
+ * @copyright  2001-2013 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage data.acl.option
@@ -24,9 +23,9 @@ class ACLOptionAction extends AbstractDatabaseObjectAction {
         * Validates parameters for ACL options.
         */
        public function validateLoadAll() {
-               if (!isset($this->parameters['data']['objectTypeID'])) {
-                       throw new UserInputException('objectTypeID');
-               }
+               $this->readInteger('objectID', true);
+               $this->readInteger('objectTypeID');
+               $this->readString('categoryName', true);
        }
        
        /**
@@ -35,8 +34,8 @@ class ACLOptionAction extends AbstractDatabaseObjectAction {
         * @return      array
         */
        public function loadAll() {
-               $objectIDs = (isset($this->parameters['data']['objectID'])) ? array($this->parameters['data']['objectID']) : array();
-               $permissions = ACLHandler::getInstance()->getPermissions($this->parameters['data']['objectTypeID'], $objectIDs, null, true);
+               $objectIDs = (isset($this->parameters['objectID'])) ? array($this->parameters['objectID']) : array();
+               $permissions = ACLHandler::getInstance()->getPermissions($this->parameters['objectTypeID'], $objectIDs, $this->parameters['categoryName'], true);
                
                return $permissions;
        }
index 2f8b43a219be39d247edea39bb74c86a8939bef4..2ddae34ab7b11f540f48ef3d74657d38257fd149 100644 (file)
@@ -11,6 +11,7 @@ use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Handles ACL permissions.
@@ -215,14 +216,14 @@ class ACLHandler extends SingletonFactory {
        /**
         * Returns a list of permissions by object type id.
         * 
-        * @param       integer                                         $objectTypeID
-        * @param       array                                           $objectIDs
-        * @param       wcf\data\acl\option\category\ACLOptionCategory  $category
-        * @param       boolean                                         $settingsView
+        * @param       integer         $objectTypeID
+        * @param       array           $objectIDs
+        * @param       string          $categoryName
+        * @param       boolean         $settingsView
         * @return      array
         */
-       public function getPermissions($objectTypeID, array $objectIDs, ACLOptionCategory $category = null, $settingsView = false) {
-               $optionList = $this->getOptions($objectTypeID, $category);
+       public function getPermissions($objectTypeID, array $objectIDs, $categoryName = '', $settingsView = false) {
+               $optionList = $this->getOptions($objectTypeID, $categoryName);
                
                $data = array(
                        'options' => $optionList,
@@ -242,28 +243,30 @@ class ACLHandler extends SingletonFactory {
                        $data['options'] = array();
                        $data['categories'] = array();
                        
-                       $categoryNames = array();
-                       foreach ($optionList as $option) {
-                               $data['options'][$option->optionID] = array(
-                                       'categoryName' => $option->categoryName,
-                                       'label' => WCF::getLanguage()->get('wcf.acl.option.'.$objectType->objectType.'.'.$option->optionName),
-                                       'optionName' => $option->optionName
-                               );
+                       if (count($optionList)) {
+                               $categoryNames = array();
+                               foreach ($optionList as $option) {
+                                       $data['options'][$option->optionID] = array(
+                                               'categoryName' => $option->categoryName,
+                                               'label' => WCF::getLanguage()->get('wcf.acl.option.'.$objectType->objectType.'.'.$option->optionName),
+                                               'optionName' => $option->optionName
+                                       );
+                                       
+                                       if (!in_array($option->categoryName, $categoryNames)) {
+                                               $categoryNames[] = $option->categoryName;
+                                       }
+                               }
                                
-                               if (!in_array($option->categoryName, $categoryNames)) {
-                                       $categoryNames[] = $option->categoryName;
+                               // load categories
+                               $categoryList = new ACLOptionCategoryList();
+                               $categoryList->getConditionBuilder()->add("acl_option_category.categoryName IN (?)", array($categoryNames));
+                               $categoryList->getConditionBuilder()->add("acl_option_category.objectTypeID = ?", array($objectTypeID));
+                               $categoryList->readObjects();
+                               
+                               foreach ($categoryList as $category) {
+                                       $data['categories'][$category->categoryName] = WCF::getLanguage()->get('wcf.acl.option.category.'.$objectType->objectType.'.'.$category->categoryName);
                                }
                        }
-                       
-                       // load categories
-                       $categoryList = new ACLOptionCategoryList();
-                       $categoryList->getConditionBuilder()->add("acl_option_category.categoryName IN (?)", array($categoryNames));
-                       $categoryList->getConditionBuilder()->add("acl_option_category.objectTypeID = ?", array($objectTypeID));
-                       $categoryList->readObjects();
-                       
-                       foreach ($categoryList as $category) {
-                               $data['categories'][$category->categoryName] = WCF::getLanguage()->get('wcf.acl.option.category.'.$objectType->objectType.'.'.$category->categoryName);
-                       }
                }
                
                return $data;
@@ -285,6 +288,11 @@ class ACLHandler extends SingletonFactory {
                        $optionsIDs[] = $option->optionID;
                }
                
+               // category matched no options
+               if (empty($optionsIDs)) {
+                       return;
+               }
+               
                $columnID = $type.'ID';
                $conditions = new PreparedStatementConditionBuilder();
                $conditions->add("optionID IN (?)", array($optionsIDs));
@@ -354,14 +362,20 @@ class ACLHandler extends SingletonFactory {
        /**
         * Returns a list of options by object type id.
         * 
-        * @param       integer                                         $objectTypeID
-        * @param       wcf\data\acl\option\category\ACLOptionCategory  $category
+        * @param       integer         $objectTypeID
+        * @param       string          $categoryName
         * @return      wcf\data\acl\option\ACLOptionList
         */
-       public function getOptions($objectTypeID, ACLOptionCategory $category = null) {
+       public function getOptions($objectTypeID, $categoryName = '') {
                $optionList = new ACLOptionList();
-               if ($category !== null) {
-                       $optionList->getConditionBuilder()->add("acl_option.categoryName = ?", array($category->categoryName));
+               if (!empty($categoryName)) {
+                       if (StringUtil::endsWith($categoryName, '.*')) {
+                               $categoryName = StringUtil::substring($categoryName, 0, -1) . '%';
+                               $optionList->getConditionBuilder()->add("acl_option.categoryName LIKE ?", array($categoryName));
+                       }
+                       else {
+                               $optionList->getConditionBuilder()->add("acl_option.categoryName = ?", array($category->categoryName));
+                       }
                }
                $optionList->getConditionBuilder()->add("acl_option.objectTypeID = ?", array($objectTypeID));
                $optionList->readObjects();