Neos\Neos\Domain\Service\UserService::currentUserCanManageWorkspace PHP Method

currentUserCanManageWorkspace() public method

In future versions, this logic may be implemented in Neos in a more generic way (for example, by means of an ACL object), but for now, this method exists in order to at least centralize and encapsulate the required logic.
public currentUserCanManageWorkspace ( Workspace $workspace ) : boolean
$workspace Neos\ContentRepository\Domain\Model\Workspace The workspace
return boolean
    public function currentUserCanManageWorkspace(Workspace $workspace)
    {
        if ($workspace->isPersonalWorkspace()) {
            return false;
        }
        if ($workspace->isInternalWorkspace()) {
            return $this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.Module.Management.Workspaces.ManageInternalWorkspaces');
        }
        if ($workspace->isPrivateWorkspace() && $workspace->getOwner() === $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');
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * Creates an array of workspace names and their respective titles which are possible base workspaces for other
  * workspaces.
  *
  * @param Workspace $excludedWorkspace If set, this workspace will be excluded from the list of returned workspaces
  * @return array
  */
 protected function prepareBaseWorkspaceOptions(Workspace $excludedWorkspace = null)
 {
     $baseWorkspaceOptions = [];
     foreach ($this->workspaceRepository->findAll() as $workspace) {
         /** @var Workspace $workspace */
         if (!$workspace->isPersonalWorkspace() && $workspace !== $excludedWorkspace && ($workspace->isPublicWorkspace() || $workspace->isInternalWorkspace() || $this->userService->currentUserCanManageWorkspace($workspace))) {
             $baseWorkspaceOptions[$workspace->getName()] = $workspace->getTitle();
         }
     }
     return $baseWorkspaceOptions;
 }