[BUGFIX] Error in filelist for Storage context menu 04/19204/5
authorNicole Cordes <typo3@cordes.co>
Fri, 22 Mar 2013 22:40:35 +0000 (23:40 +0100)
committerAndreas Wolf <andreas.wolf@typo3.org>
Sun, 24 Mar 2013 10:25:33 +0000 (11:25 +0100)
The click menu for storage roots or mount points in filelist contains
functions which are not supported (e.g. cut/copy). This patch improves the
menu and only displays options which are allowed for storages/mount points
and for the current user.

Change-Id: I8e729eb3ea2d3977551ec689230ac9accfa76c4c
Resolves: #46575
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/19204
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
typo3/sysext/backend/Classes/ClickMenu/ClickMenu.php
typo3/sysext/backend/Classes/Tree/View/FolderTreeView.php
typo3/sysext/lang/locallang_core.xlf

index a41e46b..ee87be5 100644 (file)
@@ -27,6 +27,7 @@ namespace TYPO3\CMS\Backend\ClickMenu;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -734,6 +735,10 @@ class ClickMenu {
                                ->retrieveFileOrFolderObject($combinedIdentifier);
                if ($fileObject) {
                        $folder = FALSE;
+                       $isStorageRoot = FALSE;
+                       $isOnline = TRUE;
+                       $userMayViewStorage = FALSE;
+                       $userMayEditStorage = FALSE;
                        $identifier = $fileObject->getCombinedIdentifier();
                        if ($fileObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
                                $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder', array(
@@ -741,39 +746,70 @@ class ClickMenu {
                                        'title' => htmlspecialchars($fileObject->getName())
                                ));
                                $folder = TRUE;
+                               if ($fileObject->getIdentifier() === $fileObject->getStorage()->getRootLevelFolder()->getIdentifier()) {
+                                       $isStorageRoot = TRUE;
+                                       if ($GLOBALS['BE_USER']->check('tables_select', 'sys_file_storage')) {
+                                               $userMayViewStorage = TRUE;
+                                       }
+                                       if ($GLOBALS['BE_USER']->check('tables_modify', 'sys_file_storage')) {
+                                               $userMayEditStorage = TRUE;
+                                       }
+                               }
+                               if (!$fileObject->getStorage()->isOnline()) {
+                                       $isOnline = FALSE;
+                               }
                        } else {
                                $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileObject->getExtension(), array(
                                        'class' => 'absmiddle',
                                        'title' => htmlspecialchars($fileObject->getName() . ' (' . GeneralUtility::formatSize($fileObject->getSize()) . ')')
                                ));
                        }
+                       // Hide
+                       if (!in_array('hide', $this->disabledItems) && $isStorageRoot && $userMayEditStorage) {
+                               $record = BackendUtility::getRecord('sys_file_storage', $fileObject->getStorage()->getUid());
+                               $menuItems['hide'] = $this->DB_changeFlag(
+                                       'sys_file_storage',
+                                       $record,
+                                       'is_online',
+                                       $this->label($record['is_online'] ? 'offline' : 'online'),
+                                       'hide'
+                               );
+                       }
                        // Edit
-                       if (!in_array('edit', $this->disabledItems) && !$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileObject->getExtension())) {
-                               $menuItems['edit'] = $this->FILE_launch($identifier, 'file_edit.php', 'edit', 'edit_file.gif');
+                       if (!in_array('edit', $this->disabledItems)) {
+                               if (!$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileObject->getExtension())) {
+                                       $menuItems['edit'] = $this->FILE_launch($identifier, 'file_edit.php', 'edit', 'edit_file.gif');
+                               } elseif ($isStorageRoot && $userMayEditStorage) {
+                                       $menuItems['edit'] = $this->DB_edit('sys_file_storage', $fileObject->getStorage()->getUid());
+                               }
                        }
                        // Rename
