Skip to content

(9.0) BUGFIX: Ensure private workspaces appear in the workspace module #4051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
*/
class Workspace
{

/**
* This prefix determines if a given workspace (name) is a user workspace.
*/
public const PERSONAL_WORKSPACE_PREFIX = 'user-';

/**
* @internal
*/
Expand All @@ -40,12 +46,33 @@ public function __construct(
) {
}


/**
* Checks if this workspace is a user's personal workspace
* @api
*/
public function isPersonalWorkspace(): bool
{
return str_starts_with($this->workspaceName->name, static::PERSONAL_WORKSPACE_PREFIX);
}

/**
* Checks if this workspace is shared only across users with access to internal workspaces, for example "reviewers"
*
* @return bool
* @api
*/
public function isPrivateWorkspace(): bool
{
return $this->workspaceOwner !== null && !$this->isPersonalWorkspace();
}

/**
* Checks if this workspace is shared across all editors
*
* @return boolean
*/
public function isInternalWorkspace()
public function isInternalWorkspace(): bool
{
return $this->baseWorkspaceName !== null && $this->workspaceOwner === null;
}
Expand All @@ -55,17 +82,9 @@ public function isInternalWorkspace()
*
* @return boolean
*/
public function isPublicWorkspace()
public function isPublicWorkspace(): bool
{
return $this->baseWorkspaceName === null && $this->workspaceOwner === null;
}

/**
* Checks if this workspace is a user's personal workspace
* @api
*/
public function isPersonalWorkspace(): bool
{
return $this->workspaceOwner !== null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public function indexAction()
'changesCounts' => $this->computeChangesCount($userWorkspace, $contentRepository),
'canPublish' => false,
'canManage' => false,
'canDelete' => false
'canDelete' => false,
'workspaceOwnerHumanReadable' => $userWorkspace->workspaceOwner ? $this->domainUserService->findByUserIdentifier(UserId::fromString($userWorkspace->workspaceOwner))?->getLabel() : null
]
];

foreach ($contentRepository->getWorkspaceFinder()->findAll() as $workspace) {
/** @var \Neos\ContentRepository\Core\Projection\Workspace\Workspace $workspace */
// FIXME: This check should be implemented through a specialized Workspace Privilege or something similar
// TODO $this->domainUserService->currentUserCanManageWorkspace($workspace)
if (!$workspace->isPersonalWorkspace() && ($workspace->isInternalWorkspace())) {
if (!$workspace->isPersonalWorkspace() && ($workspace->isInternalWorkspace() || $this->domainUserService->currentUserCanManageWorkspace($workspace))) {
$workspaceName = (string)$workspace->workspaceName;
$workspacesAndCounts[$workspaceName]['workspace'] = $workspace;
$workspacesAndCounts[$workspaceName]['changesCounts'] =
Expand All @@ -147,6 +147,7 @@ public function indexAction()
$workspacesAndCounts[$workspaceName]['dependentWorkspacesCount'] = count(
$contentRepository->getWorkspaceFinder()->findByBaseWorkspace($workspace->workspaceName)
);
$workspacesAndCounts[$workspaceName]['workspaceOwnerHumanReadable'] = $workspace->workspaceOwner ? $this->domainUserService->findByUserIdentifier(UserId::fromString($workspace->workspaceOwner))?->getLabel() : null;
}
}

Expand Down
36 changes: 21 additions & 15 deletions Neos.Neos/Classes/Domain/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ public function getCurrentUserIdentifier(): ?UserId
: null;
}

public function findByUserIdentifier(UserId $userId): ?User
{
return $this->partyRepository->findByIdentifier($userId->value);
}

/**
* Creates a user based on the given information
*
Expand Down Expand Up @@ -730,19 +735,18 @@ public function currentUserCanManageWorkspace(Workspace $workspace): bool
);
}

/** @todo implement me
if ($workspace->isPrivateWorkspace() && $workspace->getOwner() === $this->getCurrentUser()) {
return $this->privilegeManager->isPrivilegeTargetGranted(
'Neos.Neos:Backend.Module.Management.Workspaces.ManageOwnWorkspaces'
);

if ($workspace->isPrivateWorkspace() && $workspace->workspaceOwner === $this->persistenceManager->getIdentifierByObject($this->getCurrentUser())) {
return $this->privilegeManager->isPrivilegeTargetGranted(
'Neos.Neos:Backend.Module.Management.Workspaces.ManageOwnWorkspaces'
);
}

if ($workspace->isPrivateWorkspace() && $workspace->getOwner() !== $this->getCurrentUser()) {
return $this->privilegeManager->isPrivilegeTargetGranted(
'Neos.Neos:Backend.Module.Management.Workspaces.ManageAllPrivateWorkspaces'
);
if ($workspace->isPrivateWorkspace() && $workspace->workspaceOwner !== $this->persistenceManager->getIdentifierByObject($this->getCurrentUser())) {
return $this->privilegeManager->isPrivilegeTargetGranted(
'Neos.Neos:Backend.Module.Management.Workspaces.ManageAllPrivateWorkspaces'
);
}
*/

return false;
}
Expand Down Expand Up @@ -936,12 +940,14 @@ protected function findUserForAccount($username, $authenticationProviderName)

$user = $this->partyService->getAssignedPartyOfAccount($account);
if (!$user instanceof User) {
throw new Exception(sprintf(
'Unexpected user type "%s". An account with the identifier "%s" exists,'
throw new Exception(
sprintf(
'Unexpected user type "%s". An account with the identifier "%s" exists,'
. ' but the corresponding party is not a Neos User.',
get_class($user),
$username
), 1422270948);
get_class($user),
$username
), 1422270948
);
}

return $user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
<td>
<f:security.ifAccess privilegeTarget="Neos.Neos:Backend.Module.Administration.Users">
<f:then>
<neos:link.module path="administration/users" action="show" arguments="{user: workspace.owner}">{workspace.workspaceOwner}</neos:link.module>
<neos:link.module path="administration/users" action="show" arguments="{user: workspace.workspaceOwner}">{workspaceAndCounts.workspaceOwnerHumanReadable}</neos:link.module>
</f:then>
<f:else>
{workspace.workspaceOwner}
{workspaceAndCounts.workspaceOwnerHumanReadable}
</f:else>
</f:security.ifAccess>
</td>
Expand Down