[BUGFIX] Show "add pages" button to qualified users only 29/43629/4
authorDaniel Goerz <ervaude@gmail.com>
Tue, 29 Sep 2015 16:10:03 +0000 (18:10 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 30 Sep 2015 14:47:57 +0000 (16:47 +0200)
If an editor has no rights to create new pages of any type the
icon for showing the document toolbar for the drag'n drop
adding is shown nevertheless.

This patch changes this behavior. The icon is only shown
after the AJAX call returns at least one allowed doktype.

Change-Id: I35050e4cfe923b58c26d85ce39a69dc69aa58515
Resolves: #26901
Releases: master
Reviewed-on: http://review.typo3.org/43629
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Tree/Pagetree/ExtdirectTreeDataProvider.php
typo3/sysext/backend/Resources/Public/JavaScript/extjs/components/pagetree/javascript/toppanel.js

index 8dd5dcd..defbcfa 100644 (file)
@@ -125,8 +125,12 @@ class ExtdirectTreeDataProvider extends \TYPO3\CMS\Backend\Tree\AbstractExtJsTre
                }
                $doktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.doktypesToShowInNewPageDragArea'));
                $output = array();
-               $allowedDoktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select']);
+               $allowedDoktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], TRUE);
                $isAdmin = $GLOBALS['BE_USER']->isAdmin();
+               // Early return if backend user may not create any doktype
+               if (!$isAdmin && empty($allowedDoktypes)) {
+                       return $output;
+               }
                foreach ($doktypes as $doktype) {
                        if (!$isAdmin && !in_array($doktype, $allowedDoktypes)) {
                                continue;
index db418ec..0015a04 100644 (file)
@@ -426,18 +426,23 @@ TYPO3.Components.PageTree.TopPanel = Ext.extend(Ext.Panel, {
                });
 
                this.dataProvider.getNodeTypes(function(response) {
-                       for (var i = 0; i < response.length; ++i) {
-                               response[i].template = this.getButtonTemplate();
-                               newNodeToolbar.addItem(response[i]);
+                       var amountOfNodeTypes = response.length;
+                       if (amountOfNodeTypes > 0) {
+                               topPanelButton.show();
+                               for (var i = 0; i < amountOfNodeTypes; ++i) {
+                                       response[i].template = this.getButtonTemplate();
+                                       newNodeToolbar.addItem(response[i]);
+                               }
+                               newNodeToolbar.doLayout();
                        }
-                       newNodeToolbar.doLayout();
                }, this);
 
                var topPanelButton = new Ext.Button({
                        id: this.id + '-button-newNode',
                        cls: this.id + '-button',
                        text: TYPO3.Components.PageTree.Icons.NewNode,
-                       tooltip: TYPO3.Components.PageTree.LLL.buttonNewNode
+                       tooltip: TYPO3.Components.PageTree.LLL.buttonNewNode,
+                       hidden: true
                });
 
                this.addButton(topPanelButton, newNodeToolbar);