From ae6b590f77b6fb277cc4840b309c8345ab8c99d6 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 20 Jun 2014 20:26:58 +0200 Subject: [PATCH] Add "usersonly" setting for user group options --- com.woltlab.wcf/userGroupOption.xml | 65 +++++++++++++++++++ .../lib/acp/form/UserGroupEditForm.class.php | 10 +++ .../acp/form/UserGroupOptionForm.class.php | 6 ++ .../UserGroupOptionCacheBuilder.class.php | 18 +++++ .../group/UserGroupOptionHandler.class.php | 16 +++++ ...pOptionPackageInstallationPlugin.class.php | 3 + .../system/session/SessionHandler.class.php | 20 ++++++ wcfsetup/setup/db/install.sql | 7 +- 8 files changed, 142 insertions(+), 3 deletions(-) diff --git a/com.woltlab.wcf/userGroupOption.xml b/com.woltlab.wcf/userGroupOption.xml index 5a864cd00e..0f9e318c97 100644 --- a/com.woltlab.wcf/userGroupOption.xml +++ b/com.woltlab.wcf/userGroupOption.xml @@ -124,132 +124,154 @@ boolean 0 1 + 1 @@ -403,24 +439,28 @@ pdf]]> boolean 0 1 + 1 @@ -441,17 +483,20 @@ pdf]]> user.signature boolean 1 + 1 @@ -479,28 +526,33 @@ pdf]]> user.profile boolean 1 + 1 @@ -570,6 +627,7 @@ png]]> boolean 0 1 + 1 @@ -627,6 +686,7 @@ png]]> user.profileComment boolean 0 + 1 @@ -635,6 +695,7 @@ png]]> boolean 0 1 + 1 diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php index fd52b8a288..a57e8322ed 100755 --- a/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php @@ -59,7 +59,17 @@ class UserGroupEditForm extends UserGroupAddForm { } $this->group = new UserGroupEditor($group); + $this->optionHandler->setUserGroup($group); + $this->optionHandler->init(); + } + + /** + * @see \wcf\acp\form\AbstractOptionListForm::initOptionHandler() + */ + protected function initOptionHandler() { + // does nothing, we call OptionHandler::init() after we set the + // user group } /** diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php index 898bd96ab0..f980054a1c 100644 --- a/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php @@ -116,6 +116,12 @@ class UserGroupOptionForm extends AbstractForm { // read accessible groups $this->groups = UserGroup::getAccessibleGroups(); + if ($this->userGroupOption->usersOnly) { + $guestGroup = UserGroup::getGroupByType(UserGroup::GUESTS); + if (isset($this->groups[$guestGroup->groupID])) { + unset($this->groups[$guestGroup->groupID]); + } + } if (empty($this->groups)) { throw new PermissionDeniedException(); } diff --git a/wcfsetup/install/files/lib/system/cache/builder/UserGroupOptionCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/UserGroupOptionCacheBuilder.class.php index 4afbdb18bd..1e7aee3f0e 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/UserGroupOptionCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/UserGroupOptionCacheBuilder.class.php @@ -21,4 +21,22 @@ class UserGroupOptionCacheBuilder extends OptionCacheBuilder { * @see \wcf\system\cache\builder\OptionCacheBuilder::$tableName */ protected $tableName = 'user_group_option'; + + /** + * @see \wcf\system\cache\builder\AbstractCacheBuilder::rebuild() + */ + public function rebuild(array $parameters) { + $data = parent::rebuild($parameters); + + $usersOnlyPermissions = array(); + foreach ($data['options'] as $option) { + if ($option->usersOnly) { + $usersOnlyPermissions[] = $option->optionName; + } + } + + $data['usersOnlyOptions'] = $usersOnlyPermissions; + + return $data; + } } diff --git a/wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php b/wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php index dcfe454a63..4b2f34505c 100644 --- a/wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php @@ -45,6 +45,22 @@ class UserGroupOptionHandler extends OptionHandler { $this->group = $group; } + /** + * @see \wcf\system\option\OptionHandler::checkOption() + */ + protected function checkOption(Option $option) { + if (parent::checkOption($option)) { + // check if permission is available for guests if group is guests + if ($this->group && $this->group->groupType == UserGroup::GUESTS && $option->usersOnly) { + return false; + } + + return true; + } + + return false; + } + /** * @see \wcf\system\option\OptionHandler::getClassName() */ diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php index 87385de3d9..cc3006d9fb 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php @@ -39,6 +39,7 @@ class UserGroupOptionPackageInstallationPlugin extends AbstractOptionPackageInst protected function saveOption($option, $categoryName, $existingOptionID = 0) { // default values $optionName = $optionType = $defaultValue = $adminDefaultValue = $modDefaultValue = $userDefaultValue = $validationPattern = $enableOptions = $permissions = $options = ''; + $usersOnly = 0; $showOrder = null; // get values @@ -54,6 +55,7 @@ class UserGroupOptionPackageInstallationPlugin extends AbstractOptionPackageInst if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions']; if (isset($option['permissions'])) $permissions = $option['permissions']; if (isset($option['options'])) $options = $option['options']; + if (isset($option['usersonly'])) $usersOnly = $option['usersonly']; // collect additional tags and their values $additionalData = array(); @@ -82,6 +84,7 @@ class UserGroupOptionPackageInstallationPlugin extends AbstractOptionPackageInst 'enableOptions' => $enableOptions, 'permissions' => $permissions, 'options' => $options, + 'usersOnly' => $usersOnly, 'additionalData' => serialize($additionalData) ); diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 828f0370f3..aac5fdc423 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -7,6 +7,7 @@ use wcf\data\user\User; use wcf\data\user\UserEditor; use wcf\page\ITrackablePage; use wcf\system\cache\builder\SpiderCacheBuilder; +use wcf\system\cache\builder\UserGroupOptionCacheBuilder; use wcf\system\cache\builder\UserGroupPermissionCacheBuilder; use wcf\system\database\DatabaseException; use wcf\system\exception\PermissionDeniedException; @@ -127,6 +128,12 @@ class SessionHandler extends SingletonFactory { */ protected $firstVisit = false; + /** + * list of names of permissions only available for users + * @var array + */ + protected $usersOnlyPermissions = array(); + /** * Provides access to session data. * @@ -141,6 +148,13 @@ class SessionHandler extends SingletonFactory { return $this->session->{$key}; } + /** + * @see \wcf\system\SingletonFactory::init() + */ + protected function init() { + $this->usersOnlyPermissions = UserGroupOptionCacheBuilder::getInstance()->getData(array(), 'usersOnlyOptions'); + } + /** * Loads an existing session or creates a new one. * @@ -462,6 +476,12 @@ class SessionHandler extends SingletonFactory { * @return mixed permission value */ public function getPermission($permission) { + // check if a users only permission is checked for a guest and return + // false if that is the case + if (!$this->user->userID && in_array($permission, $this->usersOnlyPermissions)) { + return false; + } + $this->loadGroupData(); if (!isset($this->groupData[$permission])) return false; diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 681158ccc1..ddde915215 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -1157,6 +1157,7 @@ CREATE TABLE wcf1_user_group_option ( showOrder INT(10) NOT NULL DEFAULT 0, permissions TEXT, options TEXT, + usersOnly TINYINT(1) NOT NULL DEFAULT 0, additionalData MEDIUMTEXT, UNIQUE KEY optionName (optionName, packageID) ); @@ -1645,9 +1646,9 @@ INSERT INTO wcf1_user_group (groupID, groupName, groupType) VALUES (4, 'wcf.acp. INSERT INTO wcf1_user_group (groupID, groupName, groupType) VALUES (5, 'wcf.acp.group.group5', 4); -- Moderators -- default user group options -INSERT INTO wcf1_user_group_option (optionID, optionName, categoryName, optionType, defaultValue, showOrder) VALUES (1, 'admin.general.canUseAcp', 'admin.general', 'boolean', '0', 1); -INSERT INTO wcf1_user_group_option (optionID, optionName, categoryName, optionType, defaultValue, showOrder) VALUES (2, 'admin.system.package.canInstallPackage', 'admin.system.package', 'boolean', '0', 1); -INSERT INTO wcf1_user_group_option (optionID, optionName, categoryName, optionType, defaultValue, showOrder) VALUES (3, 'admin.user.canEditGroup', 'admin.user.group', 'boolean', '0', 1); +INSERT INTO wcf1_user_group_option (optionID, optionName, categoryName, optionType, defaultValue, showOrder, usersOnly) VALUES (1, 'admin.general.canUseAcp', 'admin.general', 'boolean', '0', 1, 1); +INSERT INTO wcf1_user_group_option (optionID, optionName, categoryName, optionType, defaultValue, showOrder, usersOnly) VALUES (2, 'admin.system.package.canInstallPackage', 'admin.system.package', 'boolean', '0', 1, 1); +INSERT INTO wcf1_user_group_option (optionID, optionName, categoryName, optionType, defaultValue, showOrder, usersOnly) VALUES (3, 'admin.user.canEditGroup', 'admin.user.group', 'boolean', '0', 1, 1); -- default user group option values INSERT INTO wcf1_user_group_option_value (groupID, optionID, optionValue) VALUES (1, 1, '0'); -- Everyone -- 2.20.1