-                       if (!in_array('rename', $this->disabledItems)) {
+                       if (!in_array('rename', $this->disabledItems) && !$isStorageRoot) {
                                $menuItems['rename'] = $this->FILE_launch($identifier, 'file_rename.php', 'rename', 'rename.gif');
                        }
                        // Upload
-                       if (!in_array('upload', $this->disabledItems) && $folder) {
+                       if (!in_array('upload', $this->disabledItems) && $folder && $isOnline) {
                                $menuItems['upload'] = $this->FILE_upload($identifier);
                        }
                        // New
-                       if (!in_array('new', $this->disabledItems) && $folder) {
+                       if (!in_array('new', $this->disabledItems) && $folder && $isOnline) {
                                $menuItems['new'] = $this->FILE_launch($identifier, 'file_newfolder.php', 'new', 'new_file.gif');
                        }
                        // Info
                        if (!in_array('info', $this->disabledItems)) {
-                               $menuItems['info'] = $this->fileInfo($identifier);
+                               if ($isStorageRoot && $userMayViewStorage) {
+                                       $menuItems['info'] = $this->DB_info('sys_file_storage', $fileObject->getStorage()->getUid());
+                               } elseif (!$folder) {
+                                       $menuItems['info'] = $this->fileInfo($identifier);
+                               }
                        }
                        $menuItems[] = 'spacer';
                        // Copy:
-                       if (!in_array('copy', $this->disabledItems)) {
+                       if (!in_array('copy', $this->disabledItems) && !$isStorageRoot) {
                                $menuItems['copy'] = $this->FILE_copycut($identifier, 'copy');
                        }
                        // Cut:
-                       if (!in_array('cut', $this->disabledItems)) {
+                       if (!in_array('cut', $this->disabledItems) && !$isStorageRoot) {
                                $menuItems['cut'] = $this->FILE_copycut($identifier, 'cut');
                        }
                        // Paste:
@@ -791,7 +827,12 @@ class ClickMenu {
                        $menuItems[] = 'spacer';
                        // Delete:
                        if (!in_array('delete', $this->disabledItems)) {
-                               $menuItems['delete'] = $this->FILE_delete($identifier);
+                               if ($isStorageRoot && $userMayEditStorage) {
+                                       $elInfo = array(GeneralUtility::fixed_lgd_cs($fileObject->getStorage()->getName(), $GLOBALS['BE_USER']->uc['titleLen']));
+                                       $menuItems['delete'] = $this->DB_delete('sys_file_storage', $fileObject->getStorage()->getUid(), $elInfo);
+                               } elseif (!$isStorageRoot) {
+                                       $menuItems['delete'] = $this->FILE_delete($identifier);
+                               }
                        }
                }
                // Adding external elements to the menuItems array
index 4db691e..110db2b 100644 (file)
@@ -130,11 +130,10 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
                $theFolderIcon = $this->addTagAttributes($icon, $this->titleAttrib ? $this->titleAttrib . '="' . $this->getTitleAttrib($folderObject) . '"' : '');
                // Wrap icon in click-menu link.
                if (!$this->ext_IconMode) {
-                       // Disable context menu for offline storages
-                       if (!$folderObject->getStorage()->isOnline()) {
-                               return $theFolderIcon;
+                       // Check storage access to wrap with click menu
+                       if ($folderObject->getStorage()->hasFolder('/')) {
+                               $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon, $folderObject->getCombinedIdentifier(), '', 0);
                        }
-                       $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon, $folderObject->getCombinedIdentifier(), '', 0);
                } elseif (!strcmp($this->ext_IconMode, 'titlelink')) {
                        $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($folderObject) . '\',this,\'' . $this->domIdPrefix . $this->getId($folderObject) . '\',' . $this->bank . ');';
                        $theFolderIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $theFolderIcon . '</a>';
@@ -152,11 +151,10 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
         * @internal
         */
        public function wrapTitle($title, \TYPO3\CMS\Core\Resource\Folder $folderObject, $bank = 0) {
-               // Disable context menu for offline storages
-               if (!$folderObject->getStorage()->isOnline()) {
+               // Check storage access to wrap with click menu
+               if (!$folderObject->getStorage()->hasFolder('/')) {
                        return $title;
                }
-
                $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($folderObject) . '\', this, \'' . $this->domIdPrefix . $this->getId($folderObject) . '\', ' . $bank . ');';
                $CSM = ' oncontextmenu="' . htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('', $folderObject->getCombinedIdentifier(), '', 0, ('&bank=' . $this->bank), '', TRUE)) . '"';
 
@@ -668,4 +666,4 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
 }
 
 
-?>
\ No newline at end of file
+?>
index 90b6219..7635457 100644 (file)
@@ -727,6 +727,12 @@ Would you like to save now in order to refresh the display?</source>
                        <trans-unit id="cm.unhide" xml:space="preserve">
                                <source>Unhide</source>
                        </trans-unit>
+                       <trans-unit id="cm.online" xml:space="preserve">
+                               <source>Turn online</source>
+                       </trans-unit>
+                       <trans-unit id="cm.offline" xml:space="preserve">
+                               <source>Turn offline</source>
+                       </trans-unit>
                        <trans-unit id="cm.upload" xml:space="preserve">
                                <source>Upload Files</source>
                        </trans-unit>