From ccdd46cffb8ae0915133a1b95bf28fd94d33d8f6 Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Tue, 17 Dec 2024 20:23:30 +0100 Subject: [PATCH] FEATURE: Set basic visibility on workspace creation --- .../Domain/Model/WorkspaceRoleAssignments.php | 15 +++ .../Controller/WorkspaceController.php | 10 +- .../Features/Workspace/Actions/Delete.fusion | 2 + .../Features/Workspace/Actions/New.fusion | 103 ++------------- .../Features/Workspace/Modals/Create.fusion | 125 ++++++++++++++++++ .../Features/Workspace/Modals/Delete.fusion | 2 + 6 files changed, 162 insertions(+), 95 deletions(-) create mode 100644 Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Create.fusion diff --git a/Neos.Neos/Classes/Domain/Model/WorkspaceRoleAssignments.php b/Neos.Neos/Classes/Domain/Model/WorkspaceRoleAssignments.php index 87b33bc0d3b..c10d1e0ba6e 100644 --- a/Neos.Neos/Classes/Domain/Model/WorkspaceRoleAssignments.php +++ b/Neos.Neos/Classes/Domain/Model/WorkspaceRoleAssignments.php @@ -82,6 +82,21 @@ public static function createForSharedWorkspace(UserId $userId): self ); } + /** + * Default role assignment to be specified at creation via {@see WorkspaceService::createSharedWorkspace()} + * + * The specified user is manager + */ + public static function createForPrivateWorkspace(UserId $userId): self + { + return new self( + WorkspaceRoleAssignment::createForUser( + $userId, + WorkspaceRole::MANAGER, + ) + ); + } + public function isEmpty(): bool { return $this->assignments === []; diff --git a/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php b/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php index 3f59855a88b..45b4aaded15 100644 --- a/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php +++ b/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php @@ -52,6 +52,8 @@ 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\WorkspaceTitle; use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface; @@ -234,6 +236,7 @@ public function createAction( WorkspaceTitle $title, WorkspaceName $baseWorkspace, WorkspaceDescription $description, + string $visibility = 'shared', ): void { $currentUser = $this->userService->getCurrentUser(); if ($currentUser === null) { @@ -244,15 +247,16 @@ public function createAction( $workspaceName = $this->workspaceService->getUniqueWorkspaceName($contentRepositoryId, $title->value); try { + $assignments = $visibility === 'shared' ? + WorkspaceRoleAssignments::createForSharedWorkspace($currentUser->getId()) : + WorkspaceRoleAssignments::createForPrivateWorkspace($currentUser->getId()); $this->workspaceService->createSharedWorkspace( $contentRepositoryId, $workspaceName, $title, $description, $baseWorkspace, - WorkspaceRoleAssignments::createForSharedWorkspace( - $currentUser->getId() - ) + $assignments ); } catch (WorkspaceAlreadyExists $exception) { $this->addFlashMessage( diff --git a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/Delete.fusion b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/Delete.fusion index 39bdb8ed5e2..18600d3651c 100644 --- a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/Delete.fusion +++ b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/Delete.fusion @@ -2,7 +2,9 @@ # Delete confirmation modal with empty POST response # Neos.Workspace.Ui.WorkspaceController.delete = Neos.Fusion:Component { + /// string workspaceName = ${workspaceName} + /// string workspaceTitle = ${workspaceTitle} renderer = Neos.Fusion:Match { diff --git a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/New.fusion b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/New.fusion index 50698a05999..e74e2f9aa9a 100644 --- a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/New.fusion +++ b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Actions/New.fusion @@ -1,97 +1,16 @@ Neos.Workspace.Ui.WorkspaceController.new = Neos.Fusion:Component { + /// array baseWorkspaceOptions = ${baseWorkspaceOptions} - workspace = ${workspace} - i18n = ${I18n.id('').source('Main').package('Neos.Workspace.Ui')} - popoverId = 'create-workspace-popover' - prototype(Neos.Fusion.Form:LabelRenderer) { - translationPackage = 'Neos.Workspace.Ui' - translationSource = 'Main' + renderer = Neos.Fusion:Match { + @subject = ${request.httpRequest.method} + # Render the create modal + @default = afx` + + ` + # Empty template for the delete response as the payload is contained in the HTTP headers + POST = '' } - - prototype(Neos.Fusion.Form:Neos.BackendModule.FieldContainer) { - translation.label { - package = 'Neos.Workspace.Ui' - source = 'Main' - } - } - - renderer = afx` -
-
- -
- {props.i18n.id('workspaces.createNewWorkspace')} -
-
- -
-
- - - - - - - - - - - - - {workspaceTitle} - - - -
-
-
- - - {props.i18n.id('workspaces.createWorkspace')} - -
-
-
- ` } diff --git a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Create.fusion b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Create.fusion new file mode 100644 index 00000000000..9030bb72b2a --- /dev/null +++ b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Create.fusion @@ -0,0 +1,125 @@ +prototype(Neos.Workspace.Ui:Component.Modal.Create) < prototype(Neos.Fusion:Component) { + /// array + baseWorkspaceOptions = null + + @private { + i18n = ${I18n.id('').source('Main').package('Neos.Workspace.Ui')} + popoverId = 'create-workspace-popover' + } + + prototype(Neos.Fusion.Form:LabelRenderer) { + translationPackage = 'Neos.Workspace.Ui' + translationSource = 'Main' + } + + prototype(Neos.Fusion.Form:Neos.BackendModule.FieldContainer) { + translation.label { + package = 'Neos.Workspace.Ui' + source = 'Main' + } + } + + renderer = afx` +
+
+ +
+ {private.i18n.id('workspaces.createNewWorkspace')} +
+
+ +
+
+ + + + + + + + + + + + {workspaceTitle} + + + + + + + {private.i18n.id('workspaces.workspace.visibility.internal')} + +

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

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

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

+
+
+
+ +
+
+ ` +} diff --git a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Delete.fusion b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Delete.fusion index aa72e299239..6fe25e1582e 100644 --- a/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Delete.fusion +++ b/Neos.Workspace.Ui/Resources/Private/Fusion/Features/Workspace/Modals/Delete.fusion @@ -1,5 +1,7 @@ prototype(Neos.Workspace.Ui:Component.Modal.Delete) < prototype(Neos.Fusion:Component) { + /// string workspaceName = null + /// string workspaceTitle = null @private {