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 currentUserCanPublishToWorkspace ( |
||
$workspace | The workspace | |
return | boolean |
/** * Shows a list of existing workspaces * * @return string */ public function indexAction() { $user = $this->userService->getCurrentUser(); $workspacesArray = []; /** @var Workspace $workspace */ foreach ($this->workspaceRepository->findAll() as $workspace) { // FIXME: This check should be implemented through a specialized Workspace Privilege or something similar if ($workspace->getOwner() !== null && $workspace->getOwner() !== $user) { continue; } $workspaceArray = ['name' => $workspace->getName(), 'title' => $workspace->getTitle(), 'description' => $workspace->getDescription(), 'baseWorkspace' => $workspace->getBaseWorkspace()]; if ($user !== null) { $workspaceArray['readonly'] = !$this->userService->currentUserCanPublishToWorkspace($workspace); } $workspacesArray[] = $workspaceArray; } $this->view->assign('workspaces', $workspacesArray); }
/** * @param Workspace $workspace * @return void */ public function showAction(Workspace $workspace) { $this->view->assignMultiple(['selectedWorkspace' => $workspace, 'selectedWorkspaceLabel' => $workspace->getTitle() ?: $workspace->getName(), 'baseWorkspaceName' => $workspace->getBaseWorkspace()->getName(), 'baseWorkspaceLabel' => $workspace->getBaseWorkspace()->getTitle() ?: $workspace->getBaseWorkspace()->getName(), 'canPublishToBaseWorkspace' => $this->userService->currentUserCanPublishToWorkspace($workspace->getBaseWorkspace()), 'siteChanges' => $this->computeSiteChanges($workspace), 'contentDimensions' => $this->contentDimensionPresetSource->getAllPresets()]); }