Add inverted permissions feature for pages
authorjoshuaruesweg <ruesweg@woltlab.com>
Thu, 4 Feb 2021 12:34:58 +0000 (13:34 +0100)
committerjoshuaruesweg <ruesweg@woltlab.com>
Thu, 4 Feb 2021 15:20:07 +0000 (16:20 +0100)
wcfsetup/install/files/acp/templates/pageAdd.tpl
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_db.php
wcfsetup/install/files/lib/acp/form/PageAddForm.class.php
wcfsetup/install/files/lib/acp/form/PageEditForm.class.php
wcfsetup/install/files/lib/data/page/Page.class.php
wcfsetup/setup/db/install.sql

index d1bff21793e269628608b647833c3fcfece7a910..e5d71a1d39d6caa07b35313c0e1cbb97e1aad998 100644 (file)
                
                {if $action != 'edit' || $page->pageType != 'system'}
                        <div id="acl" class="tabMenuContent">
-                               {include file='aclSimple'}
+                               {include file='aclSimple' __supportsInvertedPermissions=true}
                        </div>
                {/if}
                
index 4aa2dd48b0e257ba3b51d15231141f4c3e26b3a3..14fea9657b3adbef69e01e62f0ae7c9421cd1a1c 100644 (file)
@@ -183,6 +183,11 @@ $tables = [
         ->columns([
             DefaultFalseBooleanDatabaseTableColumn::create('invertPermissions'),
         ]),
+
+    PartialDatabaseTable::create('wcf1_page')
+        ->columns([
+            DefaultFalseBooleanDatabaseTableColumn::create('invertPermissions'),
+        ]),
 ];
 
 (new DatabaseTableChangeProcessor(
index a5cc38760b366333d30983f560467f5f12d8275d..c4b6260c5fa444642ad878cc21ed78459d57a080 100644 (file)
@@ -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,
         ]);
     }
 }
index 930c0ffbf1887434a7bab9ec5272dea4ec6b0c9c..f7fc82d1eea9628304c4883a191ad9fb8fc8fee1 100644 (file)
@@ -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;
         }
     }
 
index 234ebc96a3ab0480977011063ff81c720eb21a2f..65bfc40cd3078cf140397c96fd4590f14558d89a 100644 (file)
@@ -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;
     }
 
     /**
index 09249d30d6fd08c9a4f3ecdcadd84ea3a329c7bc..cde53c4c396ac2724cb88f202e888352d2748d5a 100644 (file)
@@ -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;