From 0e00dfacfaebd69bcb92cab6525ecfc80c341849 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:28:48 +0100 Subject: [PATCH] WIP adjustments for #5132 see https://github.com/neos/neos-development-collection/commit/916e51009e9c97b42aa32372b94d149a2022faeb --- .../Domain/Model/WorkspacePermissions.php | 5 +++++ .../Domain/Service/WorkspaceService.php | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Neos.Neos/Classes/Domain/Model/WorkspacePermissions.php b/Neos.Neos/Classes/Domain/Model/WorkspacePermissions.php index faf543259cf..05dd0945556 100644 --- a/Neos.Neos/Classes/Domain/Model/WorkspacePermissions.php +++ b/Neos.Neos/Classes/Domain/Model/WorkspacePermissions.php @@ -47,4 +47,9 @@ public static function all(): self { return new self(true, true, true); } + + public static function none(): self + { + return new self(false, false, false); + } } diff --git a/Neos.Neos/Classes/Domain/Service/WorkspaceService.php b/Neos.Neos/Classes/Domain/Service/WorkspaceService.php index 8d7e11d2e4f..d515a0205cc 100644 --- a/Neos.Neos/Classes/Domain/Service/WorkspaceService.php +++ b/Neos.Neos/Classes/Domain/Service/WorkspaceService.php @@ -302,19 +302,30 @@ public function getWorkspacePermissionsForUser(ContentRepositoryId $contentRepos } catch (NoSuchRoleException $e) { throw new \RuntimeException(sprintf('Failed to determine roles for user "%s", check your package dependencies: %s', $user->getId()->value, $e->getMessage()), 1727084881, $e); } + + $userIsAdministrator = in_array('Neos.Neos:Administrator', $userRoles, true); + + if ($userIsAdministrator) { + return WorkspacePermissions::all(); + } + $workspaceMetadata = $this->loadWorkspaceMetadata($contentRepositoryId, $workspaceName); - if ($workspaceMetadata !== null && $workspaceMetadata->ownerUserId !== null && $workspaceMetadata->ownerUserId->equals($user->getId())) { + $userIsOwner = $workspaceMetadata !== null && $workspaceMetadata->ownerUserId !== null && $workspaceMetadata->ownerUserId->equals($user->getId()); + + if ($userIsOwner) { return WorkspacePermissions::all(); } + $userWorkspaceRole = $this->loadWorkspaceRoleOfUser($contentRepositoryId, $workspaceName, $user->getId(), $userRoles); - $userIsAdministrator = in_array('Neos.Neos:Administrator', $userRoles, true); + if ($userWorkspaceRole === null) { - return WorkspacePermissions::create(false, false, $userIsAdministrator); + return WorkspacePermissions::none(); } + return WorkspacePermissions::create( read: $userWorkspaceRole->isAtLeast(WorkspaceRole::COLLABORATOR), write: $userWorkspaceRole->isAtLeast(WorkspaceRole::COLLABORATOR), - manage: $userIsAdministrator || $userWorkspaceRole->isAtLeast(WorkspaceRole::MANAGER), + manage: $userWorkspaceRole->isAtLeast(WorkspaceRole::MANAGER), ); }