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: Handle nodes with missing UriPathSegments in uriPathProjection #5412

Open
wants to merge 4 commits into
base: 9.0
Choose a base branch
from

Conversation

mficzel
Copy link
Member

@mficzel mficzel commented Dec 22, 2024

Use nodeAggregateId as fallback for missing uriPathSegments in uriPathProjection.

This is necessary as the fallback to "" can create empty pathes for documents without uriPathSegment which is later on confused with root urls of the site. Falling back to the nodeAggregate id which is by definition unique and url-safe ensures that all documents get a valid url by the projection that can be adjusted later.

Empty uriPathSegments are usually avoided by validation and autocreation from the title but those mechanisms do not work for tethered nodes. This is even more problematic as this cannot be fixed later since the full uriPath is only created oCreate and laster on only the last segment of the path is adjusted without ever reevaluating the parentPath.

In addition this pr adds a nodeName to the site node in multiple test cases as this is actually required and only worked in the past because the empty uriPathSegment behaved like a site node.

Resolves: #5413

Upgrade instructions

Review instructions

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

mficzel added a commit to mficzel/neos-development-collection that referenced this pull request Dec 22, 2024
Since "" is treated as the uriPath for a site node this causes confusion if it is projected for a document in cases where one was created without an uriPathSegment which may happen for tethered nodes.

Resolves: neos#5412
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch from 43fdcb5 to 107b282 Compare December 22, 2024 11:43
…gments

The testcase verifies that the nodeAggregateId is used as fallback in case no uriPathSegment
was set and that this can be overwritten afterwards of a proper uriPathSegment is set later.

Relates: neos#5413
mficzel added a commit to mficzel/neos-development-collection that referenced this pull request Dec 22, 2024
Since "" is treated as the uriPath for a site node this causes confusion if it is projected for a document in cases where one was created without an uriPathSegment which may happen for tethered nodes.

Resolves: neos#5412
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch from 107b282 to dd3ff9d Compare December 22, 2024 11:56
@mficzel mficzel changed the title BUGFIX: Handle nodes with missing UriPathSrents in uri projection BUGFIX: Handle nodes with missing UriPathSegments in uri PathProjection Dec 22, 2024
@mficzel mficzel changed the title BUGFIX: Handle nodes with missing UriPathSegments in uri PathProjection BUGFIX: Handle nodes with missing UriPathSegments in uriPathProjection Dec 22, 2024
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch 5 times, most recently from a16aeb8 to d81eb9f Compare December 22, 2024 14:06
@mficzel
Copy link
Member Author

mficzel commented Dec 22, 2024

I wonder wether the site node detection that is currently done in handCreateNodeAggregateWith is wise because a
site node is basically defined as a named node that is directly below a rootNode.

@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch 2 times, most recently from 9abce68 to d9772d3 Compare December 22, 2024 15:09
@mficzel mficzel marked this pull request as ready for review December 22, 2024 15:19
Since "" is treated as the uriPath for a site node this causes confusion if it is projected for a document in cases where one was created without an uriPathSegment which may happen for tethered nodes.

Resolves: neos#5412
…vior

The projection detects site nodes that should have an empty path by verifying that the parent is a root node and they have a nodeName.
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch from d9772d3 to 64d52a7 Compare December 22, 2024 15:25
Copy link
Member

@bwaidelich bwaidelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand, why some seemingly unrelated tests needed adjustments, but the change itself makes sense to me, thanks!

@mficzel
Copy link
Member Author

mficzel commented Dec 22, 2024

The definition of site node (with path „“) used in the uriPathProjection is that it is a child of a rootNode and has a nodeName.

The adjusted tests only worked in the past because an empty uriPathSegment was treated implicitly like a site node. Since we now have fallback for empty uriPathSegments the tests that relied on that now need a proper site Node.

@mficzel mficzel requested a review from nezaniel December 22, 2024 16:19
@@ -209,7 +209,7 @@ private function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCre
}

$propertyValues = $event->initialPropertyValues->getPlainValues();
$uriPathSegment = $propertyValues['uriPathSegment'] ?? '';
$uriPathSegment = $propertyValues['uriPathSegment'] ?? $event->nodeAggregateId->value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we discussed an alternative in line 273 but it doesnt really work :D

                $uriPath = $this->nodeTypeManager->getNodeType($parentNode->getNodeTypeName())?->isOfType(NodeTypeNameFactory::NAME_SITE)
                    ? $uriPathSegment
                    : $parentNode->getUriPath() . '/' . $uriPathSegment;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still think resilience against missing uri path segments is better than adding an even tighter bond to the Neos NodeTypes. Even if this would work ;-)

The fallback way makes uriPathes more like a soft concern (which it is technically anyways) and allows routing of documents in cases where it is missing for any reason.

Only thing that would speak against that would be a case where the node-identifier based fallback does harm anything but i do not see a way for this to happen.

Copy link
Member

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would preferably not necessary to use the node identifier here as that would now lead to odd uris containing a uuid which is not humanreadable. But then again - hey - at least there is an uri now and it can be edited and changes are picked up. Alternatively i suggested using the NodeName which is definitely available as a first choice over the node aggregate id as this will be kindof readable but to be honest this is such an edgecase it might not be worth discussing over this tiny detail.

A total alternative direction would be to introduce some kind of special path segment in the projection which says "hey" im just a placeholder please dont route me. But we agreed its more important to have an actual uri first than to have no uri until the reaction fixes it.

This whole issue shows that the node creation dialog of the ui is actually missing an important feature: To allow to specify the initial properties of the tethered nodes ... and fun fact the Neos ESCR core api cannot do this at the current point - there is no "initial node properties for tethered node" option, which we might yet have to introduce.

Either way - even with the thought out creation dialog extension we cant ensure that the uriPathSegment is set always (well we could via command hooks - but do we want to? related: #4581).

So it definitely makes sense to build the projection a little more forgiving.


Note that there are some more inconsistencies we found like that an empty ("") uriPathSegment on creation does not yet replaced with the node aggregate id to avoid problems like this.

And also the projection does not consider the case when the property is manually set to empty ("") or unset via propertyValuesToUnset.

$uriPathSegments[array_key_last($uriPathSegments)] = $newPropertyValues['uriPathSegment'];

Technically we would need to adopt and enforce the same behaviour as started with this pr: use the node aggregate id as fallback. Currently we dont do so and run in odd states. Either way this cleanup will be out of scope of this current bugfix and might not even be that critical as the Neos Ui regularly prevents the uripath segment to be unset or empty.
We can always fix that later in the future and advice affected users to replay.

@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch from 9208c23 to 195af38 Compare January 14, 2025 15:50
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch 2 times, most recently from eca5d6b to ff41831 Compare January 14, 2025 16:09
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch from ff41831 to 215c884 Compare January 14, 2025 16:28
@mficzel
Copy link
Member Author

mficzel commented Jan 14, 2025

@mhsdesign adjusted the code to handle "" as uriPathSegments and also later setting of uriPathSegments to "" or null.

The general the rule for the uriPathSegment is now ($newPropertyValues['uriPathSegment'] ?? '') ?: $event->nodeAggregateId;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: UriPathProjection cannot recover from missing UriPathSegments in nested+tethered documentNodes
3 participants