[BUGFIX] Respect editlock in history/undo-module 04/57804/7
authorGuido Schmechel <guido.schmechel@brandung.de>
Sat, 4 Aug 2018 10:36:07 +0000 (12:36 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Mon, 24 Sep 2018 18:32:06 +0000 (20:32 +0200)
Now the editlock information of the page is retreived and used
as condition for the rollback command icon.

Releases: master
Resolves: #69114
Change-Id: Ie3122a511c96ca6d6d7913e3e1efcfe3d4d84cd6
Reviewed-on: https://review.typo3.org/57804
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Guido Schmechel <guido.schmechel@brandung.de>
Tested-by: Guido Schmechel <guido.schmechel@brandung.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/Controller/ContentElement/ElementHistoryController.php
typo3/sysext/backend/Resources/Private/Language/locallang_show_rechis.xlf
typo3/sysext/backend/Resources/Private/Partials/RecordHistory/History.html

index 8c5e59a..e3cac97 100644 (file)
@@ -64,6 +64,13 @@ class ElementHistoryController
     protected $moduleTemplate;
 
     /**
+     * Restrict editing by non-Admins (0-no, 1-yes)
+     *
+     * @var bool
+     */
+    protected $editLock = false;
+
+    /**
      * Constructor
      */
     public function __construct()
@@ -123,6 +130,7 @@ class ElementHistoryController
         $elementData = $this->historyObject->getElementData();
         if ($elementData) {
             $this->setPagePath($elementData[0], $elementData[1]);
+            $this->editLock = $this->getEditLockFromElement($elementData[0], $elementData[1]);
             // Get link to page history if the element history is shown
             if ($elementData[0] !== 'pages') {
                 $this->view->assign('singleElement', true);
@@ -138,6 +146,7 @@ class ElementHistoryController
         }
 
         $this->view->assign('TYPO3_REQUEST_URI', $normalizedParams->getRequestUrl());
+        $this->view->assign('editLock', $this->editLock);
 
         // Setting up the buttons and markers for docheader
         $this->getButtons($request);
@@ -503,4 +512,29 @@ class ElementHistoryController
     {
         return $GLOBALS['BE_USER'];
     }
+
+    /**
+     * Get the editlock value from page of a history element
+     *
+     * @param string $tableName
+     * @param int $elementUid
+     *
+     * @return bool
+     */
+    protected function getEditLockFromElement($tableName, $elementUid): bool
+    {
+        // If the user is admin, then he may always edit the page.
+        if ($this->getBackendUser()->isAdmin()) {
+            return false;
+        }
+
+        $record = BackendUtility::getRecord($tableName, $elementUid, '*', '', false);
+        // we need the parent page record for the editlock info if element isn't a page
+        if ($tableName !== 'pages') {
+            $pageId = $record['pid'];
+            $record = BackendUtility::getRecord('pages', $pageId, '*', '', false);
+        }
+
+        return (bool)$record['editlock'];
+    }
 }
index 1782c93..395d5a8 100644 (file)
                        <trans-unit id="noDifferences">
                                <source>There are no differences to the current page!</source>
                        </trans-unit>
+                       <trans-unit id="editLockIsActive">
+                               <source>Editing is blocked for non-admins</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
index 8496379..2569fa6 100644 (file)
                <tbody>
                <f:for each="{history}" as="historyRow">
                        <tr>
-                               <td><span><span title="{f:translate(key: 'LLL:EXT:backend/Resources/Private/Language/locallang_show_rechis.xlf:sumUpChanges')}">
-                                       <a href="{historyRow.diffUrl}"><core:icon identifier="actions-document-history-open" /></a>
-                               </span></span></td>
+                               <td>
+                                       <f:if condition="{editLock}">
+                                               <f:then>
+                                                       <button class="btn btn-default disabled" title="{f:translate(key: 'LLL:EXT:backend/Resources/Private/Language/locallang_show_rechis.xlf:editLockIsActive')}">
+                                                               <core:icon identifier="actions-document-history-open" />
+                                                       </button>
+                                               </f:then>
+                                               <f:else>
+                                                       <a class="btn btn-default" href="{historyRow.diffUrl}" title="{f:translate(key: 'LLL:EXT:backend/Resources/Private/Language/locallang_show_rechis.xlf:sumUpChanges')}">
+                                                               <core:icon identifier="actions-document-history-open" />
+                                                       </a>
+                                               </f:else>
+                                       </f:if>
+                               </td>
                                <td>{historyRow.time}</td>
                                <td>{historyRow.age}</td>
                                <td>