Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Prevent copy nodes across dimensions #3892

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading