Skip to content

Commit 4287534

Browse files
Improve error handling on profile redirection
1 parent c742a9d commit 4287534

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Glpi/Controller/Session/ChangeProfileController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ public function __invoke(Request $request): Response
7373
$route = $go_to_create_ticket ? "/ServiceCatalog" : "/Helpdesk";
7474
$redirect = $request->getBasePath() . $route;
7575
} else {
76-
$_SESSION['_redirected_from_profile_selector'] = true;
7776
$redirect = Html::getBackUrl();
77+
$separator = str_contains($redirect, '?') ? "&" : "?";
78+
$redirect = $redirect . $separator . '_redirected_from_profile_selector=true';
7879
}
7980

8081
return new RedirectResponse($redirect);

src/Glpi/Kernel/Listener/ExceptionListener/AccessErrorListener.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public function onKernelException(ExceptionEvent $event): void
7272

7373
$response = null;
7474

75+
// On profile change, we will redirect the user to the home page in case
76+
// of access errors for the current page.
77+
$redirect_to_home_on_error = $event->getRequest()
78+
->query
79+
->getBoolean('_redirected_from_profile_selector')
80+
;
81+
7582
if ($throwable instanceof SessionExpiredException) {
7683
Session::destroy(); // destroy the session to prevent pesistence of unexpected data
7784

@@ -84,10 +91,8 @@ public function onKernelException(ExceptionEvent $event): void
8491
);
8592
} elseif (
8693
$throwable instanceof AccessDeniedHttpException
87-
&& ($_SESSION['_redirected_from_profile_selector'] ?? false)
94+
&& $redirect_to_home_on_error
8895
) {
89-
unset($_SESSION['_redirected_from_profile_selector']);
90-
9196
$request = $event->getRequest();
9297
$response = new RedirectResponse(
9398
sprintf(

0 commit comments

Comments
 (0)