From c1b907f345397a5604f8ceca8af257d61938639a Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 21 May 2015 23:10:45 +0200 Subject: [PATCH] Add TDatabaseObjectOptions and TDatabaseObjectPermissions traits --- CHANGELOG.md | 1 + .../acp/form/UserGroupOptionForm.class.php | 6 +- .../lib/data/object/type/ObjectType.class.php | 5 ++ .../files/lib/data/option/Option.class.php | 5 ++ .../option/category/OptionCategory.class.php | 5 ++ .../files/lib/data/sitemap/Sitemap.class.php | 35 ++--------- .../UserGroupOptionCategory.class.php | 5 ++ .../event/UserNotificationEvent.class.php | 5 ++ .../menu/item/UserProfileMenuItem.class.php | 5 ++ .../files/lib/page/TaggedPage.class.php | 30 +-------- .../files/lib/system/ad/AdHandler.class.php | 10 +-- .../user/profile/UserProfileMenu.class.php | 30 +-------- .../lib/system/option/OptionHandler.class.php | 62 +------------------ .../lib/system/page/PageManager.class.php | 10 +-- .../AbstractACPSearchResultProvider.class.php | 2 +- .../AbstractUserNotificationEvent.class.php | 26 +------- 16 files changed, 52 insertions(+), 190 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1984f657ee..3a7bfd2442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php index 3fddd8aacc..6150d7e5d0 100644 --- a/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/data/object/type/ObjectType.class.php b/wcfsetup/install/files/lib/data/object/type/ObjectType.class.php index 58a9ccc1c7..782cde862b 100644 --- a/wcfsetup/install/files/lib/data/object/type/ObjectType.class.php +++ b/wcfsetup/install/files/lib/data/object/type/ObjectType.class.php @@ -1,6 +1,8 @@ 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(); } } diff --git a/wcfsetup/install/files/lib/data/user/group/option/category/UserGroupOptionCategory.class.php b/wcfsetup/install/files/lib/data/user/group/option/category/UserGroupOptionCategory.class.php index f3173b7dd5..e6be27ee05 100644 --- a/wcfsetup/install/files/lib/data/user/group/option/category/UserGroupOptionCategory.class.php +++ b/wcfsetup/install/files/lib/data/user/group/option/category/UserGroupOptionCategory.class.php @@ -1,6 +1,8 @@ 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]); } } diff --git a/wcfsetup/install/files/lib/system/ad/AdHandler.class.php b/wcfsetup/install/files/lib/system/ad/AdHandler.class.php index a6e6ed44d6..4a7f3d74fe 100644 --- a/wcfsetup/install/files/lib/system/ad/AdHandler.class.php +++ b/wcfsetup/install/files/lib/system/ad/AdHandler.class.php @@ -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]); } } diff --git a/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php b/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php index f0f88f6d9d..55a94a23b6 100644 --- a/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php @@ -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(); } /** diff --git a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php index 0328fdeba9..dc3742d276 100644 --- a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php @@ -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); } /** diff --git a/wcfsetup/install/files/lib/system/page/PageManager.class.php b/wcfsetup/install/files/lib/system/page/PageManager.class.php index 30073db04f..e118bd8aca 100644 --- a/wcfsetup/install/files/lib/system/page/PageManager.class.php +++ b/wcfsetup/install/files/lib/system/page/PageManager.class.php @@ -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]); } } diff --git a/wcfsetup/install/files/lib/system/search/acp/AbstractACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/AbstractACPSearchResultProvider.class.php index 4d5703056a..de8cd47744 100644 --- a/wcfsetup/install/files/lib/system/search/acp/AbstractACPSearchResultProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/AbstractACPSearchResultProvider.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php index b39dc41753..bc3df9c90c 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php @@ -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(); } /** -- 2.20.1