From d9f4851b5259dcf8113f4f2e526da850a0e2a768 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 7 Dec 2024 16:52:53 +0100 Subject: [PATCH 1/2] BUGFIX: Prevent copy nodes across dimensions see https://github.com/neos/neos-development-collection/issues/5054#issuecomment-2523060805 Previously the `$targetDimensionSpacePoint` was also wrongly chosen, and it was attempted to paste the node into the subjects home dimension --- Classes/Domain/Model/Changes/CopyAfter.php | 8 +++++--- Classes/Domain/Model/Changes/CopyBefore.php | 5 ++++- Classes/Domain/Model/Changes/CopyInto.php | 5 ++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Classes/Domain/Model/Changes/CopyAfter.php b/Classes/Domain/Model/Changes/CopyAfter.php index cffc77b23e..c3e8307719 100644 --- a/Classes/Domain/Model/Changes/CopyAfter.php +++ b/Classes/Domain/Model/Changes/CopyAfter.php @@ -64,15 +64,17 @@ public function apply(): void try { $succeedingSibling = $this->findChildNodes($parentNodeOfPreviousSibling)->next($previousSibling); } catch (\InvalidArgumentException $e) { - // do nothing; $succeedingSibling is null. + // do nothing; $succeedingSibling is null. Todo add Nodes::contain() + } + if (!$subject->dimensionSpacePoint->equals($parentNodeOfPreviousSibling->dimensionSpacePoint)) { + throw new \RuntimeException('Copying across dimensions is not supported yet (https://github.com/neos/neos-development-collection/issues/5054)', 1733586265); } - $this->nodeDuplicationService->copyNodesRecursively( $subject->contentRepositoryId, $subject->workspaceName, $subject->dimensionSpacePoint, $subject->aggregateId, - OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), + OriginDimensionSpacePoint::fromDimensionSpacePoint($parentNodeOfPreviousSibling->dimensionSpacePoint), $parentNodeOfPreviousSibling->aggregateId, $succeedingSibling?->aggregateId, NodeAggregateIdMapping::createEmpty() diff --git a/Classes/Domain/Model/Changes/CopyBefore.php b/Classes/Domain/Model/Changes/CopyBefore.php index 7dd5191e7a..764a03a3cc 100644 --- a/Classes/Domain/Model/Changes/CopyBefore.php +++ b/Classes/Domain/Model/Changes/CopyBefore.php @@ -62,12 +62,15 @@ public function apply(): void if ($this->canApply() && !is_null($succeedingSibling) && !is_null($parentNodeOfSucceedingSibling) ) { + if (!$subject->dimensionSpacePoint->equals($succeedingSibling->dimensionSpacePoint)) { + throw new \RuntimeException('Copying across dimensions is not supported yet (https://github.com/neos/neos-development-collection/issues/5054)', 1733586265); + } $this->nodeDuplicationService->copyNodesRecursively( $subject->contentRepositoryId, $subject->workspaceName, $subject->dimensionSpacePoint, $subject->aggregateId, - OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), + OriginDimensionSpacePoint::fromDimensionSpacePoint($succeedingSibling->dimensionSpacePoint), $parentNodeOfSucceedingSibling->aggregateId, $succeedingSibling->aggregateId, NodeAggregateIdMapping::createEmpty() diff --git a/Classes/Domain/Model/Changes/CopyInto.php b/Classes/Domain/Model/Changes/CopyInto.php index 1a1eda3f10..6e5c0eb2a9 100644 --- a/Classes/Domain/Model/Changes/CopyInto.php +++ b/Classes/Domain/Model/Changes/CopyInto.php @@ -72,12 +72,15 @@ public function apply(): void $subject = $this->getSubject(); $parentNode = $this->getParentNode(); if ($parentNode && $this->canApply()) { + if (!$subject->dimensionSpacePoint->equals($parentNode->dimensionSpacePoint)) { + throw new \RuntimeException('Copying across dimensions is not supported yet (https://github.com/neos/neos-development-collection/issues/5054)', 1733586265); + } $this->nodeDuplicationService->copyNodesRecursively( $subject->contentRepositoryId, $subject->workspaceName, $subject->dimensionSpacePoint, $subject->aggregateId, - OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), + OriginDimensionSpacePoint::fromDimensionSpacePoint($parentNode->dimensionSpacePoint), $parentNode->aggregateId, null, NodeAggregateIdMapping::createEmpty() From 27e53b804b595c207b24a68f757fa3584628bd50 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 7 Dec 2024 16:53:44 +0100 Subject: [PATCH 2/2] BUGFIX: Hide paste button in the Neos Ui if its across dimensions --- .../neos-ui-redux-store/src/CR/Nodes/selectors.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/neos-ui-redux-store/src/CR/Nodes/selectors.ts b/packages/neos-ui-redux-store/src/CR/Nodes/selectors.ts index 7232166eeb..007b7a27c6 100644 --- a/packages/neos-ui-redux-store/src/CR/Nodes/selectors.ts +++ b/packages/neos-ui-redux-store/src/CR/Nodes/selectors.ts @@ -455,12 +455,25 @@ export const makeCanBeMovedAlongsideSelector = (nodeTypesRegistry: NodeTypesRegi (canBeInsertedInto, referenceIsDescendantOfSubject) => canBeInsertedInto && !referenceIsDescendantOfSubject ); +const makeNodeIsOfCurrentDimension = (_: GlobalState, {subject, reference}: {subject: NodeContextPath | null, reference: NodeContextPath | null}) => { + if (subject === null || reference === null) { + return false; + } + + // todo centralise client side NodeAddress logic + const subjectDimension = JSON.parse(subject).dimensionSpacePoint; + const referenceDimension = JSON.parse(reference).dimensionSpacePoint; + + return JSON.stringify(subjectDimension) === JSON.stringify(referenceDimension); +}; + export const makeCanBeCopiedSelector = (nodeTypesRegistry: NodeTypesRegistry) => createSelector( [ + makeNodeIsOfCurrentDimension, makeCanBeCopiedAlongsideSelector(nodeTypesRegistry), makeCanBeCopiedIntoSelector(nodeTypesRegistry) ], - (canBeInsertedAlongside, canBeInsertedInto) => (canBeInsertedAlongside || canBeInsertedInto) + (nodeIsOfCurrentDimension, canBeInsertedAlongside, canBeInsertedInto) => nodeIsOfCurrentDimension && (canBeInsertedAlongside || canBeInsertedInto) ); export const makeCanBeMovedSelector = (nodeTypesRegistry: NodeTypesRegistry) => createSelector(