Skip to content
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

!!! TASK: Move workspace module to separate package #4665

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -63,6 +63,35 @@ public function findOneByName(WorkspaceName $name): ?Workspace
return $workspace;
}


public function findOneByTitle(WorkspaceTitle $title): ?Workspace
{
# TODO: Compare lowercase to prevent two workspaces "Anke" and "anke" to be created
$workspace = $this->workspaceRuntimeCache->getWorkspaceByTitle($title);
if ($workspace !== null) {
return $workspace;
}

$connection = $this->client->getConnection();
$workspaceRow = $connection->executeQuery(
'
SELECT * FROM ' . $this->tableName . '
WHERE workspaceTitle = :workspaceTitle
',
[
'workspaceTitle' => $title->value,
]
)->fetchAssociative();

if ($workspaceRow === false) {
return null;
}

$workspace = $this->createWorkspaceFromDatabaseRow($workspaceRow);
$this->workspaceRuntimeCache->setWorkspace($workspace);
return $workspace;
}

public function findOneByCurrentContentStreamId(
ContentStreamId $contentStreamId
): ?Workspace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle;

/**
* Workspace Runtime Cache
Expand All @@ -31,6 +32,11 @@ final class WorkspaceRuntimeCache
*/
private array $cachedWorkspacesByName = [];

/**
* @var array<string,Workspace>
*/
private array $cachedWorkspacesByTitle = [];

/**
* @var array<string,Workspace>
*/
Expand All @@ -43,6 +49,7 @@ public function disableCache(): void
{
$this->cacheEnabled = false;
$this->cachedWorkspacesByName = [];
$this->cachedWorkspacesByTitle = [];
$this->cachedWorkspacesByContentStreamId = [];
}

Expand All @@ -54,6 +61,14 @@ public function getWorkspaceByName(WorkspaceName $name): ?Workspace
return null;
}

public function getWorkspaceByTitle(WorkspaceTitle $title): ?Workspace
{
if ($this->cacheEnabled === true && isset($this->cachedWorkspacesByTitle[$title->value])) {
return $this->cachedWorkspacesByTitle[$title->value];
}
return null;
}

public function setWorkspace(Workspace $workspace): void
{
if ($this->cacheEnabled === true) {
Expand Down
35 changes: 28 additions & 7 deletions Neos.Neos/Classes/Domain/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,8 @@ public function currentUserCanPublishToWorkspace(Workspace $workspace): bool
return true;
}

return false;
return $currentUser && $workspace->isPrivateWorkspace()
&& $this->isWorkspaceSharedWithUser($workspace, $currentUser);
}

/**
Expand All @@ -715,8 +716,15 @@ public function currentUserCanReadWorkspace(Workspace $workspace): bool

$currentUser = $this->getCurrentUser();

return $currentUser && $workspace->workspaceOwner
=== $this->persistenceManager->getIdentifierByObject($currentUser);
if (!$currentUser) {
return false;
}

if ($workspace->workspaceOwner === $this->persistenceManager->getIdentifierByObject($currentUser)) {
return true;
}

return $workspace->isPrivateWorkspace() && $this->isWorkspaceSharedWithUser($workspace, $currentUser);
}

/**
Expand Down Expand Up @@ -963,13 +971,26 @@ protected function findUserForAccount($username, $authenticationProviderName)
return $user;
}

/**
* @param Account $account
* @return User|null
*/
private function getNeosUserForAccount(Account $account): ?User
{
$user = $this->partyService->getAssignedPartyOfAccount($account);
return ($user instanceof User) ? $user : null;
}

/**
* Checks whether the given workspace is shared with the given user.
*/
protected function isWorkspaceSharedWithUser(Workspace $workspace, User $user): bool
{
// TODO: Reimplement
return false;

// $workspaceDetails = $this->workspaceDetailsRepository->findOneByWorkspace($workspace);
// if (!$workspaceDetails) {
// return false;
// }
// $allowedUsers = array_map(fn($user) => $this->persistenceManager->getIdentifierByObject($user),
// $workspaceDetails->getAcl());
// return in_array($this->persistenceManager->getIdentifierByObject($user), $allowedUsers, true);
}
}
48 changes: 0 additions & 48 deletions Neos.Neos/Configuration/Policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ privilegeTargets:
label: Allowed to publish to the live workspace
matcher: 'method(Neos\ContentRepository\Domain\Model\Workspace->(publish|publishNode|publishNodes)(targetWorkspace.name === "live"))'

'Neos.Neos:Backend.PublishAllToLiveWorkspace':
label: Allowed to publish to the live workspace
matcher: 'method(Neos\Neos\Controller\Module\Management\WorkspacesController->publishWorkspaceAction(workspace.baseWorkspace.name === "live"))'

'Neos.Neos:Backend.PublishOwnWorkspaceContent':
label: Allowed to publish own personal workspace
matcher: 'method(Neos\Neos\Service\Controller\WorkspaceController->(publishNode|publishNodes|error)Action()) || method(Neos\Neos\Service\Controller\WorkspaceController->publishAllAction(workspaceName = current.userInformation.personalWorkspaceName)) || method(Neos\Neos\Service\Controller\WorkspaceController->getWorkspaceWideUnpublishedNodesAction(workspace.name = current.userInformation.personalWorkspaceName))'
Expand All @@ -76,22 +72,6 @@ privilegeTargets:
# Workspace management
#

