Add TDatabaseObjectOptions and TDatabaseObjectPermissions traits
authorMatthias Schmidt <gravatronics@live.com>
Thu, 21 May 2015 21:10:45 +0000 (23:10 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 21 May 2015 21:10:45 +0000 (23:10 +0200)
16 files changed:
CHANGELOG.md
wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php
wcfsetup/install/files/lib/data/object/type/ObjectType.class.php
wcfsetup/install/files/lib/data/option/Option.class.php
wcfsetup/install/files/lib/data/option/category/OptionCategory.class.php
wcfsetup/install/files/lib/data/sitemap/Sitemap.class.php
wcfsetup/install/files/lib/data/user/group/option/category/UserGroupOptionCategory.class.php
wcfsetup/install/files/lib/data/user/notification/event/UserNotificationEvent.class.php
wcfsetup/install/files/lib/data/user/profile/menu/item/UserProfileMenuItem.class.php
wcfsetup/install/files/lib/page/TaggedPage.class.php
wcfsetup/install/files/lib/system/ad/AdHandler.class.php
wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php
wcfsetup/install/files/lib/system/option/OptionHandler.class.php
wcfsetup/install/files/lib/system/page/PageManager.class.php
wcfsetup/install/files/lib/system/search/acp/AbstractACPSearchResultProvider.class.php
wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php

index 1984f657ee326b132b6e034d457145f74ab3b0fe..3a7bfd2442306dbab7394e259f9de99c53b15280 100644 (file)
@@ -4,5 +4,6 @@
 
 ### 2.2.0 Alpha 1 (XXXX-YY-ZZ)
 
+* Add `wcf\data\TDatabaseObjectOptions` and `wcf\data\TDatabaseObjectPermissions` for database object-bound options and permissions validation.
 * `wcf\system\cache\builder\EventListenerCacheBuilder` returns `wcf\data\event\listener\EventListener` objects instead of data arrays.
 
index 3fddd8aaccde2a219efc6352fbe1e2485f664f05..6150d7e5d049151e54448f725bdc452aa3da39bd 100644 (file)
@@ -89,7 +89,7 @@ class UserGroupOptionForm extends AbstractForm {
                }
                
                // verify options and permissions for current option
-               if ($this->verifyPermissions($this->userGroupOption)) {
+               if ($this->userGroupOption->validateOptions() && $this->userGroupOption->validatePermissions()) {
                        // read all categories
                        $categoryList = new UserGroupOptionCategoryList();
                        $categoryList->readObjects();
@@ -102,7 +102,7 @@ class UserGroupOptionForm extends AbstractForm {
                        // verify categories
                        $category = $categories[$this->userGroupOption->categoryName];
                        while ($category != null) {
-                               if (!$this->verifyPermissions($category)) {
+                               if (!$category->validateOptions() || !$category->validatePermissions()) {
                                        throw new PermissionDeniedException();
                                }
                                
@@ -255,6 +255,8 @@ class UserGroupOptionForm extends AbstractForm {
         * 
         * @param       \wcf\data\DatabaseObject                $object
         * @return      boolean
+        * 
+        * @deprecated  since 2.2
         */
        protected function verifyPermissions(DatabaseObject $object) {
                // check the options of this item
index 58a9ccc1c7743490f9b78d82a16f8e2227c35668..782cde862bdf15bf2cdbc4589d538127331dd6d1 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\object\type;
 use wcf\data\ProcessibleDatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
 use wcf\system\exception\SystemException;
 use wcf\util\ClassUtil;
 
@@ -15,6 +17,9 @@ use wcf\util\ClassUtil;
  * @category   Community Framework
  */
 class ObjectType extends ProcessibleDatabaseObject {
+       use TDatabaseObjectOptions;
+       use TDatabaseObjectPermissions;
+       
        /**
         * @see \wcf\data\DatabaseObject::$databaseTableName
         */
index c08cbed93046c1f9f28a35306665be4213977c83..84387a8a00f779d54003bc5d061183c919584c88 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\option;
 use wcf\data\DatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
 
@@ -15,6 +17,9 @@ use wcf\util\StringUtil;
  * @category   Community Framework
  */
 class Option extends DatabaseObject {
+       use TDatabaseObjectOptions;
+       use TDatabaseObjectPermissions;
+       
        /**
         * @see \wcf\data\DatabaseObject::$databaseTableName
         */
index 23c39e545d7f2be31853d0010d0ceef72233f3be..dc5881211ee86c5c852832ad471d3338c2960808 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\option\category;
 use wcf\data\DatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
 
 /**
  * Represents an option category.
@@ -13,6 +15,9 @@ use wcf\data\DatabaseObject;
  * @category   Community Framework
  */
 class OptionCategory extends DatabaseObject {
+       use TDatabaseObjectOptions;
+       use TDatabaseObjectPermissions;
+       
        /**
         * @see \wcf\data\DatabaseObject::$databaseTableName
         */
index 14bf14a66d26a0d548b985325c251e5b154dc1e0..651a0257bfe432e1f1012736c00824088d1a0c31 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\sitemap;
 use wcf\data\DatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
 use wcf\util\ClassUtil;
@@ -16,6 +18,9 @@ use wcf\util\ClassUtil;
  * @category   Community Framework
  */
 class Sitemap extends DatabaseObject {
+       use TDatabaseObjectOptions;
+       use TDatabaseObjectPermissions;
+       
        /**
         * ISitemapProvider object
         * @var \wcf\system\sitemap\ISitemapProvider
@@ -60,34 +65,6 @@ class Sitemap extends DatabaseObject {
         * @return      boolean
         */
        public function isAccessible() {
-               // check the options of this item
-               $hasEnabledOption = true;
-               if ($this->options) {
-                       $hasEnabledOption = false;
-                       $options = explode(',', strtoupper($this->options));
-                       foreach ($options as $option) {
-                               if (defined($option) && constant($option)) {
-                                       $hasEnabledOption = true;
-                                       break;
-                               }
-                       }
-               }
-               if (!$hasEnabledOption) return false;
-               
-               // check the permission of this item for the active user
-               $hasPermission = true;
-               if ($this->permissions) {
-                       $hasPermission = false;
-                       $permissions = explode(',', $this->permissions);
-                       foreach ($permissions as $permission) {
-                               if (WCF::getSession()->getPermission($permission)) {
-                                       $hasPermission = true;
-                                       break;
-                               }
-                       }
-               }
-               if (!$hasPermission) return false;
-               
-               return true;
+               return $this->validateOptions() && $this->validatePermissions();
        }
 }
index f3173b7dd5dee59903bd518064cb997562a5a5b6..e6be27ee05a7229656e7162155fad22e9c2e3a1d 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\user\group\option\category;
 use wcf\data\DatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
 
 /**
  * Represents a user group options category.
@@ -13,6 +15,9 @@ use wcf\data\DatabaseObject;
  * @category   Community Framework
  */
 class UserGroupOptionCategory extends DatabaseObject {
+       use TDatabaseObjectOptions;
+       use TDatabaseObjectPermissions;
+       
        /**
         * @see \wcf\data\DatabaseObject::$databaseTableName
         */
index 7600a0451e9aed49834d992b407f881c088b87e3..9b8e912015bb22b40ff3d849659befadaf6eae9d 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\user\notification\event;
 use wcf\data\ProcessibleDatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
 
 /**
  * Represents a user notification event.
@@ -13,6 +15,9 @@ use wcf\data\ProcessibleDatabaseObject;
  * @category   Community Framework
  */
 class UserNotificationEvent extends ProcessibleDatabaseObject {
+       use TDatabaseObjectOptions;
+       use TDatabaseObjectPermissions;
+       
        /**
         * @see \wcf\data\DatabaseObject::$databaseTableName
         */
index b6728b4bdf3bf85dc99704000f46bf6fe264f0fe..aca02ed7dc1e6da044620d7e8c194af2cd14ae43 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\user\profile\menu\item;
 use wcf\data\DatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
 use wcf\system\exception\SystemException;
 use wcf\util\ClassUtil;
 
@@ -15,6 +17,9 @@ use wcf\util\ClassUtil;
  * @category   Community Framework
  */
 class UserProfileMenuItem extends DatabaseObject {
+       use TDatabaseObjectOptions;
+       use TDatabaseObjectPermissions;
+       
        /**
         * content manager
         * @var \wcf\system\menu\user\profile\content\IUserProfileContent
index 3325d97057cf6501e11a4ba406d84b53f6fe82cb..298805917d2245b422a76aa302b2f88ccddc72d2 100644 (file)
@@ -74,34 +74,8 @@ class TaggedPage extends MultipleLinkPage {
                // filter taggable object types by options and permissions
                $this->availableObjectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.tagging.taggableObject');
                foreach ($this->availableObjectTypes as $key => $objectType) {
-                       if ($objectType->options) {
-                               $hasEnabledOption = false;
-                               $options = explode(',', strtoupper($objectType->options));
-                               foreach ($options as $option) {
-                                       if (defined($option) && constant($option)) {
-                                               $hasEnabledOption = true;
-                                               break;
-                                       }
-                               }
-                               
-                               if (!$hasEnabledOption) {
-                                       unset($this->availableObjectTypes[$key]);
-                               }
-                       }
-                       
-                       if ($objectType->permissions) {
-                               $hasPermission = false;
-                               $permissions = explode(',', $objectType->permissions);
-                               foreach ($permissions as $permission) {
-                                       if (WCF::getSession()->getPermission($permission)) {
-                                               $hasPermission = true;
-                                               break;
-                                       }
-                               }
-                               
-                               if (!$hasPermission) {
-                                       unset($this->availableObjectTypes[$key]);
-                               }
+                       if (!$objectType->validateOptions() || !$objectType->validatePermissions()) {
+                               unset($this->availableObjectTypes[$key]);
                        }
                }
                
index a6e6ed44d696f0ee48824785791f23c9cedaba2c..4a7f3d74fe00716c0d98c5ed741d5a31b9da97e0 100644 (file)
@@ -93,14 +93,8 @@ class AdHandler extends SingletonFactory {
                
                // filter by options
                foreach ($objectTypes as $objectTypeName => $objectType) {
-                       if ($objectType->options) {
-                               $options = explode(',', strtoupper($objectType->options));
-                               foreach ($options as $option) {
-                                       if (!defined($option) || !constant($option)) {
-                                               unset($objectTypes[$objectTypeName]);
-                                               break;
-                                       }
-                               }
+                       if (!$objectType->validateOptions()) {
+                               unset($objectTypes[$objectTypeName]);
                        }
                }
                
index f0f88f6d9d6e26c718a91b8e4ff455aee8976533..55a94a23b6ce12934cab982ccdd47eebef9d68dc 100644 (file)
@@ -72,35 +72,7 @@ class UserProfileMenu extends SingletonFactory {
         * @return      boolean
         */
        protected function checkMenuItem(UserProfileMenuItem $item) {
-               // check the options of this item
-               $hasEnabledOption = true;
-               if (!empty($item->options)) {
-                       $hasEnabledOption = false;
-                       $options = explode(',', strtoupper($item->options));
-                       foreach ($options as $option) {
-                               if (defined($option) && constant($option)) {
-                                       $hasEnabledOption = true;
-                                       break;
-                               }
-                       }
-               }
-               if (!$hasEnabledOption) return false;
-               
-               // check the permission of this item for the active user
-               $hasPermission = true;
-               if (!empty($item->permissions)) {
-                       $hasPermission = false;
-                       $permissions = explode(',', $item->permissions);
-                       foreach ($permissions as $permission) {
-                               if (WCF::getSession()->getPermission($permission)) {
-                                       $hasPermission = true;
-                                       break;
-                               }
-                       }
-               }
-               if (!$hasPermission) return false;
-               
-               return true;
+               return $item->validateOptions() && $item->validatePermissions();
        }
        
        /**
index 0328fdeba9eb16d4a1baad10adc0185d80fa10c0..dc3742d276dae7d89f1e755693e977bac83accdf 100644 (file)
@@ -443,34 +443,7 @@ class OptionHandler implements IOptionHandler {
         * @return      boolean
         */
        protected function checkCategory(OptionCategory $category) {
-               if ($category->permissions) {
-                       $hasPermission = false;
-                       $permissions = explode(',', $category->permissions);
-                       foreach ($permissions as $permission) {
-                               if (WCF::getSession()->getPermission($permission)) {
-                                       $hasPermission = true;
-                                       break;
-                               }
-                       }
-                       
-                       if (!$hasPermission) return false;
-                       
-               }
-               
-               if ($category->options) {
-                       $hasEnabledOption = false;
-                       $options = explode(',', strtoupper($category->options));
-                       foreach ($options as $option) {
-                               if (defined($option) && constant($option)) {
-                                       $hasEnabledOption = true;
-                                       break;
-                               }
-                       }
-                       
-                       if (!$hasEnabledOption) return false;
-               }
-               
-               return true;
+               return $category->validateOptions() && $category->validatePermissions();
        }
        
        /**
@@ -480,38 +453,7 @@ class OptionHandler implements IOptionHandler {
         * @return      boolean
         */
        protected function checkOption(Option $option) {
-               if ($option->permissions) {
-                       $hasPermission = false;
-                       $permissions = explode(',', $option->permissions);
-                       foreach ($permissions as $permission) {
-                               if (WCF::getSession()->getPermission($permission)) {
-                                       $hasPermission = true;
-                                       break;
-                               }
-                       }
-                       
-                       if (!$hasPermission) return false;
-                       
-               }
-               
-               if ($option->options) {
-                       $hasEnabledOption = false;
-                       $__options = explode(',', strtoupper($option->options));
-                       foreach ($__options as $__option) {
-                               if (defined($__option) && constant($__option)) {
-                                       $hasEnabledOption = true;
-                                       break;
-                               }
-                       }
-                       
-                       if (!$hasEnabledOption) return false;
-               }
-               
-               if (!$this->checkVisibility($option)) {
-                       return false;
-               }
-               
-               return true;
+               return $option->validateOptions() && $option->validatePermissions() && $this->checkVisibility($option);
        }
        
        /**
index 30073db04f8c600d7e05f9f25b74a384c86f2748..e118bd8acadbfea757d070573f22783d22f329d2 100644 (file)
@@ -68,14 +68,8 @@ class PageManager extends SingletonFactory {
                
                // filter by options
                foreach ($objectTypes as $objectTypeName => $objectType) {
-                       if ($objectType->options) {
-                               $options = explode(',', strtoupper($objectType->options));
-                               foreach ($options as $option) {
-                                       if (!defined($option) || !constant($option)) {
-                                               unset($objectTypes[$objectTypeName]);
-                                               break;
-                                       }
-                               }
+                       if (!$objectType->validateOptions()) {
+                               unset($objectTypes[$objectTypeName]);
                        }
                }
                
index 4d5703056ad123bd70c9d1b2ecb1aed8c980c5c3..de8cd477448d2035755a9262c2aef593657ff8b3 100644 (file)
@@ -17,7 +17,7 @@ abstract class AbstractACPSearchResultProvider {
        /**
         * Validates object options and permissions.
         * 
-        * @param       \wcf\data\DatabaseObject                $object
+        * @param       \wcf\data\DatabaseObject        $object
         * @param       string                          $optionsColumnName
         * @param       string                          $permissionsColumnName
         * @return      boolean
index b39dc4175314b4ee6b3e4b9ce0446674cdce3595..bc3df9c90cb13b3f7dc73ee4fb7782d11dae5874 100644 (file)
@@ -114,31 +114,7 @@ abstract class AbstractUserNotificationEvent extends DatabaseObjectDecorator imp
         * @see \wcf\system\user\notification\event\IUserNotificationEvent::isVisible()
         */
        public function isVisible() {
-               if ($this->options) {
-                       $hasEnabledOption = false;
-                       $options = explode(',', strtoupper($this->options));
-                       foreach ($options as $option) {
-                               if (defined($option) && constant($option)) {
-                                       $hasEnabledOption = true;
-                                       break;
-                               }
-                       }
-                       if (!$hasEnabledOption) return false;
-               }
-               
-               $hasPermission = true;
-               if ($this->permissions) {
-                       $hasPermission = false;
-                       $permissions = explode(',', $this->permissions);
-                       foreach ($permissions as $permission) {
-                               if (WCF::getSession()->getPermission($permission)) {
-                                       $hasPermission = true;
-                               break;
-                               }
-                       }
-               }
-               if (!$hasPermission) return false;
-               return true;
+               return $this->getDecoratedObject()->validateOptions() & $this->getDecoratedObject()->validatePermissions();
        }
        
        /**