Skip to content

Commit

Permalink
Merge pull request #4597 from neos/task/remove-lastVisitedNode-handling
Browse files Browse the repository at this point in the history
TASK: Removes lastVisitedNode javascript and handling
  • Loading branch information
nezaniel authored Oct 16, 2023
2 parents 9227deb + 0e7f1df commit 4d4538e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 130 deletions.
4 changes: 0 additions & 4 deletions Neos.Neos/Classes/Controller/Frontend/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ public function previewAction(string $node): void
if (!$this->view->canRenderWithNodeAndPath()) {
$this->view->setFusionPath('rawContent');
}

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

Expand Down
16 changes: 2 additions & 14 deletions Neos.Neos/Classes/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function initializeIndexAction(): void
$this->request->setArgument(
'username',
$authenticationArgument['Neos']['Flow']['Security']['Authentication']
['Token']['UsernamePassword']['username']
['Token']['UsernamePassword']['username']
);
}
}
Expand Down Expand Up @@ -173,9 +173,7 @@ public function tokenLoginAction(string $token): void
if ($newSession->canBeResumed()) {
$newSession->resume();
}
if ($newSession->isStarted()) {
$newSession->putData('lastVisitedNode', null);
} else {
if (!$newSession->isStarted()) {
$this->logger->error(sprintf(
'Failed resuming or starting session %s which was referred to in the login token %s.',
$newSessionId,
Expand Down Expand Up @@ -230,12 +228,6 @@ protected function onAuthenticationSuccess(ActionRequest $originalRequest = null
]
);
} else {
if (
$this->request->hasArgument('lastVisitedNode')
&& $this->request->getArgument('lastVisitedNode') !== ''
) {
$this->session->putData('lastVisitedNode', $this->request->getArgument('lastVisitedNode'));
}
if ($originalRequest !== null) {
// Redirect to the location that redirected to the login form because the user was nog logged in
$this->redirectToRequest($originalRequest);
Expand All @@ -256,16 +248,12 @@ protected function onAuthenticationSuccess(ActionRequest $originalRequest = null
*/
public function logoutAction(): void
{
$possibleRedirectionUri = $this->backendRedirectionService->getAfterLogoutRedirectionUri($this->request);
parent::logoutAction();
switch ($this->request->getFormat()) {
case 'json':
$this->view->assign('value', ['success' => true]);
break;
default:
if ($possibleRedirectionUri !== null) {
$this->redirectToUri($possibleRedirectionUri);
}
$this->addFlashMessage(
$this->getLabel('login.loggedOut.body'),
$this->getLabel('login.loggedOut.title'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Neos\Neos\Controller\Module\Administration;

use Neos\ContentRepository\Core\Feature\NodeRenaming\Command\ChangeNodeAggregateName;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeNameIsAlreadyOccupied;
Expand Down Expand Up @@ -234,7 +233,7 @@ public function updateSiteAction(Site $site, $newSiteNodeName)
[],
1412371798
);
$this->unsetLastVisitedNodeAndRedirect('index');
$this->redirect('index');
}

/**
Expand Down Expand Up @@ -430,7 +429,7 @@ public function createSiteNodeAction($packageKey, $siteName, $nodeType)
[],
1412372266
);
$this->unsetLastVisitedNodeAndRedirect('index');
$this->redirect('index');
}

/**
Expand All @@ -450,7 +449,7 @@ public function deleteSiteAction(Site $site)
[],
1412372689
);
$this->unsetLastVisitedNodeAndRedirect('index');
$this->redirect('index');
}

/**
Expand All @@ -470,7 +469,7 @@ public function activateSiteAction(Site $site)
[],
1412372881
);
$this->unsetLastVisitedNodeAndRedirect('index');
$this->redirect('index');
}

/**
Expand All @@ -490,7 +489,7 @@ public function deactivateSiteAction(Site $site)
[],
1412372975
);
$this->unsetLastVisitedNodeAndRedirect('index');
$this->redirect('index');
}

/**
Expand Down Expand Up @@ -525,7 +524,7 @@ public function updateDomainAction(Domain $domain)
[],
1412373069
);
$this->unsetLastVisitedNodeAndRedirect('edit', null, null, ['site' => $domain->getSite()]);
$this->redirect('edit', null, null, ['site' => $domain->getSite()]);
}

/**
Expand Down Expand Up @@ -562,7 +561,7 @@ public function createDomainAction(Domain $domain)
[],
1412373192
);
$this->unsetLastVisitedNodeAndRedirect('edit', null, null, ['site' => $domain->getSite()]);
$this->redirect('edit', null, null, ['site' => $domain->getSite()]);
}

/**
Expand All @@ -587,7 +586,7 @@ public function deleteDomainAction(Domain $domain)
[],
1412373310
);
$this->unsetLastVisitedNodeAndRedirect('edit', null, null, ['site' => $site]);
$this->redirect('edit', null, null, ['site' => $site]);
}

/**
Expand All @@ -608,7 +607,7 @@ public function activateDomainAction(Domain $domain)
[],
1412373539
);
$this->unsetLastVisitedNodeAndRedirect('edit', null, null, ['site' => $domain->getSite()]);
$this->redirect('edit', null, null, ['site' => $domain->getSite()]);
}

/**
Expand All @@ -629,31 +628,6 @@ public function deactivateDomainAction(Domain $domain)
[],
1412373425
);
$this->unsetLastVisitedNodeAndRedirect('edit', null, null, ['site' => $domain->getSite()]);
}

/**
* @param string $actionName Name of the action to forward to
* @param string $controllerName Unqualified object name of the controller to forward to.
* If not specified, the current controller is used.
* @param string $packageKey Key of the package containing the controller to forward to.
* If not specified, the current package is assumed.
* @param array<string,mixed> $arguments Array of arguments for the target action
* @param integer $delay (optional) The delay in seconds. Default is no delay.
* @param integer $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other"
* @param string $format The format to use for the redirect URI
* @return void
*/
protected function unsetLastVisitedNodeAndRedirect(
$actionName,
$controllerName = null,
$packageKey = null,
array $arguments = [],
$delay = 0,
$statusCode = 303,
$format = null
) {
$this->session->putData('lastVisitedNode', null);
parent::redirect($actionName, $controllerName, $packageKey, $arguments, $delay, $statusCode, $format);
$this->redirect('edit', null, null, ['site' => $domain->getSite()]);
}
}
50 changes: 0 additions & 50 deletions Neos.Neos/Classes/Service/BackendRedirectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,54 +136,4 @@ protected function determineStartModule(array $availableModules): ?array

return $firstModule;
}

/**
* Returns a specific URI string to redirect to after the logout; or NULL if there is none.
* In case of NULL, it's the responsibility of the AuthenticationController where to redirect,
* most likely to the LoginController's index action.
*
* @param ActionRequest $actionRequest
* @return string A possible redirection URI, if any
* @throws \Neos\Flow\Http\Exception
* @throws MissingActionNameException
*/
public function getAfterLogoutRedirectionUri(ActionRequest $actionRequest): ?string
{
$lastVisitedNode = $this->getLastVisitedNode('live', $actionRequest);
if ($lastVisitedNode === null) {
return null;
}
$uriBuilder = new UriBuilder();
$uriBuilder->setRequest($actionRequest);
$uriBuilder->setFormat('html');
$uriBuilder->setCreateAbsoluteUri(true);

return $uriBuilder->uriFor('show', ['node' => $lastVisitedNode], 'Frontend\\Node', 'Neos.Neos');
}

protected function getLastVisitedNode(string $workspaceName, ActionRequest $actionRequest): ?Node
{
$contentRepositoryId = SiteDetectionResult::fromRequest($actionRequest->getHttpRequest())
->contentRepositoryId;
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$workspace = $contentRepository->getWorkspaceFinder()->findOneByName(WorkspaceName::fromString($workspaceName));
if (!$workspace || !$this->session->isStarted() || !$this->session->hasKey('lastVisitedNode')) {
return null;
}
try {
/** @var Node $lastVisitedNode */
$lastVisitedNode = $this->propertyMapper->convert(
$this->session->getData('lastVisitedNode'),
Node::class
);

return $contentRepository->getContentGraph()->getSubgraph(
$workspace->currentContentStreamId,
$lastVisitedNode->subgraphIdentity->dimensionSpacePoint,
VisibilityConstraints::withoutRestrictions()
)->findNodeById($lastVisitedNode->nodeAggregateId);
} catch (\Exception $exception) {
return null;
}
}
}
4 changes: 0 additions & 4 deletions Neos.Neos/Resources/Private/Fusion/Backend/Views/Login.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ prototype(Neos.Neos:View.Login) < prototype(Neos.Fusion:Component) {
document.querySelector('.neos-login-btn').classList.toggle('neos-hidden');
document.querySelector('.neos-login-btn.neos-disabled').classList.toggle('neos-hidden');
});
try {
document.querySelector('form[name=\"login\"] input[name=\"lastVisitedNode\"]').value = sessionStorage.getItem('Neos.Neos.lastVisitedNode');
} catch(e) {}
"}</script>
</body>
</html>
Expand All @@ -111,7 +108,6 @@ prototype(Neos.Neos:Component.Login.Form) < prototype(Neos.Fusion:Component) {

renderer = afx`
<Neos.Fusion.Form:Form form.target.action="authenticate" attributes.name="login">
<Neos.Fusion.Form:Hidden field.name="lastVisitedNode" />
<fieldset>
<div class="neos-controls">
<Neos.Fusion.Form:Input
Expand Down
14 changes: 0 additions & 14 deletions Neos.Neos/Resources/Private/Fusion/Prototypes/Page.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,6 @@ prototype(Neos.Neos:Page) < prototype(Neos.Fusion:Http.Message) {
@process.appendJavaScripts = ${value + this.javascripts}
}

# This enables redirecting to the last visited page after login
lastVisitedNodeScript = Neos.Fusion:Tag {
@position = 'before closingBodyTag'

tagName = 'script'
attributes {
data-neos-node = ${Neos.Node.serializedNodeAddress(node)}
src = Neos.Fusion:ResourceUri {
path = 'resource://Neos.Neos/Public/JavaScript/LastVisitedNode.js'
}
async = true
}
}

closingBodyTag = '</body>'
closingBodyTag.@position = 'end 100'

Expand Down
8 changes: 0 additions & 8 deletions Neos.Neos/Resources/Public/JavaScript/LastVisitedNode.js

This file was deleted.

0 comments on commit 4d4538e

Please sign in to comment.