Skip to content

Commit

Permalink
FEATURE: Hide switch for read only workspaces
Browse files Browse the repository at this point in the history
When you work with countless backend users and workspaces, it may happen that the restricted editors maybe are confused by all the available workspaces. And sometimes select a workspace that is read only. Then they can not edit content since the latest bug fixes and before that, they run into an error while publishing.

This feature should enable the developers and integrators to hide all none writable workspaces in the selection. That should improve the user experience for the editors. By default, the setting is false and therefore everything is like before that feature.

When you enable it with the setting 
initialState.user.settings.hideReadOnlyWorkspaces the user will see only writable workspaces in the publishing dropdown, except there are no writable workspaces. Then we use the default target workspace as fallback. This is often live.
  • Loading branch information
markusguenther committed Jan 5, 2022
1 parent 7ede460 commit 82fd3d2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
34 changes: 33 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,12 @@ class WorkspaceService
*/
protected $domainUserService;

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

/**
* Get all publishable node context paths for a workspace
*
Expand Down Expand Up @@ -104,11 +111,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 +140,23 @@ 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()
{
return $this->hideReadOnlyWorkspaces;
}
}
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);
}

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('live');
}

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 @@ -183,6 +183,7 @@ Neos:
settings:
isAutoPublishingEnabled: false
targetWorkspace: 'live'
hideReadOnlyWorkspaces: true
changes:
types:
'Neos.Neos.Ui:Property': Neos\Neos\Ui\Domain\Model\Changes\Property
Expand Down

0 comments on commit 82fd3d2

Please sign in to comment.