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

FEATURE: Hide read only workspaces #3011

Open
wants to merge 5 commits into
base: 8.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 47 additions & 1 deletion Classes/ContentRepository/Service/WorkspaceService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Neos\Neos\Ui\ContentRepository\Service;

/*
Expand Down Expand Up @@ -53,6 +54,18 @@ class WorkspaceService
*/
protected $domainUserService;

/**
* @Flow\InjectConfiguration(path="initialState.user.settings.hideReadOnlyWorkspaces", package="Neos.Neos.Ui")
* @var boolean
*/
protected $hideReadOnlyWorkspaces;

/**
* @Flow\InjectConfiguration(path="initialState.user.settings.targetWorkspace", package="Neos.Neos.Ui")
* @var boolean
*/
protected $initialUserTargetWorkspace;

/**
* Get all publishable node context paths for a workspace
*
Expand Down Expand Up @@ -104,11 +117,17 @@ public function getAllowedTargetWorkspaces()
continue;
}

$readOnly = !$this->domainUserService->currentUserCanPublishToWorkspace($workspace);
if ($readOnly === true && $this->hideReadOnlyWorkspaces) {
// Skip read only workspaces
continue;
}

$workspaceArray = [
'name' => $workspace->getName(),
'title' => $workspace->getTitle(),
'description' => $workspace->getDescription(),
'readonly' => !$this->domainUserService->currentUserCanPublishToWorkspace($workspace)
'readonly' => $readOnly
];
$workspacesArray[$workspace->getName()] = $workspaceArray;
}
Expand All @@ -127,4 +146,31 @@ public function setBaseWorkspace(Workspace $workspace)
$userWorkspace = $this->userService->getPersonalWorkspace();
$userWorkspace->setBaseWorkspace($workspace);
}

/**
* Returns a workspace object if workspace with the given name exists.
*
* @param string $workspaceName
* @return Workspace|null
*/
public function getWorkspaceByName($workspaceName): ?Workspace
{
return $this->workspaceRepository->findOneByName($workspaceName);
}

/**
* @return bool
*/
public function shouldHideReadOnlyWorkspaces(): bool
{
return $this->hideReadOnlyWorkspaces;
}

/**
* @return string
*/
public function getInitialUserTargetWorkspace(): string
{
return $this->initialUserTargetWorkspace;
}
}
36 changes: 35 additions & 1 deletion Classes/Fusion/Helper/WorkspaceHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Neos\Neos\Ui\Fusion\Helper;

/*
Expand Down Expand Up @@ -51,15 +52,48 @@ public function getPersonalWorkspace()
{
$personalWorkspace = $this->userService->getPersonalWorkspace();
$baseWorkspace = $personalWorkspace->getBaseWorkspace();
$readOnly = !$this->domainUserService->currentUserCanPublishToWorkspace($baseWorkspace);

if ($readOnly === true && $this->workspaceService->shouldHideReadOnlyWorkspaces()) {
// Skip read only workspaces
$baseWorkspace = $this->getFirstWriteableTargetWorkspace();
$this->workspaceService->setBaseWorkspace($baseWorkspace);
$readOnly = !$this->domainUserService->currentUserCanPublishToWorkspace($baseWorkspace);
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
}

return [
'name' => $personalWorkspace->getName(),
'publishableNodes' => $this->getPublishableNodeInfo($personalWorkspace),
'baseWorkspace' => $baseWorkspace->getName(),
'readOnly' => !$this->domainUserService->currentUserCanPublishToWorkspace($baseWorkspace)
'readOnly' => $readOnly
];
}

/**
* Returns the first writable workspace for the current user. If we find no writeable workspace
* we use the configured targetWorkspace as fallback. This is mostly live.
*
* @return Workspace|null
*/
public function getFirstWriteableTargetWorkspace(): ?Workspace
{
$allowedTargetWorkspaces = $this->getAllowedTargetWorkspaces();
foreach ($allowedTargetWorkspaces as $allowedTargetWorkspace) {
$readOnly = $allowedTargetWorkspace['readonly'];
if ($readOnly === true) {
continue;
}

$writeableTargetWorkspace = $this->workspaceService->getWorkspaceByName($allowedTargetWorkspace['name']);
if ($writeableTargetWorkspace) {
return $writeableTargetWorkspace;
}
}

// Live as fallback
return $this->workspaceService->getWorkspaceByName($this->workspaceService->getInitialUserTargetWorkspace());
}

public function getAllowedTargetWorkspaces()
{
return $this->workspaceService->getAllowedTargetWorkspaces();
Expand Down
1 change: 1 addition & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Neos:
settings:
isAutoPublishingEnabled: false
targetWorkspace: 'live'
hideReadOnlyWorkspaces: false
changes:
types:
'Neos.Neos.Ui:Property': Neos\Neos\Ui\Domain\Model\Changes\Property
Expand Down