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 currentUserCanReadWorkspace ( |
||
$workspace | The workspace | |
return | boolean |
/** * Returns an array of usage reference objects. * * @param AssetInterface $asset * @return array<\Neos\Neos\Domain\Model\Dto\AssetUsageInNodeProperties> * @throws \Neos\ContentRepository\Exception\NodeConfigurationException */ public function getUsageReferences(AssetInterface $asset) { $assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset); if (isset($this->firstlevelCache[$assetIdentifier])) { return $this->firstlevelCache[$assetIdentifier]; } $userWorkspace = $this->userService->getPersonalWorkspace(); $relatedNodes = []; foreach ($this->getRelatedNodes($asset) as $relatedNodeData) { $accessible = $this->domainUserService->currentUserCanReadWorkspace($relatedNodeData->getWorkspace()); if ($accessible) { $context = $this->createContextMatchingNodeData($relatedNodeData); } else { $context = $this->createContentContext($userWorkspace->getName()); } $site = $context->getCurrentSite(); $node = $this->nodeFactory->createFromNodeData($relatedNodeData, $context); $flowQuery = new FlowQuery([$node]); /** @var \Neos\ContentRepository\Domain\Model\NodeInterface $documentNode */ $documentNode = $flowQuery->closest('[instanceof Neos.Neos:Document]')->get(0); $relatedNodes[] = new AssetUsageInNodeProperties($asset, $site, $documentNode, $node, $accessible); } $this->firstlevelCache[$assetIdentifier] = $relatedNodes; return $this->firstlevelCache[$assetIdentifier]; }