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

WIP: Rename previewAction to editAction #4217

Draft
wants to merge 3 commits into
base: 8.3
Choose a base branch
from
Draft
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
41 changes: 39 additions & 2 deletions Neos.Neos/Classes/Controller/Frontend/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ public function showAction(NodeInterface $node = null)
* @return void
* @throws NoSuchArgumentException
*/
protected function initializePreviewAction(): void
protected function initializeEditAction(): void
{
if ($this->arguments->hasArgument('node') && $this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
$this->arguments->getArgument('node')->getPropertyMappingConfiguration()->setTypeConverterOption(NodeConverter::class, NodeConverter::INVISIBLE_CONTENT_SHOWN, true);
}
}

/**
* Previews a node that is not live (i.e. for the Backend Preview & Edit Mode)
* Previews a node that is not live (i.e. for the Backend Preview Mode)
*
* @param NodeInterface $node
* @return string View output for the specified node
Expand Down Expand Up @@ -161,6 +161,43 @@ public function previewAction(NodeInterface $node = null)
}
}

/**
* Renders a node in backend
*
* @param NodeInterface|null $node
* @throws NeosException
* @throws NodeNotFoundException
* @throws SessionNotStartedException
* @throws UnresolvableShortcutException
*/
public function editAction(NodeInterface $node = null)
{
if ($node === null) {
throw new NodeNotFoundException('The requested node does not exist or isn\'t accessible to the current user', 1430218623);
}

$inBackend = $node->getContext()->isInBackend();

if ($node->getNodeType()->isOfType('Neos.Neos:Shortcut') && !$inBackend) {
$this->handleShortcutNode($node);
}

$this->view->assign('value', $node);

if ($inBackend) {
$this->overrideViewVariablesFromInternalArguments();
$this->response->setHttpHeader('Cache-Control', 'no-cache');
if (!$this->view->canRenderWithNodeAndPath()) {
$this->view->setFusionPath('rawContent');
}

if ($this->session->isStarted()) {
$this->session->putData('lastVisitedNode', $node->getContextPath());
}
}
}


/**
* Checks if the optionally given node context path, affected node context path and Fusion path are set
* and overrides the rendering to use those. Will also add a "X-Neos-AffectedNodePath" header in case the
Expand Down
26 changes: 24 additions & 2 deletions Neos.Neos/Classes/Service/LinkingService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Neos\Neos\Service;

/*
Expand All @@ -11,6 +12,7 @@
* source code.
*/

use http\Exception\RuntimeException;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\BaseUriProvider;
Expand All @@ -29,6 +31,7 @@
use Neos\Neos\TYPO3CR\NeosNodeServiceInterface;
use Psr\Http\Message\UriInterface;
use Psr\Log\LoggerInterface;
use function Psalm\get_path_to_config;

/**
* A service for creating URIs pointing to nodes and assets.
Expand Down Expand Up @@ -242,7 +245,7 @@ public function convertUriToObject($uri, NodeInterface $contextNode = null)
* @throws HttpException
* @throws \Neos\Flow\Persistence\Exception\IllegalObjectTypeException
*/
public function createNodeUri(ControllerContext $controllerContext, $node = null, NodeInterface $baseNode = null, $format = null, $absolute = false, array $arguments = [], $section = '', $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], $resolveShortcuts = true): string
public function createNodeUri(ControllerContext $controllerContext, $node = null, NodeInterface $baseNode = null, $format = null, $absolute = false, array $arguments = [], $section = '', $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], $resolveShortcuts = true, ?string $overrideDefaultAction = null): string
{
$this->lastLinkedNode = null;
if ($resolveShortcuts === false) {
Expand Down Expand Up @@ -284,7 +287,7 @@ public function createNodeUri(ControllerContext $controllerContext, $node = null
$request = $controllerContext->getRequest()->getMainRequest();
$uriBuilder = clone $controllerContext->getUriBuilder();
$uriBuilder->setRequest($request);
$action = $node->getContext()->getWorkspace()->isPublicWorkspace() && !$node->isHidden() ? 'show' : 'preview';
$action = $this->determineAction($request, $overrideDefaultAction);
return $uriBuilder
->reset()
->setSection($section)
Expand Down Expand Up @@ -333,4 +336,23 @@ public function getLastLinkedNode(): ?NodeInterface
{
return $this->lastLinkedNode;
}

/**
* @param NodeInterface $node
* @param \Neos\Flow\Mvc\ActionRequest $request
* @return string
* @throws \Neos\Flow\Persistence\Exception\IllegalObjectTypeException
*/
private function determineAction(\Neos\Flow\Mvc\ActionRequest $request, ?string $overrideActionName): string
{
$validActions = ['show', 'preview', 'edit'];
if ($overrideActionName === null) {
return in_array($request->getControllerActionName(), $validActions) ? $request->getControllerActionName() : 'show';
}
if (in_array($overrideActionName, $validActions)) {
return $overrideActionName;
}
throw new \RuntimeException('Override action not allowed', 1682778247);

}
}
8 changes: 8 additions & 0 deletions Neos.Neos/Configuration/Policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ privilegeTargets:
label: Access to the backend content preview
matcher: 'method(Neos\Neos\Controller\Frontend\NodeController->previewAction())'

'Neos.Neos:ContentEdit':
label: Access to the backend edit mode
matcher: 'method(Neos\Neos\Controller\Frontend\NodeController->editAction())'

'Neos.Neos:BackendLogin':
label: General access to the backend login
matcher: 'method(Neos\Neos\Controller\LoginController->(index|tokenLogin|authenticate)Action()) || method(Neos\Flow\Security\Authentication\Controller\AbstractAuthenticationController->authenticateAction())'
Expand Down Expand Up @@ -225,6 +229,10 @@ roles:
privilegeTarget: 'Neos.Neos:ContentPreview'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:ContentEdit'
permission: GRANT

-
privilegeTarget: 'Neos.Neos:Backend.PersonalWorkspaceReadAccess.NodeConverter'
permission: GRANT
Expand Down
7 changes: 7 additions & 0 deletions Neos.Neos/Configuration/Routes.Frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
'@action': 'preview'
appendExceedingArguments: true

-
name: 'Edit'
uriPattern: 'neos/edit'
defaults:
'@action': 'edit'
appendExceedingArguments: true

-
name: 'Default Frontend'
uriPattern: '{node}'
Expand Down
Loading