'Neos.Neos:Backend.CreateWorkspaces':
label: Allowed to create a workspace
matcher: 'method(Neos\Neos\Controller\Service\WorkspacesController->(new|create)Action()) || method(Neos\Neos\Controller\Module\Management\WorkspacesController->(create|new)Action())'

'Neos.Neos:Backend.Module.Management.Workspaces.ManageOwnWorkspaces':
label: Allowed to manage own workspaces
matcher: 'method(Neos\Neos\Controller\Module\Management\WorkspacesController->(publishWorkspace|discardWorkspace|edit|update|delete)Action(workspace.owner === current.userInformation.backendUser))'

'Neos.Neos:Backend.Module.Management.Workspaces.ManageInternalWorkspaces':
label: Manage internal workspaces
matcher: 'method(Neos\Neos\Controller\Module\Management\WorkspacesController->(publishWorkspace|discardWorkspace|edit|update|delete)Action(workspace.owner === null))'

'Neos.Neos:Backend.Module.Management.Workspaces.ManageAllPrivateWorkspaces':
label: Manage all private workspaces
matcher: 'method(Neos\Neos\Controller\Module\Management\WorkspacesController->(publishWorkspace|discardWorkspace|edit|update|delete)Action()) && evaluate(this.workspace.owner !== current.userInformation.backendUser, this.workspace.personalWorkspace === false)'

'Neos.Neos:Backend.Service.Workspaces.Index':
label: Access workspace services
matcher: 'method(Neos\Neos\Controller\Service\WorkspacesController->(index|error|show)Action())'
Expand Down Expand Up @@ -150,10 +130,6 @@ privilegeTargets:
label: General access to the management module section
matcher: 'management'

'Neos.Neos:Backend.Module.Management.Workspaces':
label: General access to the workspace module
matcher: 'management/workspaces'

'Neos.Neos:Backend.Module.Administration':
label: General access to the administration module
matcher: 'administration'
Expand Down Expand Up @@ -205,10 +181,6 @@ roles:
privilegeTarget: 'Neos.Neos:Backend.PublishToLiveWorkspace'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.PublishAllToLiveWorkspace'
permission: GRANT

'Neos.Neos:AbstractEditor':
abstract: true
parentRoles: ['Neos.ContentRepository:Administrator']
Expand Down Expand Up @@ -245,14 +217,6 @@ roles:
privilegeTarget: 'Neos.Neos:Backend.Service.Workspaces.ManageOwnWorkspaces'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.Module.Management.Workspaces.ManageOwnWorkspaces'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.CreateWorkspaces'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.ContentDimensions'
permission: GRANT
Expand Down Expand Up @@ -285,10 +249,6 @@ roles:
privilegeTarget: 'Neos.Neos:Backend.Module.Management'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.Module.Management.Workspaces'
permission: GRANT


'Neos.Neos:RestrictedEditor':
label: Restricted Editor
Expand Down Expand Up @@ -332,14 +292,6 @@ roles:
privilegeTarget: 'Neos.Neos:Backend.Module.Administration.Packages'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.Module.Management.Workspaces.ManageInternalWorkspaces'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.Module.Management.Workspaces.ManageAllPrivateWorkspaces'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.Module.Administration.Sites'
permission: GRANT
Expand Down
45 changes: 0 additions & 45 deletions Neos.Neos/Configuration/Routes.Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,51 +103,6 @@
appendExceedingArguments: true
httpMethods: ['HEAD', 'GET']

# RESTful WorkspacesController routes

-
name: 'Services - WorkspacesController->indexAction()'
uriPattern: 'workspaces'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Service\Workspaces'
'@action': 'index'
appendExceedingArguments: true
httpMethods: ['GET']

-
name: 'Services - WorkspacesController->showAction()'
uriPattern: 'workspaces/{workspace}'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Service\Workspaces'
'@action': 'show'
httpMethods: ['GET']

-
name: 'Services - WorkspacesController->createAction()'
uriPattern: 'workspaces/{baseWorkspace}/{workspaceName}'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Service\Workspaces'
'@action': 'create'
'@format': 'json'
httpMethods: ['POST']

# Note: we need to specify the workspace as {workspace.__identity} in the uriPattern because if we just used
# {workspace}, the properties could not be overridden through the parameters in the PUT request's body.
# This is a shortcoming of the DispatchComponent and should be solved in a future version of Flow.
-
name: 'Services - WorkspacesController->updateAction()'
uriPattern: 'workspaces/{workspace.__identity}'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Service\Workspaces'
'@action': 'update'
'@format': 'json'
appendExceedingArguments: true
httpMethods: ['PUT']

# DataSourceController routes
-
name: 'Services - DataSourceController->index'
Expand Down
7 changes: 0 additions & 7 deletions Neos.Neos/Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,6 @@ Neos:
description: 'Neos.Neos:Modules:management.description'
icon: fas fa-briefcase
mainStylesheet: 'Lite'
submodules:
workspaces:
label: 'Neos.Neos:Modules:workspaces.label'
controller: 'Neos\Neos\Controller\Module\Management\WorkspacesController'
description: 'Neos.Neos:Modules:workspaces.description'
icon: fas fa-th-large
mainStylesheet: 'Lite'
administration:
label: 'Neos.Neos:Modules:administration.label'
controller: 'Neos\Neos\Controller\Module\AdministrationController'
Expand Down

This file was deleted.

Loading
Loading