### 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.
}
// 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();
// verify categories
$category = $categories[$this->userGroupOption->categoryName];
while ($category != null) {
- if (!$this->verifyPermissions($category)) {
+ if (!$category->validateOptions() || !$category->validatePermissions()) {
throw new PermissionDeniedException();
}
*
* @param \wcf\data\DatabaseObject $object
* @return boolean
+ *
+ * @deprecated since 2.2
*/
protected function verifyPermissions(DatabaseObject $object) {
// check the options of this item
<?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;
* @category Community Framework
*/
class ObjectType extends ProcessibleDatabaseObject {
+ use TDatabaseObjectOptions;
+ use TDatabaseObjectPermissions;
+
/**
* @see \wcf\data\DatabaseObject::$databaseTableName
*/
<?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;
* @category Community Framework
*/
class Option extends DatabaseObject {
+ use TDatabaseObjectOptions;
+ use TDatabaseObjectPermissions;
+
/**
* @see \wcf\data\DatabaseObject::$databaseTableName
*/
<?php
namespace wcf\data\option\category;
use wcf\data\DatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
/**
* Represents an option category.
* @category Community Framework
*/
class OptionCategory extends DatabaseObject {
+ use TDatabaseObjectOptions;
+ use TDatabaseObjectPermissions;
+
/**
* @see \wcf\data\DatabaseObject::$databaseTableName
*/
<?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;
* @category Community Framework
*/
class Sitemap extends DatabaseObject {
+ use TDatabaseObjectOptions;
+ use TDatabaseObjectPermissions;
+
/**
* ISitemapProvider object
* @var \wcf\system\sitemap\ISitemapProvider
* @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();
}
}
<?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.
* @category Community Framework
*/
class UserGroupOptionCategory extends DatabaseObject {
+ use TDatabaseObjectOptions;
+ use TDatabaseObjectPermissions;
+
/**
* @see \wcf\data\DatabaseObject::$databaseTableName
*/
<?php
namespace wcf\data\user\notification\event;
use wcf\data\ProcessibleDatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
/**
* Represents a user notification event.
* @category Community Framework
*/
class UserNotificationEvent extends ProcessibleDatabaseObject {
+ use TDatabaseObjectOptions;
+ use TDatabaseObjectPermissions;
+
/**
* @see \wcf\data\DatabaseObject::$databaseTableName
*/
<?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;
* @category Community Framework
*/
class UserProfileMenuItem extends DatabaseObject {
+ use TDatabaseObjectOptions;
+ use TDatabaseObjectPermissions;
+
/**
* content manager
* @var \wcf\system\menu\user\profile\content\IUserProfileContent
// 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]);
}
}
// 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]);
}
}
* @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();
}
/**
* @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();
}
/**
* @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);
}
/**
// 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]);
}
}
/**
* Validates object options and permissions.
*
- * @param \wcf\data\DatabaseObject $object
+ * @param \wcf\data\DatabaseObject $object
* @param string $optionsColumnName
* @param string $permissionsColumnName
* @return boolean
* @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();
}
/**