Added ACL support for menus
authorAlexander Ebert <ebert@woltlab.com>
Sun, 30 Apr 2017 23:19:21 +0000 (01:19 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 30 Apr 2017 23:19:21 +0000 (01:19 +0200)
See #2255

wcfsetup/install/files/acp/templates/menuAdd.tpl
wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php
wcfsetup/install/files/lib/acp/form/MenuEditForm.class.php

index 6402b54291b8d4c08076d10e6e39e59a3aec2398..a79664de0ed04e9a6e8eb4103c9effdb7652fc0a 100644 (file)
 {/if}
 
 <form method="post" action="{if $action == 'add'}{link controller='MenuAdd'}{/link}{else}{link controller='MenuEdit' id=$menuID}{/link}{/if}">
-       <div class="section">
-               <dl{if $errorField == 'title'} class="formError"{/if}>
-                       <dt><label for="title">{lang}wcf.global.title{/lang}</label></dt>
-                       <dd>
-                               <input type="text" id="title" name="title" value="{$i18nPlainValues['title']}" autofocus class="long">
-                               {if $errorField == 'title'}
-                                       <small class="innerError">
-                                               {if $errorType == 'empty' || $errorType == 'multilingual'}
-                                                       {lang}wcf.global.form.error.{@$errorType}{/lang}
-                                               {else}
-                                                       {lang}wcf.acp.menu.title.error.{@$errorType}{/lang}
-                                               {/if}
-                                       </small>
-                               {/if}
-                               {include file='multipleLanguageInputJavascript' elementIdentifier='title' forceSelection=false}
-                       </dd>
-               </dl>
-               
-               {if $action == 'add' || $menu->identifier != 'com.woltlab.wcf.MainMenu'}
-                       <dl{if $errorField == 'position'} class="formError"{/if}>
-                               <dt><label for="position">{lang}wcf.acp.box.position{/lang}</label></dt>
+       {if $action == 'edit' && $menu->identifier == 'com.woltlab.wcf.MainMenu'}
+               {* editing the main menu *}
+               <div class="section">
+                       <dl{if $errorField == 'title'} class="formError"{/if}>
+                               <dt><label for="title">{lang}wcf.global.title{/lang}</label></dt>
                                <dd>
-                                       <select name="position" id="position">
-                                               {foreach from=$availablePositions item=availablePosition}
-                                                       <option value="{@$availablePosition}"{if $availablePosition == $position} selected{/if}>{lang}wcf.acp.box.position.{@$availablePosition}{/lang}</option>
-                                               {/foreach}
-                                       </select>
-                                       
-                                       {if $errorField == 'position'}
+                                       <input type="text" id="title" name="title" value="{$i18nPlainValues['title']}" autofocus class="long">
+                                       {if $errorField == 'title'}
                                                <small class="innerError">
-                                                       {if $errorType == 'empty'}
-                                                               {lang}wcf.global.form.error.empty{/lang}
+                                                       {if $errorType == 'empty' || $errorType == 'multilingual'}
+                                                               {lang}wcf.global.form.error.{@$errorType}{/lang}
                                                        {else}
-                                                               {lang}wcf.acp.box.position.error.{@$errorType}{/lang}
+                                                               {lang}wcf.acp.menu.title.error.{@$errorType}{/lang}
                                                        {/if}
                                                </small>
                                        {/if}
+                                       {include file='multipleLanguageInputJavascript' elementIdentifier='title' forceSelection=false}
                                </dd>
                        </dl>
+               </div>
+       {else}
+               {* anything, but the main menu *}
+               <div class="section tabMenuContainer" data-active="{$activeTabMenuItem}" data-store="activeTabMenuItem" id="pageTabMenuContainer">
+                       <nav class="tabMenu">
+                               <ul>
+                                       <li><a href="{@$__wcf->getAnchor('general')}">{lang}wcf.global.form.data{/lang}</a></li>
+                                       <li><a href="{@$__wcf->getAnchor('pages')}">{lang}wcf.acp.page.list{/lang}</a></li>
+                                       <li><a href="{@$__wcf->getAnchor('acl')}">{lang}wcf.acl.access{/lang}</a></li>
+                                       
+                                       {event name='tabMenuTabs'}
+                               </ul>
+                       </nav>
                        
-                       <dl>
-                               <dt><label for="showOrder">{lang}wcf.global.showOrder{/lang}</label></dt>
-                               <dd>
-                                       <input type="number" id="showOrder" name="showOrder" value="{@$showOrder}" class="tiny" min="0">
-                               </dd>
-                       </dl>
-                       
-                       <dl{if $errorField == 'cssClassName'} class="formError"{/if}>
-                               <dt><label for="cssClassName">{lang}wcf.acp.box.cssClassName{/lang}</label></dt>
-                               <dd>
-                                       <input type="text" id="cssClassName" name="cssClassName" value="{$cssClassName}" class="long">
-                                       {if $errorField == 'cssClassName'}
-                                               <small class="innerError">
-                                                       {if $errorType == 'empty'}
-                                                               {lang}wcf.global.form.error.empty{/lang}
-                                                       {else}
-                                                               {lang}wcf.acp.box.cssClassName.error.{@$errorType}{/lang}
+                       <div id="general" class="tabMenuContent">
+                               <div class="section">
+                                       <dl{if $errorField == 'title'} class="formError"{/if}>
+                                               <dt><label for="title">{lang}wcf.global.title{/lang}</label></dt>
+                                               <dd>
+                                                       <input type="text" id="title" name="title" value="{$i18nPlainValues['title']}" autofocus class="long">
+                                                       {if $errorField == 'title'}
+                                                               <small class="innerError">
+                                                                       {if $errorType == 'empty' || $errorType == 'multilingual'}
+                                                                               {lang}wcf.global.form.error.{@$errorType}{/lang}
+                                                                       {else}
+                                                                               {lang}wcf.acp.menu.title.error.{@$errorType}{/lang}
+                                                                       {/if}
+                                                               </small>
                                                        {/if}
-                                               </small>
-                                       {/if}
-                               </dd>
-                       </dl>
+                                                       {include file='multipleLanguageInputJavascript' elementIdentifier='title' forceSelection=false}
+                                               </dd>
+                                       </dl>
+                                       
+                                       <dl{if $errorField == 'position'} class="formError"{/if}>
+                                               <dt><label for="position">{lang}wcf.acp.box.position{/lang}</label></dt>
+                                               <dd>
+                                                       <select name="position" id="position">
+                                                               {foreach from=$availablePositions item=availablePosition}
+                                                                       <option value="{@$availablePosition}"{if $availablePosition == $position} selected{/if}>{lang}wcf.acp.box.position.{@$availablePosition}{/lang}</option>
+                                                               {/foreach}
+                                                       </select>
+                                                       
+                                                       {if $errorField == 'position'}
+                                                               <small class="innerError">
+                                                                       {if $errorType == 'empty'}
+                                                                               {lang}wcf.global.form.error.empty{/lang}
+                                                                       {else}
+                                                                               {lang}wcf.acp.box.position.error.{@$errorType}{/lang}
+                                                                       {/if}
+                                                               </small>
+                                                       {/if}
+                                               </dd>
+                                       </dl>
+                                       
+                                       <dl>
+                                               <dt><label for="showOrder">{lang}wcf.global.showOrder{/lang}</label></dt>
+                                               <dd>
+                                                       <input type="number" id="showOrder" name="showOrder" value="{@$showOrder}" class="tiny" min="0">
+                                               </dd>
+                                       </dl>
+                                       
+                                       <dl{if $errorField == 'cssClassName'} class="formError"{/if}>
+                                               <dt><label for="cssClassName">{lang}wcf.acp.box.cssClassName{/lang}</label></dt>
+                                               <dd>
+                                                       <input type="text" id="cssClassName" name="cssClassName" value="{$cssClassName}" class="long">
+                                                       {if $errorField == 'cssClassName'}
+                                                               <small class="innerError">
+                                                                       {if $errorType == 'empty'}
+                                                                               {lang}wcf.global.form.error.empty{/lang}
+                                                                       {else}
+                                                                               {lang}wcf.acp.box.cssClassName.error.{@$errorType}{/lang}
+                                                                       {/if}
+                                                               </small>
+                                                       {/if}
+                                               </dd>
+                                       </dl>
+                                       
+                                       <dl>
+                                               <dt></dt>
+                                               <dd>
+                                                       <label><input type="checkbox" id="showHeader" name="showHeader" value="1"{if $showHeader} checked{/if}> {lang}wcf.acp.box.showHeader{/lang}</label>
+                                               </dd>
+                                       </dl>
+                               </div>
+                       </div>
                        
-                       <dl>
-                               <dt></dt>
-                               <dd>
-                                       <label><input type="checkbox" id="showHeader" name="showHeader" value="1"{if $showHeader} checked{/if}> {lang}wcf.acp.box.showHeader{/lang}</label>
-                               </dd>
-                       </dl>
                        
-                       <dl>
-                               <dt></dt>
-                               <dd>
-                                       <label><input type="checkbox" id="visibleEverywhere" name="visibleEverywhere" value="1"{if $visibleEverywhere} checked{/if}> {lang}wcf.acp.box.visibleEverywhere{/lang}</label>
-                                       <script data-relocate="true">
-                                               elById('visibleEverywhere').addEventListener('change', function() {
-                                                       if (this.checked) {
-                                                               elShow(elById('visibilityExceptionHidden'));
-                                                               elHide(elById('visibilityExceptionVisible'));
-                                                       }
-                                                       else {
-                                                               elHide(elById('visibilityExceptionHidden'));
-                                                               elShow(elById('visibilityExceptionVisible'));
-                                                       }
-                                               });
-                                       </script>
-                               </dd>
-                       </dl>
                        
-                       <dl>
-                               <dt>
-                                       <span id="visibilityExceptionVisible"{if $visibleEverywhere} style="display: none"{/if}>{lang}wcf.acp.box.visibilityException.visible{/lang}</span>
-                                       <span id="visibilityExceptionHidden"{if !$visibleEverywhere} style="display: none"{/if}>{lang}wcf.acp.box.visibilityException.hidden{/lang}</span>
-                               </dt>
-                               <dd>
-                                       <ul class="scrollableCheckboxList">
-                                               {foreach from=$pageNodeList item=pageNode}
-                                                       <li{if $pageNode->getDepth() > 1} style="padding-left: {$pageNode->getDepth()*20-20}px"{/if}>
-                                                               <label><input type="checkbox" name="pageIDs[]" value="{@$pageNode->pageID}"{if $pageNode->pageID|in_array:$pageIDs} checked{/if}> {$pageNode->name}</label>
-                                                       </li>
-                                               {/foreach}
-                                       </ul>
-                               </dd>
-                       </dl>
-               {/if}
-               
-               {event name='dataFields'}
-       </div>
+                       <div id="pages" class="tabMenuContent">
+                               <div class="section">
+                                       <dl>
+                                               <dt></dt>
+                                               <dd>
+                                                       <label><input type="checkbox" id="visibleEverywhere" name="visibleEverywhere" value="1"{if $visibleEverywhere} checked{/if}> {lang}wcf.acp.box.visibleEverywhere{/lang}</label>
+                                                       <script data-relocate="true">
+                                                               elById('visibleEverywhere').addEventListener('change', function() {
+                                                                       if (this.checked) {
+                                                                               elShow(elById('visibilityExceptionHidden'));
+                                                                               elHide(elById('visibilityExceptionVisible'));
+                                                                       }
+                                                                       else {
+                                                                               elHide(elById('visibilityExceptionHidden'));
+                                                                               elShow(elById('visibilityExceptionVisible'));
+                                                                       }
+                                                               });
+                                                       </script>
+                                               </dd>
+                                       </dl>
+                                       
+                                       <dl>
+                                               <dt>
+                                                       <span id="visibilityExceptionVisible"{if $visibleEverywhere} style="display: none"{/if}>{lang}wcf.acp.box.visibilityException.visible{/lang}</span>
+                                                       <span id="visibilityExceptionHidden"{if !$visibleEverywhere} style="display: none"{/if}>{lang}wcf.acp.box.visibilityException.hidden{/lang}</span>
+                                               </dt>
+                                               <dd>
+                                                       <ul class="scrollableCheckboxList">
+                                                               {foreach from=$pageNodeList item=pageNode}
+                                                                       <li{if $pageNode->getDepth() > 1} style="padding-left: {$pageNode->getDepth()*20-20}px"{/if}>
+                                                                               <label><input type="checkbox" name="pageIDs[]" value="{@$pageNode->pageID}"{if $pageNode->pageID|in_array:$pageIDs} checked{/if}> {$pageNode->name}</label>
+                                                                       </li>
+                                                               {/foreach}
+                                                       </ul>
+                                               </dd>
+                                       </dl>
+                                       
+                                       {event name='dataFields'}
+                               </div>
+                       </div>
+                       
+                       <div id="acl" class="tabMenuContent">
+                               {include file='aclSimple'}
+                       </div>
+               </div>
+       {/if}
        
        {event name='sections'}
        
index b753c4911d92b40940ba8969b91243631e7753e3..9e60537d5de39058a350a8adec8084ac47e1d33f 100644 (file)
@@ -5,6 +5,7 @@ use wcf\data\menu\MenuAction;
 use wcf\data\menu\MenuEditor;
 use wcf\data\page\PageNodeTree;
 use wcf\form\AbstractForm;
+use wcf\system\acl\simple\SimpleAclHandler;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\UserInputException;
 use wcf\system\language\I18nHandler;
@@ -75,6 +76,12 @@ class MenuAddForm extends AbstractForm {
         */
        public $pageIDs = [];
        
+       /**
+        * acl values
+        * @var array
+        */
+       public $aclValues = [];
+       
        /**
         * @inheritDoc
         */
@@ -101,6 +108,7 @@ class MenuAddForm extends AbstractForm {
                if (isset($_POST['cssClassName'])) $this->cssClassName = StringUtil::trim($_POST['cssClassName']);
                if (isset($_POST['showHeader'])) $this->showHeader = intval($_POST['showHeader']);
                if (isset($_POST['pageIDs']) && is_array($_POST['pageIDs'])) $this->pageIDs = ArrayUtil::toIntegerArray($_POST['pageIDs']);
+               if (isset($_POST['aclValues']) && is_array($_POST['aclValues'])) $this->aclValues = $_POST['aclValues'];
        }
        
        /**
@@ -188,10 +196,18 @@ class MenuAddForm extends AbstractForm {
                                'title' => 'wcf.menu.com.woltlab.wcf.genericMenu'.$menuEditor->menuID
                        ]);
                }
+               
+               // save acl
+               SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.box', $menuEditor->getDecoratedObject()->getBox()->boxID, $this->aclValues);
+               
                $this->saved();
                
                // reset values
-               $this->title = '';
+               $this->cssClassName = $this->title = '';
+               $this->position = 'contentTop';
+               $this->showOrder = 0;
+               $this->visibleEverywhere = $this->showHeader = 1;
+               $this->pageIDs = $this->aclValues = [];
                
                // show success message
                WCF::getTPL()->assign('success', true);
@@ -217,7 +233,8 @@ class MenuAddForm extends AbstractForm {
                        'showHeader' => $this->showHeader,
                        'pageIDs' => $this->pageIDs,
                        'availablePositions' => Box::$availableMenuPositions,
-                       'pageNodeList' => (new PageNodeTree())->getNodeList()
+                       'pageNodeList' => (new PageNodeTree())->getNodeList(),
+                       'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues)
                ]);
        }
 }
index fcd60b872c81e2b2ec80df6df1cb9ff8b309caa3..733c8e7a83e642d7c258d75792ba0e7f0c012de8 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\box\BoxAction;
 use wcf\data\menu\Menu;
 use wcf\data\menu\MenuAction;
 use wcf\form\AbstractForm;
+use wcf\system\acl\simple\SimpleAclHandler;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\language\I18nHandler;
 use wcf\system\language\LanguageFactory;
@@ -98,6 +99,8 @@ class MenuEditForm extends MenuAddForm {
                        $boxAction->executeAction();
                }
                
+               SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.box', $this->menu->getBox()->boxID, $this->aclValues);
+               
                $this->saved();
                
                // show success message
@@ -120,6 +123,8 @@ class MenuEditForm extends MenuAddForm {
                        $this->visibleEverywhere = $this->menu->getBox()->visibleEverywhere;
                        $this->pageIDs = $this->menu->getBox()->getPageIDs();
                        $this->showHeader = $this->menu->getBox()->showHeader;
+                       
+                       $this->aclValues = SimpleAclHandler::getInstance()->getValues('com.woltlab.wcf.box', $this->menu->getBox()->boxID);
                }
        }