Skip to content

Commit 7559ceb

Browse files
committed
[TASK] Simplify DataHandler->workspaceCannotEditRecord()
Method name and the "false" indicating "ok" are still not cool, but the method internals can be simplified already. The method is protected in v14 and now requires the full record to be handed over instead of optionally the uid only. All method consumers do that already. Resolves: #106237 Related: #106236 Releases: main Change-Id: Ifa497edeeac5160a11bf8de742b53be7e9595ce1 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88327 Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
1 parent d9cebea commit 7559ceb

File tree

1 file changed

+16
-43
lines changed

1 file changed

+16
-43
lines changed

typo3/sysext/core/Classes/DataHandling/DataHandler.php

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9411,57 +9411,30 @@ public function workspaceCannotEditOfflineVersion(string $table, array $record)
94119411
}
94129412

94139413
/**
9414-
* Checking if editing of an existing record is allowed in current workspace if that is offline.
9415-
* Rules for editing in offline mode:
9416-
* - record supports versioning and is an offline version from workspace and has the current stage
9417-
* - or record (any) is in a branch where there is a page which is a version from the workspace
9418-
* and where the stage is not preventing records
9414+
* Checking if editing of an existing record is allowed in current workspace.
94199415
*
9420-
* @param string $table Table of record
9421-
* @param array|int $recData Integer (record uid) or array where fields are at least: pid, t3ver_wsid, t3ver_oid, t3ver_stage (if versioningWS is set)
9422-
* @return string|false String error code, telling the failure state. FALSE=All ok
9416+
* @return string|false Error string, else false = ok
94239417
*/
9424-
protected function workspaceCannotEditRecord($table, $recData): string|false
9418+
protected function workspaceCannotEditRecord(string $table, array $record): string|false
94259419
{
9426-
// Only test if the user is in a workspace
94279420
if ($this->BE_USER->workspace === 0) {
9421+
// Early skip if user is not in workspace
94289422
return false;
94299423
}
9430-
$tableSupportsVersioning = $this->tcaSchemaFactory->get($table)->isWorkspaceAware();
9431-
if (!is_array($recData)) {
9432-
$recData = BackendUtility::getRecord(
9433-
$table,
9434-
$recData,
9435-
'pid' . ($tableSupportsVersioning ? ',t3ver_oid,t3ver_wsid,t3ver_state,t3ver_stage' : '')
9436-
);
9437-
}
9438-
if (is_array($recData)) {
9439-
// We are testing a "version" (identified by having a t3ver_oid): it can be edited provided
9440-
// that workspace matches and versioning is enabled for the table.
9441-
$versionState = VersionState::tryFrom($recData['t3ver_state'] ?? 0);
9442-
if ($tableSupportsVersioning
9443-
&& (
9444-
$versionState === VersionState::NEW_PLACEHOLDER || (int)(($recData['t3ver_oid'] ?? 0) > 0)
9445-
)
9446-
) {
9447-
if ((int)$recData['t3ver_wsid'] !== $this->BE_USER->workspace) {
9448-
// So does workspace match?
9449-
return 'Workspace ID of record didn\'t match current workspace';
9450-
}
9451-
// So is the user allowed to "use" the edit stage within the workspace?
9452-
return $this->BE_USER->workspaceCheckStageForCurrent(0)
9453-
? false
9454-
: 'User\'s access level did not allow for editing';
9455-
}
9456-
// Check if we are testing a "live" record
9457-
if ($this->BE_USER->workspaceAllowsLiveEditingInTable($table)) {
9458-
// Live records are OK in the current workspace
9459-
return false;
9424+
if ($this->tcaSchemaFactory->get($table)->isWorkspaceAware() && (int)($record['t3ver_wsid'] ?? 0) > 0) {
9425+
// This is a workspace record
9426+
if ((int)$record['t3ver_wsid'] !== $this->BE_USER->workspace) {
9427+
// Workspaces of record and current user do not match
9428+
return 'Workspace ID of record does not match current user workspace';
94609429
}
9461-
// If not offline, output error
9462-
return 'Online record was not in a workspace';
9430+
// Is user allowed to use the edit stage within the workspace?
9431+
return $this->BE_USER->workspaceCheckStageForCurrent(0) ? false : 'User missing workspace editing access';
9432+
}
9433+
if ($this->BE_USER->workspaceAllowsLiveEditingInTable($table)) {
9434+
// Live records for this table are ok in current workspace
9435+
return false;
94639436
}
9464-
return 'No record';
9437+
return 'Editing live record is not allowed';
94659438
}
94669439

94679440
/**

0 commit comments

Comments
 (0)