Skip to content

Commit

Permalink
Merge pull request #3892 from mhsdesign/bugfix/prevent-copy-across-di…
Browse files Browse the repository at this point in the history
…mensions

BUGFIX: Prevent copy nodes across dimensions
  • Loading branch information
kitsunet authored Dec 13, 2024
2 parents 228b4e0 + 27e53b8 commit f1b2b8a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Classes/Domain/Model/Changes/CopyAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion Classes/Domain/Model/Changes/CopyBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion Classes/Domain/Model/Changes/CopyInto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion packages/neos-ui-redux-store/src/CR/Nodes/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f1b2b8a

Please sign in to comment.