From 22a564ecea8edfba7da72dd1c71f8f7921f5f083 Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Thu, 19 Dec 2024 15:02:51 +0100 Subject: [PATCH] FEATURE: Allow modifying basic workspace visibility in edit dialog --- .../Controller/WorkspaceController.php | 41 ++++++++++++++++++- .../ViewModel/EditWorkspaceFormData.php | 1 + .../Classes/ViewModel/WorkspaceListItem.php | 6 +-- .../Features/Workspace/Actions/Edit.fusion | 2 +- .../Features/Workspace/Modals/Edit.fusion | 18 +++----- .../Resources/Public/Styles/Module.css | 1 + 6 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php b/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php index 29c58667e5..add9dc837b 100644 --- a/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php +++ b/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php @@ -47,7 +47,10 @@ use Neos\Neos\Domain\Model\User; use Neos\Neos\Domain\Model\WorkspaceClassification; use Neos\Neos\Domain\Model\WorkspaceDescription; +use Neos\Neos\Domain\Model\WorkspaceRole; +use Neos\Neos\Domain\Model\WorkspaceRoleAssignment; use Neos\Neos\Domain\Model\WorkspaceRoleAssignments; +use Neos\Neos\Domain\Model\WorkspaceRoleSubject; use Neos\Neos\Domain\Model\WorkspaceTitle; use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface; use Neos\Neos\Domain\Repository\SiteRepository; @@ -301,6 +304,15 @@ public function editAction(WorkspaceName $workspaceName): void } $workspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepositoryId, $workspace->workspaceName); + $workspaceRoleAssignments = $this->workspaceService->getWorkspaceRoleAssignments($contentRepositoryId, $workspace->workspaceName); + $isShared = false; + if ($workspaceMetadata->classification === WorkspaceClassification::SHARED) { + foreach ($workspaceRoleAssignments as $roleAssignment) { + if ($roleAssignment->role === WorkspaceRole::COLLABORATOR) { + $isShared = true; + } + } + } $editWorkspaceDto = new EditWorkspaceFormData( workspaceName: $workspace->workspaceName, @@ -309,6 +321,7 @@ public function editAction(WorkspaceName $workspaceName): void workspaceHasChanges: $this->computePendingChanges($workspace, $contentRepository)->total > 0, baseWorkspaceName: $workspace->baseWorkspaceName, baseWorkspaceOptions: $this->prepareBaseWorkspaceOptions($contentRepository, $workspaceName), + isShared: $isShared, ); $this->view->assign('editWorkspaceFormData', $editWorkspaceDto); @@ -321,13 +334,15 @@ public function editAction(WorkspaceName $workspaceName): void * @param WorkspaceName $workspaceName The name of the workspace that is being updated * @param WorkspaceTitle $title Human friendly title of the workspace, for example "Christmas Campaign" * @param WorkspaceDescription $description A description explaining the purpose of the new workspace - * @param WorkspaceName $baseWorkspace A description explaining the purpose of the new workspace + * @param WorkspaceName $baseWorkspace The base workspace to rebase this workspace onto if modified + * @param string $visibility Allow other editors to collaborate on this workspace if set to "shared" */ public function updateAction( WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceName $baseWorkspace, + string $visibility, ): void { $currentUser = $this->userService->getCurrentUser(); if ($currentUser === null) { @@ -369,6 +384,30 @@ public function updateAction( $description, ); + $workspaceRoleAssignments = $this->workspaceService->getWorkspaceRoleAssignments($contentRepositoryId, $workspaceName); + $sharedRoleAssignment = WorkspaceRoleAssignment::createForGroup( + 'Neos.Neos:AbstractEditor', + WorkspaceRole::COLLABORATOR, + ); + if ($visibility === 'shared') { + if (!$workspaceRoleAssignments->contains($sharedRoleAssignment)) { + $this->workspaceService->assignWorkspaceRole( + $contentRepositoryId, + $workspaceName, + WorkspaceRoleAssignment::createForGroup( + 'Neos.Neos:AbstractEditor', + WorkspaceRole::COLLABORATOR, + ) + ); + } + } elseif ($visibility === 'private' && $workspaceRoleAssignments->contains($sharedRoleAssignment)) { + $this->workspaceService->unassignWorkspaceRole( + $contentRepositoryId, + $workspaceName, + WorkspaceRoleSubject::createForGroup('Neos.Neos:AbstractEditor'), + ); + } + // Update Base Workspace $this->workspacePublishingService->changeBaseWorkspace( $contentRepositoryId, diff --git a/Neos.Workspace.Ui/Classes/ViewModel/EditWorkspaceFormData.php b/Neos.Workspace.Ui/Classes/ViewModel/EditWorkspaceFormData.php index c31f6e9f2b..977937c5c4 100644 --- a/Neos.Workspace.Ui/Classes/ViewModel/EditWorkspaceFormData.php +++ b/Neos.Workspace.Ui/Classes/ViewModel/EditWorkspaceFormData.php @@ -32,6 +32,7 @@ public function __construct( public bool $workspaceHasChanges, public WorkspaceName $baseWorkspaceName, public array $baseWorkspaceOptions, + public bool $isShared, ) { } } diff --git a/Neos.Workspace.Ui/Classes/ViewModel/WorkspaceListItem.php b/Neos.Workspace.Ui/Classes/ViewModel/WorkspaceListItem.php index 10faa8443b..999c422c7c 100644 --- a/Neos.Workspace.Ui/Classes/ViewModel/WorkspaceListItem.php +++ b/Neos.Workspace.Ui/Classes/ViewModel/WorkspaceListItem.php @@ -47,8 +47,7 @@ public function isPersonal(): bool public function isPrivate(): bool { - if ($this->classification !== WorkspaceClassification::SHARED->value || - $this->roleAssignments->count() > 1) { + if ($this->classification !== WorkspaceClassification::SHARED->value) { return false; } foreach ($this->roleAssignments as $roleAssignment) { @@ -61,9 +60,6 @@ public function isPrivate(): bool public function isShared(): bool { - if ($this->roleAssignments->count() > 1) { - return true; - } foreach ($this->roleAssignments as $roleAssignment) { if ($roleAssignment->role === WorkspaceRole::COLLABORATOR) { return true; diff --git a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/Edit.fusion b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/Edit.fusion index 33cd1b2ca5..805d829c88 100644 --- a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/Edit.fusion +++ b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/Edit.fusion @@ -10,7 +10,7 @@ Neos.Workspace.Ui.WorkspaceController.edit = Neos.Fusion:Component { baseWorkspaceName={props.editWorkspaceFormData.baseWorkspaceName.value} workspaceHasChanges={props.editWorkspaceFormData.workspaceHasChanges} baseWorkspaceOptions={props.editWorkspaceFormData.baseWorkspaceOptions} - visibility={props.editWorkspaceFormData.visibility} + isShared={props.editWorkspaceFormData.isShared} /> ` } diff --git a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Edit.fusion b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Edit.fusion index 0bf0a44541..a156231c01 100644 --- a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Edit.fusion +++ b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Edit.fusion @@ -7,12 +7,12 @@ prototype(Neos.Workspace.Ui:Component.Modal.Edit) < prototype(Neos.Fusion:Compon workspaceDescription = '' /// string baseWorkspaceName = '' - /// string - visibility = '' /// boolean workspaceHasChanges = false /// array baseWorkspaceOptions = ${[]} + /// boolean + isShared = false @private { i18n = ${I18n.id('').source('Main').package('Neos.Workspace.Ui')} @@ -50,6 +50,7 @@ prototype(Neos.Workspace.Ui:Component.Modal.Edit) < prototype(Neos.Fusion:Compon - + {private.i18n.id('workspaces.workspace.visibility.shared')}

{private.i18n.id('workspaces.workspace.visibility.shared.help')}


- + {private.i18n.id('workspaces.workspace.visibility.private')}

diff --git a/Neos.Workspace.Ui/Resources/Public/Styles/Module.css b/Neos.Workspace.Ui/Resources/Public/Styles/Module.css index 3eff7cb812..8e01ee7aee 100644 --- a/Neos.Workspace.Ui/Resources/Public/Styles/Module.css +++ b/Neos.Workspace.Ui/Resources/Public/Styles/Module.css @@ -31,6 +31,7 @@ .workspace-type-column { padding: 0 0.5ch; text-align: center; + width: 20px; } .workspace-type-column > * {