Added acl support for boxes
authorMarcel Werk <burntime@woltlab.com>
Fri, 24 Jun 2016 09:58:13 +0000 (11:58 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 24 Jun 2016 09:58:13 +0000 (11:58 +0200)
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/acp/templates/boxAdd.tpl
wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php
wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php
wcfsetup/install/files/lib/data/box/Box.class.php
wcfsetup/install/files/lib/system/box/BoxHandler.class.php

index aca198bf12b21643a3d9a0b77c0e5beabef816f2..2f06ec0aca79cc65de0d0361a0e3ef14910fba82 100644 (file)
                        <name>com.woltlab.wcf.page</name>
                        <definitionname>com.woltlab.wcf.acl.simple</definitionname>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.box</name>
+                       <definitionname>com.woltlab.wcf.acl.simple</definitionname>
+               </type>
                <!-- /pages -->
                
                <!-- article list box condition -->
index 3e5f8fb7ebccd6f804d302138949001071d84239..c8c8fc28d6c9c982aa9b94657c6dd30e576a02f7 100644 (file)
@@ -61,6 +61,7 @@
                                <li><a href="{@$__wcf->getAnchor('general')}">{lang}wcf.acp.box.general{/lang}</a></li>
                                <li><a href="{@$__wcf->getAnchor('contents')}">{lang}wcf.acp.box.contents{/lang}</a></li>
                                <li><a href="{@$__wcf->getAnchor('pages')}">{lang}wcf.acp.box.pages{/lang}</a></li>
+                               <li><a href="{@$__wcf->getAnchor('acl')}">{lang}wcf.acp.box.acl{/lang}</a></li>
                                
                                {event name='tabMenuTabs'}
                        </ul>
                                </dl>
                        </div>
                </div>
+               
+               <div id="acl" class="tabMenuContent">
+                       {include file='aclSimple'}
+               </div>
        </div>
        
        <div class="formSubmit">
index 98008c2b8ea30941ba27ccf954ebf8f4cef4d09b..8e3d547045140ad2a590783c21e3ae06c667abab 100644 (file)
@@ -10,6 +10,7 @@ use wcf\data\object\type\ObjectTypeCache;
 use wcf\data\page\Page;
 use wcf\data\page\PageNodeTree;
 use wcf\form\AbstractForm;
+use wcf\system\acl\simple\SimpleAclHandler;
 use wcf\system\box\IConditionBoxController;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\IllegalLinkException;
@@ -168,6 +169,12 @@ class BoxAddForm extends AbstractForm {
         */
        public $pageNodeList;
        
+       /**
+        * acl values
+        * @var array
+        */
+       public $aclValues = [];
+       
        /**
         * @inheritDoc
         */
@@ -234,6 +241,7 @@ class BoxAddForm extends AbstractForm {
                if (isset($_POST['title']) && is_array($_POST['title'])) $this->title = ArrayUtil::trim($_POST['title']);
                if (isset($_POST['content']) && is_array($_POST['content'])) $this->content = ArrayUtil::trim($_POST['content']);
                if (isset($_POST['boxControllerID'])) $this->boxControllerID = intval($_POST['boxControllerID']);
+               if (isset($_POST['aclValues']) && is_array($_POST['aclValues'])) $this->aclValues = $_POST['aclValues'];
                
                if (WCF::getSession()->getPermission('admin.content.cms.canUseMedia')) {
                        if (isset($_POST['imageID']) && is_array($_POST['imageID'])) $this->imageID = ArrayUtil::toIntegerArray($_POST['imageID']);
@@ -421,6 +429,9 @@ class BoxAddForm extends AbstractForm {
                        $this->boxController->getProcessor()->saveConditions();
                }
                
+               // save acl
+               SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.box', $box->boxID, $this->aclValues);
+               
                // call saved event
                $this->saved();
                
@@ -431,7 +442,7 @@ class BoxAddForm extends AbstractForm {
                $this->boxType = $this->position = $this->cssClassName = $this->name = '';
                $this->showOrder = $this->boxControllerID = 0;
                $this->visibleEverywhere = $this->showHeader = 1;
-               $this->title = $this->content = $this->images = $this->imageID = $this->pageIDs = [];
+               $this->title = $this->content = $this->images = $this->imageID = $this->pageIDs = $this->aclValues = [];
                $this->boxController = null;
        }
        
@@ -466,7 +477,8 @@ class BoxAddForm extends AbstractForm {
                        'availableBoxControllers' => ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.boxController'),
                        'boxController' => $this->boxController,
                        'pageNodeList' => $this->pageNodeList,
-                       'pageHandlers' => $this->pageHandlers
+                       'pageHandlers' => $this->pageHandlers,
+                       'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues)
                ]);
        }
 }
index 3d25f1cbb5a4daa31838d395844862d3baef60e9..37ba3739dadc758a612ff4d170c42a9446177931 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\box\Box;
 use wcf\data\box\BoxAction;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\form\AbstractForm;
+use wcf\system\acl\simple\SimpleAclHandler;
 use wcf\system\box\IConditionBoxController;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\language\LanguageFactory;
@@ -119,6 +120,8 @@ class BoxEditForm extends BoxAddForm {
                        $this->boxController->getProcessor()->saveConditions();
                }
                
+               SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.box', $this->box->boxID, $this->aclValues);
+               
                // call saved event
                $this->saved();
                
@@ -171,6 +174,8 @@ class BoxEditForm extends BoxAddForm {
                                }
                        }
                        
+                       $this->aclValues = SimpleAclHandler::getInstance()->getValues('com.woltlab.wcf.box', $this->box->boxID);
+                       
                        $this->readBoxImages();
                }
        }
index 9b936b9092449ce9adf50e26c7335471e6c817f3..ba8d6d05f877ebf52c4b1f1ed250066c15b0cb75 100644 (file)
@@ -5,6 +5,7 @@ use wcf\data\media\ViewableMedia;
 use wcf\data\menu\Menu;
 use wcf\data\menu\MenuCache;
 use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\acl\simple\SimpleAclResolver;
 use wcf\system\box\IBoxController;
 use wcf\system\box\IConditionBoxController;
 use wcf\system\condition\ConditionHandler;
@@ -480,6 +481,15 @@ class Box extends DatabaseObject {
                return [];
        }
        
+       /**
+        * Returns true if this box is accessible by current user.
+        *
+        * @return      boolean
+        */
+       public function isAccessible() {
+               return SimpleAclResolver::getInstance()->canAccess('com.woltlab.wcf.box', $this->boxID);
+       }
+       
        /**
         * Returns the box with the given idnetifier.
         *
index dba652554d831cc3e840dd3a5b90a8fbef4b64bc..71d03185f77b7519051c2c035201878633527155 100644 (file)
@@ -47,9 +47,11 @@ class BoxHandler extends SingletonFactory {
                $boxList->sqlOrderBy = 'showOrder';
                $boxList->readObjects();
                foreach ($boxList as $box) {
-                       if (!isset($this->boxes[$box->position])) $this->boxes[$box->position] = [];
-                       $this->boxes[$box->position][] = $box;
-                       $this->boxesByIdentifier[$box->identifier] = $box;
+                       if ($box->isAccessible()) {
+                               if (!isset($this->boxes[$box->position])) $this->boxes[$box->position] = [];
+                               $this->boxes[$box->position][] = $box;
+                               $this->boxesByIdentifier[$box->identifier] = $box;
+                       }       
                }
        }