Skip to content

Commit

Permalink
Merge branch 'decendant-of-nodetype' of github.com:vcg-development/ne…
Browse files Browse the repository at this point in the history
…os-development-collection into decendant-of-nodetype
  • Loading branch information
oherrmannVogel committed Dec 11, 2024
2 parents 5934323 + c8c80a4 commit 4c0e2fb
Show file tree
Hide file tree
Showing 138 changed files with 12,503 additions and 24,254 deletions.
2 changes: 1 addition & 1 deletion .composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": ["GPL-3.0-or-later"],
"type": "neos-package-collection",
"require": {
"neos/flow-development-collection": "8.3.x-dev"
"neos/flow-development-collection": "8.4.x-dev"
},
"scripts": {
"lint:phpstan": "../../bin/phpstan analyse",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['8.0', '8.1', '8.2', '8.3']
php-versions: ['8.2', '8.3']
dependencies: ['highest']
composer-arguments: [''] # to run --ignore-platform-reqs in experimental builds
static-analysis: ['no']
experimental: [false]
include:
- php-versions: '8.1'
- php-versions: '8.2'
static-analysis: 'yes'
experimental: false
dependencies: 'highest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ public function initializeObject()
/**
* Render a node label based on an eel expression or return the expression if it is not valid eel.
*
* @param \Neos\ContentRepository\Domain\Projection\Content\NodeInterface $node
* @return string
* @throws \Neos\Eel\Exception
*/
public function getLabel(\Neos\ContentRepository\Domain\Projection\Content\NodeInterface $node): string
{
if (Utility::parseEelExpression($this->getExpression()) === null) {
return $this->getExpression();
$expression = $this->getExpression();
if ($node->isAutoCreated()) {
$parentNode = $node->getParent();
$property = 'childNodes.' . $node->getName() . '.label';
if ($parentNode?->getNodeType()->hasConfiguration($property)) {
$expression = $parentNode->getNodeType()->getConfiguration($property);
}
}
if (Utility::parseEelExpression($expression) === null) {
return $expression;
}
return (string)Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, ['node' => $node], $this->defaultContextConfiguration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Persistence\Aspect\PersistenceMagicInterface;
Expand Down Expand Up @@ -119,19 +120,19 @@ class NodeImportService
'dimensionValues' => [],
'properties' => [],
'hiddenBeforeDateTime' => [
'columnType' => Type::DATETIME
'columnType' => Types::DATE_IMMUTABLE
],
'hiddenAfterDateTime' => [
'columnType' => Type::DATETIME
'columnType' => Types::DATE_IMMUTABLE
],
'creationDateTime' => [
'columnType' => Type::DATETIME
'columnType' => Types::DATE_IMMUTABLE
],
'lastModificationDateTime' => [
'columnType' => Type::DATETIME
'columnType' => Types::DATE_IMMUTABLE
],
'lastPublicationDateTime' => [
'columnType' => Type::DATETIME
'columnType' => Types::DATE_IMMUTABLE
],
'accessRoles' => []
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public function isDescendantNodeOf($nodePathOrIdentifier)
}

/**
* Matches nodes underneath the given NodeType(s)
*
* @param array $nodeTypes
* @return PropertyConditionGenerator
*/
public function isDescendantOfNodetype($nodeTypes)
public function isDescendantOfType($nodeTypes)
{
$propertyConditionGenerator1 = new DecendantOfNodetypeConditionGenerator($nodeTypes);

return $propertyConditionGenerator1;
return new DescendantOfTypeConditionGenerator($nodeTypes);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace Neos\ContentRepository\Security\Authorization\Privilege\Node\Doctrine;

/*
* This file is part of the Neos.ContentRepository package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Filter\SQLFilter as DoctrineSqlFilter;

/**
* A SQL generator to create a condition matching a node underneath a certain node type
*/
class DescendantOfTypeConditionGenerator implements SqlGeneratorInterface
{
private array $nodetypes;

/**
* @param array $nodetypes
*/
public function __construct(array $nodetypes)
{
$this->nodetypes = $nodetypes;
}

/**
* Returns an SQL query part that matches all Nodes that are underneath one of the the given NodeType(s)
*
* @param DoctrineSqlFilter $sqlFilter
* @param ClassMetadata $targetEntity
* @param string $targetTableAlias
* @return string
*/
public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity, $targetTableAlias)
{
$nodetypeList = implode("','", $this->nodetypes);

return "select * from public.neos_contentrepository_domain_model_nodedata n1
JOIN public.neos_contentrepository_domain_model_nodedata n2 ON n1.path LIKE CONCAT(n2.path, '%')
WHERE n2.nodetype in ('" . $nodetypeList . "')";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function isDescendantNodeOf($nodePathOrIdentifier)
* @param string|array $nodeTypes A single or an array of fully qualified NodeType name(s), e.g. "Neos.Neos:Document"
* @return boolean true if the given node matches otherwise false
*/
public function isDescendantOfNodetype($nodeTypes)
public function isDescendantOfType($nodeTypes)
{
if ($this->node === null) {
return true;
Expand Down
10 changes: 10 additions & 0 deletions Neos.ContentRepository/Configuration/Testing/NodeTypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,13 @@

'Neos.ContentRepository.Testing:NodeTypeWithEelExpressionLabel':
label: '${"Test" + " " + "nodetype"}'

'Neos.ContentRepository.Testing:NodeTypeWithPlainLabelInChildNode':
childNodes:
child:
label: 'Test child node'

'Neos.ContentRepository.Testing:NodeTypeWithEelExpressionLabelInChildNode':
childNodes:
child:
label: '${"Test" + " child " + "node"}'
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ additionalProperties:

'label':
type: ['string', 'array']
description: "An EEL expression for generating a node's of this node type's label. Alternatively an array with the key generatorClass and optional options."
description: "An EEL expression for generating a node's of this node type's label. Alternatively an array with the key generatorClass and optional generator options."

'constraints': &constraints
type: dictionary
Expand All @@ -42,6 +42,7 @@ additionalProperties:
type: dictionary
additionalProperties: false
properties:
'label': { type: string, description: "A string or an EEL expression for generating a node's of this node type's label. Alternatively an array with the key generatorClass and optional generator options." }
'type': { type: string, description: "Node Type of this child node." }
'position':
type: ['string', 'null']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Feature: Privilege to restrict editing of nodes
'Neos.ContentRepository:EditEventNodes':
matcher: 'isDescendantNodeOf("11d3aded-fb1a-70e7-1412-0b465b11fcd8")'
'Neos.ContentRepository:EditCollectionType':
matcher: 'isDescendantOfType("Neos.ContentRepository.Testing:ContentCollection")'
roles:
'Neos.Flow:Everybody':
privileges: []
Expand All @@ -31,6 +34,9 @@ Feature: Privilege to restrict editing of nodes
-
privilegeTarget: 'Neos.ContentRepository:EditEventNodes'
permission: GRANT
-
privilegeTarget: 'Neos.ContentRepository:EditCollectionType'
permission: GRANT
"""

And I have the following nodes:
Expand All @@ -40,6 +46,26 @@ Feature: Privilege to restrict editing of nodes
| 68ca0dcd-2afb-ef0e-1106-a5301e65b8a0 | /sites/content-repository/company | Neos.ContentRepository.Testing:Document | {"title": "Company"} | live |
| 52540602-b417-11e3-9358-14109fd7a2dd | /sites/content-repository/service | Neos.ContentRepository.Testing:Document | {"title": "Service"} | live |
| 11d3aded-fb1a-70e7-1412-0b465b11fcd8 | /sites/content-repository/events | Neos.ContentRepository.Testing:Document | {"title": "Events", "description": "Some cool event"} | live |
| d09c4e76-79c6-45d9-a12a-c1a06450329c | /sites/content-repository/service/collection | Neos.ContentRepository.Testing:ContentCollection | {} | live |
| 4f7230ba-36b2-4dc3-96fa-b4159371cd3b | /sites/content-repository/service/collection/text | Neos.ContentRepository.Testing:Text | {"text": "Cool text"} | live |

@Isolated @fixtures
Scenario: Anonymous users are not granted to edit childnodes on ContentCollection nodetypes
Given I am not authenticated
And I get a node by path "/sites/content-repository/service/collection/text" with the following context:
| Workspace |
| user-admin |
Then I should not be granted to set the "text" property to "Even cooler text"
And I should get false when asking the node authorization service if editing this node is granted

@Isolated @fixtures
Scenario: Administrators are granted to edit childnodes on ContentCollection nodetypes
Given I am authenticated with role "Neos.ContentRepository:Administrator"
And I get a node by path "/sites/content-repository/service/collection/text" with the following context:
| Workspace |
| user-admin |
Then I should be granted to set the "text" property to "Even cooler text"
And I should get true when asking the node authorization service if editing this node is granted

@Isolated @fixtures
Scenario: Anonymous users are granted to set properties on company node
Expand Down
17 changes: 17 additions & 0 deletions Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,23 @@ public function getLabelReturnsParsedEelExpressionOrFallback()
self::assertEquals('Test nodetype', $nodeWithEelExpressionLabel->getLabel());
}

/**
* @test
*/
public function getChildNodeLabelReturnsParsedEelExpressionOrFallback()
{
$nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
$nodeTypeWithPlainLabelInChildNode = $nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithPlainLabelInChildNode');
$nodeTypeWithEelExpressionLabelInChildNode = $nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithEelExpressionLabelInChildNode');

$rootNode = $this->context->getNode('/');
$nodeWithPlainLabelInChildNode = $rootNode->createNode('node-plain', $nodeTypeWithPlainLabelInChildNode, '30e893c1-caef-0ca5-b53d-e5699bb8e506');
$nodeWithEelExpressionLabelInChildNode = $rootNode->createNode('node-eel', $nodeTypeWithEelExpressionLabelInChildNode, '81c848ed-abb5-7608-a5db-7eea0331ccfa');

self::assertEquals('Test child node', $nodeWithPlainLabelInChildNode->getLabel());
self::assertEquals('Test child node', $nodeWithEelExpressionLabelInChildNode->getLabel());
}

/**
* @test
*/
Expand Down
Loading

0 comments on commit 4c0e2fb

Please sign in to comment.