Skip to content

Commit

Permalink
Merge pull request #4733 from mhsdesign/task/4396-preferRenderingMode…
Browse files Browse the repository at this point in the history
…IsEditChecksInsteadOfNodeIsLive

TASK: #4396 prefer renderingMode::isEdit over node::isLive
  • Loading branch information
mhsdesign authored Nov 17, 2023
2 parents 23089d7 + faa72c7 commit e304fc6
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 97 deletions.
4 changes: 2 additions & 2 deletions Neos.Neos/Classes/Domain/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public function deactivateUser(User $user): void
*/
public function currentUserCanPublishToWorkspace(Workspace $workspace): bool
{
if ($workspace->workspaceName->isLive()) {
if ($workspace->isPublicWorkspace()) {
return $this->securityContext->hasRole('Neos.Neos:LivePublisher');
}

Expand All @@ -709,7 +709,7 @@ public function currentUserCanPublishToWorkspace(Workspace $workspace): bool
*/
public function currentUserCanReadWorkspace(Workspace $workspace): bool
{
if ($workspace->workspaceName->isLive() || $workspace->workspaceOwner === null) {
if ($workspace->isPublicWorkspace()) {
return true;
}

Expand Down
13 changes: 10 additions & 3 deletions Neos.Neos/Classes/Fusion/ContentElementEditableImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Fusion\FusionObjects\AbstractFusionObject;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\Service\ContentElementEditableService;

/**
Expand Down Expand Up @@ -56,18 +57,24 @@ public function evaluate()
{
$content = $this->getValue();

$renderingMode = $this->runtime->fusionGlobals->get('renderingMode');
assert($renderingMode instanceof RenderingMode);
if (!$renderingMode->isEdit) {
return $content;
}

$node = $this->fusionValue('node');
if (!$node instanceof Node) {
return $content;
}

/** @var string $property */
$property = $this->fusionValue('property');

if (!$this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
return $content;
}

/** @var string $property */
$property = $this->fusionValue('property');

return $this->contentElementEditableService->wrapContentProperty($node, $property, $content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Fusion\FusionObjects\AbstractFusionObject;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\Service\ContentElementWrappingService;

/**
Expand Down Expand Up @@ -66,6 +67,12 @@ public function evaluate()
{
$content = $this->getValue();

$renderingMode = $this->runtime->fusionGlobals->get('renderingMode');
assert($renderingMode instanceof RenderingMode);
if (!$renderingMode->isEdit) {
return $content;
}

$node = $this->fusionValue('node');
if (!$node instanceof Node) {
return $content;
Expand Down
11 changes: 7 additions & 4 deletions Neos.Neos/Classes/Fusion/ConvertUrisImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Mvc\Exception\NoMatchingRouteException;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
Expand Down Expand Up @@ -123,16 +124,18 @@ public function evaluate()
), 1382624087);
}

$renderingMode = $this->runtime->fusionGlobals->get('renderingMode');
assert($renderingMode instanceof RenderingMode);
if ($renderingMode->isEdit && $this->fusionValue('forceConversion') !== true) {
return $text;
}

$contentRepository = $this->contentRepositoryRegistry->get(
$node->subgraphIdentity->contentRepositoryId
);

$nodeAddress = NodeAddressFactory::create($contentRepository)->createFromNode($node);

if (!$nodeAddress->isInLiveWorkspace() && !($this->fusionValue('forceConversion'))) {
return $text;
}

$unresolvedUris = [];
$absolute = $this->fusionValue('absolute');

Expand Down
24 changes: 13 additions & 11 deletions Neos.Neos/Classes/Fusion/ExceptionHandlers/NodeWrappingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Neos\Flow\Utility\Environment;
use Neos\Fusion\Core\ExceptionHandlers\AbstractRenderingExceptionHandler;
use Neos\Fusion\Core\ExceptionHandlers\ContextDependentHandler;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\Service\ContentElementWrappingService;

/**
Expand Down Expand Up @@ -72,19 +73,20 @@ protected function handle($fusionPath, \Exception $exception, $referenceCode): s
if (isset($currentContext['node'])) {
/** @var Node $node */
$node = $currentContext['node'];
$contentRepositoryId = $node->subgraphIdentity->contentRepositoryId;
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$workspace = $contentRepository->getWorkspaceFinder()->findOneByCurrentContentStreamId(
$node->subgraphIdentity->contentStreamId
);

$renderingMode = $this->runtime->fusionGlobals->get('renderingMode');
assert($renderingMode instanceof RenderingMode);
$applicationContext = $this->environment->getContext();

if (
$applicationContext->isProduction()
&& $this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')
&& !is_null($workspace)
&& !$workspace->workspaceName->isLive()
) {
if (!$renderingMode->isEdit) {
return $output;
}

if (!$this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
return $output;
}

if ($applicationContext->isProduction()) {
$output = '<div class="neos-rendering-exception">
<div class="neos-rendering-exception-title">Failed to render element' . $output . '</div>
</div>';
Expand Down
12 changes: 5 additions & 7 deletions Neos.Neos/Classes/Fusion/ExceptionHandlers/PageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Neos\FluidAdaptor\View\StandaloneView;
use Neos\Fusion\Core\ExceptionHandlers\AbstractRenderingExceptionHandler;
use Neos\Fusion\Core\ExceptionHandlers\HtmlMessageHandler;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\Service\ContentElementWrappingService;
use Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -86,14 +87,11 @@ protected function handle($fusionPath, \Exception $exception, $referenceCode)
}

if (!is_null($documentNode)) {
$contentRepositoryId = $documentNode->subgraphIdentity->contentRepositoryId;
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$workspace = $contentRepository->getWorkspaceFinder()->findOneByCurrentContentStreamId(
$documentNode->subgraphIdentity->contentStreamId
);
$renderingMode = $this->runtime->fusionGlobals->get('renderingMode');
assert($renderingMode instanceof RenderingMode);
if (
$workspace && !$workspace->workspaceName->isLive()
&& $this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')
$this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')
&& $renderingMode->isEdit
) {
$isBackend = true;
$fluidView->assign(
Expand Down
22 changes: 1 addition & 21 deletions Neos.Neos/Classes/Service/ContentElementEditableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@

namespace Neos\Neos\Service;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Fusion\Service\HtmlAugmenter as FusionHtmlAugmenter;
use Neos\Neos\FrontendRouting\NodeAddressFactory;

/**
* The content element editable service adds the necessary markup around
Expand Down Expand Up @@ -56,15 +54,6 @@ public function wrapContentProperty(Node $node, string $property, string $conten
$node->subgraphIdentity->contentRepositoryId
);

if (
$this->isContentStreamOfLiveWorkspace(
$node->subgraphIdentity->contentStreamId,
$contentRepository
)
) {
return $content;
}

// TODO: permissions
//if (!$this->nodeAuthorizationService->isGrantedToEditNode($node)) {
// return $content;
Expand All @@ -79,13 +68,4 @@ public function wrapContentProperty(Node $node, string $property, string $conten

return $this->htmlAugmenter->addAttributes($content, $attributes, 'span');
}

private function isContentStreamOfLiveWorkspace(
ContentStreamId $contentStreamId,
ContentRepository $contentRepository
): bool {
return $contentRepository->getWorkspaceFinder()
->findOneByCurrentContentStreamId($contentStreamId)
?->workspaceName->isLive() ?: false;
}
}
45 changes: 5 additions & 40 deletions Neos.Neos/Classes/Service/ContentElementWrappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@

namespace Neos\Neos\Service;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Flow\Session\SessionInterface;
use Neos\Fusion\Service\HtmlAugmenter as FusionHtmlAugmenter;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\Ui\Domain\Service\UserLocaleService;
use Neos\Neos\Ui\Fusion\Helper\NodeInfoHelper;

Expand Down Expand Up @@ -86,15 +84,6 @@ public function wrapContentObject(
$node->subgraphIdentity->contentRepositoryId
);

if (
$this->isContentStreamOfLiveWorkspace(
$node->subgraphIdentity->contentStreamId,
$contentRepository
)
) {
return $content;
}

// TODO: reenable permissions
//if ($this->nodeAuthorizationService->isGrantedToEditNode($node) === false) {
// return $content;
Expand Down Expand Up @@ -134,12 +123,10 @@ public function wrapCurrentDocumentMetadata(
string $fusionPath,
array $additionalAttributes = [],
): string {
$contentRepository = $this->contentRepositoryRegistry->get(
$node->subgraphIdentity->contentRepositoryId
);
if ($this->needsMetadata($node, $contentRepository, true) === false) {
return $content;
}
// TODO: reenable permissions
//if ($this->nodeAuthorizationService->isGrantedToEditNode($node) === false) {
// return $content;
//}

$attributes = $additionalAttributes;
$attributes['data-__neos-fusion-path'] = $fusionPath;
Expand Down Expand Up @@ -168,26 +155,4 @@ protected function addCssClasses(array $attributes, Node $node, array $initialCl

return $attributes;
}

protected function needsMetadata(
Node $node,
ContentRepository $contentRepository,
bool $renderCurrentDocumentMetadata
): bool {
return $this->isContentStreamOfLiveWorkspace(
$node->subgraphIdentity->contentStreamId,
$contentRepository
)
&& ($renderCurrentDocumentMetadata === true
/* TODO: permissions || $this->nodeAuthorizationService->isGrantedToEditNode($node) === true */);
}

private function isContentStreamOfLiveWorkspace(
ContentStreamId $contentStreamId,
ContentRepository $contentRepository
): bool {
return $contentRepository->getWorkspaceFinder()
->findOneByCurrentContentStreamId($contentStreamId)
?->workspaceName->isLive() ?: false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Neos\FluidAdaptor\Core\ViewHelper\AbstractTagBasedViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper\Exception as ViewHelperException;
use Neos\Fusion\ViewHelpers\FusionContextTrait;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\Service\ContentElementEditableService;

/**
Expand Down Expand Up @@ -114,7 +115,15 @@ public function render(): string
}
$this->tag->setContent($content);

return $this->contentElementEditableService->wrapContentProperty($node, $propertyName, (string)$this->tag->render());
$output = (string)$this->tag->render();

$renderingMode = $this->getContextVariable('renderingMode');
assert($renderingMode instanceof RenderingMode);
if (!$renderingMode->isEdit) {
return $output;
}

return $this->contentElementEditableService->wrapContentProperty($node, $propertyName, $output);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper\Exception as ViewHelperException;
use Neos\Fusion\FusionObjects\Helpers\FusionAwareViewInterface;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\Service\ContentElementWrappingService;

/**
Expand Down Expand Up @@ -85,6 +86,13 @@ public function render(): string
1645650713
);
}

$renderingMode = $fusionObject->getRuntime()->fusionGlobals->get('renderingMode');
assert($renderingMode instanceof RenderingMode);
if (!$renderingMode->isEdit) {
return (string)$this->renderChildren();
}

$currentContext = $fusionObject->getRuntime()->getCurrentContext();

$node = $this->arguments['node'] ?? $currentContext['node'];
Expand Down
13 changes: 6 additions & 7 deletions Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\CRTestSuiteRuntimeVariables;
Expand All @@ -24,9 +23,9 @@
use Neos\Fusion\Core\FusionSourceCodeCollection;
use Neos\Fusion\Core\Parser;
use Neos\Fusion\Core\RuntimeFactory;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Fusion\Exception\RuntimeException;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Domain\Service\RenderingModeService;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ServerRequestFactoryInterface;

Expand Down Expand Up @@ -68,12 +67,12 @@ public function setupFusionContext(): void
}

/**
* @When I am in Fusion rendering mode:
* @When the Fusion renderingMode is :requestUri
*/
public function iAmInFusionRenderingMode(TableNode $renderingModeData): void
public function iAmInFusionRenderingMode(string $renderingModeName): void
{
$data = $renderingModeData->getHash()[0];
$this->fusionGlobalContext['renderingMode'] = new RenderingMode($data['name'] ?? 'Testing', strtolower($data['isEdit'] ?? 'false') === 'true', strtolower($data['isPreview'] ?? 'false') === 'true', $data['title'] ?? 'Testing', $data['fusionPath'] ?? 'root', []);
$renderingMode = $this->getObject(RenderingModeService::class)->findByName($renderingModeName);
$this->fusionGlobalContext['renderingMode'] = $renderingMode;
}

/**
Expand Down
Loading

0 comments on commit e304fc6

Please sign in to comment.