From 7987d414681fe843dc2d6aa0fb2bf4f5d2afd7da Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:55:58 +0200 Subject: [PATCH 1/3] TASK: Fix hidden state evaluation The Neos 8.3 LinkingService contained this logic ``` $action = $node->getContext()->getWorkspace()->isPublicWorkspace() && !$node->isHidden() ? 'show' : 'preview'; ``` ensuring that disabled nodes can still be previewed. In Neos 9 a no route matched error will be thrown. To restore the old behaviour we evaluate the hidden state --- Classes/Controller/BackendController.php | 26 ++++++++++++++++++++++-- Classes/Fusion/Helper/NodeInfoHelper.php | 11 +--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 60dfb5b8dc..dde36a1242 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -12,9 +12,11 @@ * source code. */ +use Neos\ContentRepository\Core\Feature\SubtreeTagging\Dto\SubtreeTag; use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Flow\Annotations as Flow; use Neos\Flow\Mvc\Controller\ActionController; @@ -226,9 +228,29 @@ public function redirectToAction(string $node): void $nodeAddress = NodeAddress::fromJsonString($node); + $contentRepository = $this->contentRepositoryRegistry->get($nodeAddress->contentRepositoryId); + + $nodeInstance = $contentRepository->getContentGraph($nodeAddress->workspaceName)->getSubgraph( + $nodeAddress->dimensionSpacePoint, + VisibilityConstraints::withoutRestrictions() + )->findNodeById($nodeAddress->aggregateId); + + // we always want to redirect to the node in the base workspace. + $workspace = $contentRepository->getWorkspaceFinder()->findOneByName($nodeAddress->workspaceName); + + $nodeAddressInBaseWorkspace = NodeAddress::create( + $nodeAddress->contentRepositoryId, + $workspace->baseWorkspaceName ?? WorkspaceName::forLive(), + $nodeAddress->dimensionSpacePoint, + $nodeAddress->aggregateId + ); + + $nodeUriBuilder = $this->nodeUriBuilderFactory->forActionRequest($this->request); + $this->redirectToUri( - $this->nodeUriBuilderFactory->forActionRequest($this->request) - ->uriFor($nodeAddress) + $nodeInstance->tags->contain(SubtreeTag::disabled()) + ? $nodeUriBuilder->previewUriFor($nodeAddressInBaseWorkspace) + : $nodeUriBuilder->uriFor($nodeAddressInBaseWorkspace) ); } } diff --git a/Classes/Fusion/Helper/NodeInfoHelper.php b/Classes/Fusion/Helper/NodeInfoHelper.php index 225a968604..44ac7f22ad 100644 --- a/Classes/Fusion/Helper/NodeInfoHelper.php +++ b/Classes/Fusion/Helper/NodeInfoHelper.php @@ -356,16 +356,7 @@ public function previewUri(Node $node, ActionRequest $actionRequest): string public function createRedirectToNode(Node $node, ActionRequest $actionRequest): string { - // we always want to redirect to the node in the base workspace. - $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); - $workspace = $contentRepository->getWorkspaceFinder()->findOneByName($node->workspaceName); - - $nodeAddress = NodeAddress::create( - $node->contentRepositoryId, - $workspace->baseWorkspaceName ?? WorkspaceName::forLive(), - $node->dimensionSpacePoint, - $node->aggregateId - ); + $nodeAddress = NodeAddress::fromNode($node); $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($actionRequest); From 708c7c6c54243ee522b9fe643678035ffcb5a3bb Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:06:35 +0200 Subject: [PATCH 2/3] TASK: Harden `redirectToAction` remove logic of falling back to live workspace, but use the original workspace then instead. --- Classes/Controller/BackendController.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 9b328f1a27..6109d44f47 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -16,7 +16,6 @@ use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; -use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Flow\Annotations as Flow; use Neos\Flow\Mvc\Controller\ActionController; @@ -234,12 +233,12 @@ public function redirectToAction(string $node): void VisibilityConstraints::withoutRestrictions() )->findNodeById($nodeAddress->aggregateId); - // we always want to redirect to the node in the base workspace. - $workspace = $contentRepository->getWorkspaceFinder()->findOneByName($nodeAddress->workspaceName); + $workspace = $contentRepository->findWorkspaceByName($nodeAddress->workspaceName); + // we always want to redirect to the node in the base workspace. $nodeAddressInBaseWorkspace = NodeAddress::create( $nodeAddress->contentRepositoryId, - $workspace->baseWorkspaceName ?? WorkspaceName::forLive(), + $workspace->baseWorkspaceName ?? $nodeAddress->workspaceName, $nodeAddress->dimensionSpacePoint, $nodeAddress->aggregateId ); @@ -247,7 +246,7 @@ public function redirectToAction(string $node): void $nodeUriBuilder = $this->nodeUriBuilderFactory->forActionRequest($this->request); $this->redirectToUri( - $nodeInstance->tags->contain(SubtreeTag::disabled()) + !$nodeInstance || $nodeInstance->tags->contain(SubtreeTag::disabled()) ? $nodeUriBuilder->previewUriFor($nodeAddressInBaseWorkspace) : $nodeUriBuilder->uriFor($nodeAddressInBaseWorkspace) ); From 830cf1c6211b355924b2f8e8fc494874759df1d8 Mon Sep 17 00:00:00 2001 From: Marc Henry Schultz <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:09:24 +0200 Subject: [PATCH 3/3] update comment Co-authored-by: Bastian Waidelich --- Classes/Controller/BackendController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 6109d44f47..c785ddc95b 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -235,7 +235,7 @@ public function redirectToAction(string $node): void $workspace = $contentRepository->findWorkspaceByName($nodeAddress->workspaceName); - // we always want to redirect to the node in the base workspace. + // we always want to redirect to the node in the base workspace unless we are on a root workspace in which case we stay on that (currently that will not happen) $nodeAddressInBaseWorkspace = NodeAddress::create( $nodeAddress->contentRepositoryId, $workspace->baseWorkspaceName ?? $nodeAddress->workspaceName,