From cdc94f10f039510eee1646acde67f205246dcd45 Mon Sep 17 00:00:00 2001 From: Lukas Niestroj <niestrojlukas@gmail.com> Date: Tue, 14 Feb 2023 20:13:24 +0100 Subject: [PATCH] [TASK] Improve handling of non-versionable records Rephrase the error messages presented to the user after a failed attempt to create or update a version record in offline workspace without permissions. Further, disable all modification actions in the recordlist. Disabled buttons: edit, move, delete, copy, cut, new record, history. Resolves: #10551 Releases: main, 12.4 Change-Id: Ieada8032ca12b1b90b53ee700ed9a6ba55d55bd2 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79815 Tested-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Benni Mack <benni@typo3.org> --- .../Classes/RecordList/DatabaseRecordList.php | 22 ++++++++-- .../core/Classes/DataHandling/DataHandler.php | 44 +++++++++++++++++-- .../Private/Language/locallang_core.xlf | 6 +++ 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/typo3/sysext/backend/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/backend/Classes/RecordList/DatabaseRecordList.php index cf680f4f3db5..d22f2ee66cc6 100644 --- a/typo3/sysext/backend/Classes/RecordList/DatabaseRecordList.php +++ b/typo3/sysext/backend/Classes/RecordList/DatabaseRecordList.php @@ -778,6 +778,20 @@ class DatabaseRecordList '; } + if (!(BackendUtility::isTableWorkspaceEnabled($table))) { + // In case the table is not editable in workspace inform the user about the missing actions + if ($backendUser->workspaceAllowsLiveEditingInTable($table)) { + $message = $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.editingLiveRecordsWarning'); + } else { + $message = $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.notEditableInWorkspace'); + } + $tableActions .= ' + <span class="badge badge-warning"> + ' . htmlspecialchars($message, ENT_QUOTES | ENT_HTML5) . ' + </span> + '; + } + $collapseClass = $tableCollapsed && !$this->table ? 'collapse' : 'collapse show'; $dataState = $tableCollapsed && !$this->table ? 'collapsed' : 'expanded'; return ' @@ -2091,7 +2105,8 @@ class DatabaseRecordList $backendUser = $this->getBackendUserAuthentication(); return !($GLOBALS['TCA'][$table]['ctrl']['readOnly'] ?? false) && $this->editable - && ($backendUser->isAdmin() || $backendUser->check('tables_modify', $table)); + && ($backendUser->isAdmin() || $backendUser->check('tables_modify', $table)) + && (BackendUtility::isTableWorkspaceEnabled($table) || $backendUser->workspaceAllowsLiveEditingInTable($table)); } /** @@ -3178,7 +3193,7 @@ class DatabaseRecordList /** * Check whether the clipboard functionality is generally enabled. * In case a row is given, this checks if the record is neither - * a "delete placeholder", nor a translation. + * a "delete placeholder", nor a translation, nor a version */ protected function isClipboardFunctionalityEnabled(string $table, array $row = []): bool { @@ -3190,7 +3205,8 @@ class DatabaseRecordList !$this->isRecordDeletePlaceholder($row) && (int)($row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] ?? null] ?? 0) === 0 ) - ); + ) + && (BackendUtility::isTableWorkspaceEnabled($table) || $this->getBackendUserAuthentication()->workspaceAllowsLiveEditingInTable($table)); } /** diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php index a3a5ef08e97e..fe0f4312e081 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -944,7 +944,19 @@ class DataHandler implements LoggerAwareInterface $createNewVersion = true; } else { $recordAccess = false; - $this->log($table, 0, SystemLogDatabaseAction::VERSIONIZE, 0, SystemLogErrorClassification::USER_ERROR, 'Record could not be created in this workspace'); + $this->log( + $table, + 0, + SystemLogDatabaseAction::VERSIONIZE, + 0, + SystemLogErrorClassification::USER_ERROR, + 'Attempt to insert version record "{table}:{uid}" to this workspace failed. "Live" edit permissions of records from tables without versioning required', + -1, + [ + 'table' => $table, + 'uid' => $id, + ] + ); } } } @@ -1019,10 +1031,36 @@ class DataHandler implements LoggerAwareInterface $id = $this->autoVersionIdMap[$table][$id]; $recordAccess = true; } else { - $this->log($table, $id, SystemLogDatabaseAction::VERSIONIZE, 0, SystemLogErrorClassification::USER_ERROR, 'Could not be edited in offline workspace in the branch where found ({reason}). Auto-creation of version failed', -1, ['reason' => $errorCode]); + $this->log( + $table, + $id, + SystemLogDatabaseAction::VERSIONIZE, + 0, + SystemLogErrorClassification::USER_ERROR, + 'Attempt to version record "{table}:{uid}" failed [{reason}]', + -1, + [ + 'reason' => $errorCode, + 'table' => $table, + 'uid' => $id, + ] + ); } } else { - $this->log($table, $id, SystemLogDatabaseAction::VERSIONIZE, 0, SystemLogErrorClassification::USER_ERROR, 'Could not be edited in offline workspace in the branch where found ({reason}). Auto-creation of version not allowed in workspace', -1, ['reason' => $errorCode]); + $this->log( + $table, + $id, + SystemLogDatabaseAction::VERSIONIZE, + 0, + SystemLogErrorClassification::USER_ERROR, + 'Attempt to version record "{table}:{uid}" failed [{reason}]. "Live" edit permissions of records from tables without versioning required', + -1, + [ + 'reason' => $errorCode, + 'table' => $table, + 'uid' => $id, + ] + ); } } } diff --git a/typo3/sysext/core/Resources/Private/Language/locallang_core.xlf b/typo3/sysext/core/Resources/Private/Language/locallang_core.xlf index ed75e592f3f3..eed4d633fb8e 100644 --- a/typo3/sysext/core/Resources/Private/Language/locallang_core.xlf +++ b/typo3/sysext/core/Resources/Private/Language/locallang_core.xlf @@ -523,6 +523,12 @@ Do you want to continue WITHOUT saving?</source> <trans-unit id="labels.inconsistentLanguageWarning" resname="labels.inconsistentLanguageWarning"> <source>No translation parent assigned</source> </trans-unit> + <trans-unit id="labels.notEditableInWorkspace" resname="labels.notEditableInWorkspace"> + <source>Not editable in this workspace without "Live" edit permissions.</source> + </trans-unit> + <trans-unit id="labels.editingLiveRecordsWarning" resname="labels.editingLiveRecordsWarning"> + <source>Caution! These records are not versioned, you will edit the live records.</source> + </trans-unit> <trans-unit id="alttext.suggestSearching" resname="alttext.suggestSearching"> <source>Searching...</source> </trans-unit> -- GitLab