From 92fba0538afc1d88f411db1a80553af2d17c09b4 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Thu, 4 Feb 2021 13:34:58 +0100 Subject: [PATCH] Add inverted permissions feature for pages --- wcfsetup/install/files/acp/templates/pageAdd.tpl | 2 +- .../files/acp/update_com.woltlab.wcf_5.4_db.php | 5 +++++ .../install/files/lib/acp/form/PageAddForm.class.php | 12 ++++++++++++ .../files/lib/acp/form/PageEditForm.class.php | 2 ++ wcfsetup/install/files/lib/data/page/Page.class.php | 9 ++++++++- wcfsetup/setup/db/install.sql | 3 ++- 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/pageAdd.tpl b/wcfsetup/install/files/acp/templates/pageAdd.tpl index d1bff21793..e5d71a1d39 100644 --- a/wcfsetup/install/files/acp/templates/pageAdd.tpl +++ b/wcfsetup/install/files/acp/templates/pageAdd.tpl @@ -527,7 +527,7 @@ {if $action != 'edit' || $page->pageType != 'system'}
- {include file='aclSimple'} + {include file='aclSimple' __supportsInvertedPermissions=true}
{/if} diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_db.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_db.php index 4aa2dd48b0..14fea9657b 100644 --- a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_db.php +++ b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_db.php @@ -183,6 +183,11 @@ $tables = [ ->columns([ DefaultFalseBooleanDatabaseTableColumn::create('invertPermissions'), ]), + + PartialDatabaseTable::create('wcf1_page') + ->columns([ + DefaultFalseBooleanDatabaseTableColumn::create('invertPermissions'), + ]), ]; (new DatabaseTableChangeProcessor( diff --git a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php index a5cc38760b..c4b6260c5f 100644 --- a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php @@ -208,6 +208,12 @@ class PageAddForm extends AbstractForm */ public $presetPage; + /** + * @var bool + * @since 5.4 + */ + public $invertPermissions; + /** * @inheritDoc */ @@ -342,6 +348,9 @@ class PageAddForm extends AbstractForm if (isset($_POST['aclValues']) && \is_array($_POST['aclValues'])) { $this->aclValues = $_POST['aclValues']; } + if (isset($_POST['invertPermissions'])) { + $this->invertPermissions = $_POST['invertPermissions']; + } } /** @@ -622,6 +631,7 @@ class PageAddForm extends AbstractForm 'isMultilingual' => $this->isMultilingual, 'identifier' => '', 'packageID' => 1, + 'invertPermissions' => $this->invertPermissions, ]), 'content' => $content, 'boxToPage' => $this->getBoxToPage(), @@ -765,6 +775,7 @@ class PageAddForm extends AbstractForm 'com.woltlab.wcf.page', $this->presetPage->pageID ); + $this->invertPermissions = $this->presetPage->invertPermissions; } } @@ -825,6 +836,7 @@ class PageAddForm extends AbstractForm 'parentMenuItemID' => $this->parentMenuItemID, 'menuItemNodeList' => $this->menuItems->getNodeList(), 'enableShareButtons' => $this->enableShareButtons, + 'invertPermissions' => $this->invertPermissions, ]); } } diff --git a/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php b/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php index 930c0ffbf1..f7fc82d1ee 100644 --- a/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php @@ -206,6 +206,7 @@ class PageEditForm extends PageAddForm 'availableDuringOfflineMode' => $this->availableDuringOfflineMode, 'allowSpidersToIndex' => $this->allowSpidersToIndex, 'enableShareButtons' => $this->enableShareButtons, + 'invertPermissions' => $this->invertPermissions, ]; if ($this->pageType == 'system') { @@ -326,6 +327,7 @@ class PageEditForm extends PageAddForm } $this->aclValues = SimpleAclHandler::getInstance()->getValues('com.woltlab.wcf.page', $this->page->pageID); + $this->invertPermissions = $this->page->invertPermissions; } } diff --git a/wcfsetup/install/files/lib/data/page/Page.class.php b/wcfsetup/install/files/lib/data/page/Page.class.php index 234ebc96a3..65bfc40cd3 100644 --- a/wcfsetup/install/files/lib/data/page/Page.class.php +++ b/wcfsetup/install/files/lib/data/page/Page.class.php @@ -53,6 +53,7 @@ use wcf\system\WCF; * @property-read string $enableShareButtons is `1` if the page should display share buttons, otherwise `0` * @property-read string $permissions comma separated list of user group permissions of which the active user needs to have at least one to access the page * @property-read string $options comma separated list of options of which at least one needs to be enabled for the page to be accessible + * @property-read bool $invertPermissions is `1` if the permissions are inverted */ class Page extends DatabaseObject implements ILinkableObject, ITitledObject { @@ -264,7 +265,13 @@ class Page extends DatabaseObject implements ILinkableObject, ITitledObject */ public function isAccessible() { - return SimpleAclResolver::getInstance()->canAccess('com.woltlab.wcf.page', $this->pageID); + $canAccess = SimpleAclResolver::getInstance()->canAccess('com.woltlab.wcf.page', $this->pageID); + + if ($this->invertPermissions) { + $canAccess = !$canAccess; + } + + return $canAccess; } /** diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 09249d30d6..cde53c4c39 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -1098,7 +1098,8 @@ CREATE TABLE wcf1_page ( excludeFromLandingPage TINYINT(1) NOT NULL DEFAULT 0, enableShareButtons TINYINT(1) NOT NULL DEFAULT 0, permissions TEXT NULL, - options TEXT NULL + options TEXT NULL, + invertPermissions TINYINT(1) NOT NULL DEFAULT 0 ); DROP TABLE IF EXISTS wcf1_page_box_order; -- 2.20.1