From 4743c5f5c8499cb3b59f3b2e9fe6bad6e7812653 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 26 Oct 2023 11:59:56 +0200 Subject: [PATCH 1/3] loader.js: Really don't push redirects to history refs #4879 --- public/js/icinga/loader.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index cb512c03dc..c736a48f74 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -637,6 +637,7 @@ var redirectionUrl = icinga.utils.addUrlFlag(url, 'renderLayout'); var r = this.loadUrl(redirectionUrl, $('#layout')); r.historyUrl = url; + r.referrer = referrer; if (parts.length) { r.loadNext = parts; } else if (!! document.location.hash) { @@ -961,7 +962,7 @@ }); } - if (this.processRedirectHeader(req)) { + if ((textStatus === 'abort' && typeof req.referrer !== 'undefined') || this.processRedirectHeader(req)) { return; } From 30b540952ac8c25f34236ed358dcfb6eb925071b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 26 Oct 2023 12:00:42 +0200 Subject: [PATCH 2/3] loader.js: Don't consider redirected form submits as auto submits A redirect caused by a form submit is **never** an automatic submit. Unless I'm missing something here. There is one way this may be true, as ipl forms without a submit button are indeed successful due to a autosubmit element, but they don't redirect by default. So if the controller redirects in such a case, the form should have a submit button, I guess.. Anyway, this is necessary due to the previous commit as this may otherwise cause form submits, that re-render layout during a redirect, are considered being auto submitted. (Such as the login form) --- public/js/icinga/loader.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index c736a48f74..97891a7f2b 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -790,14 +790,9 @@ this.icinga.ui.setWindowId(windowId); } - var referrer = req.referrer; - if (typeof referrer === 'undefined') { - referrer = req; - } - var autoSubmit = false; var currentUrl = this.icinga.utils.parseUrl(req.$target.data('icingaUrl')); - if (referrer.method === 'POST') { + if (req.method === 'POST') { var newUrl = this.icinga.utils.parseUrl(req.url); if (newUrl.path === currentUrl.path && this.icinga.utils.arraysEqual(newUrl.params, currentUrl.params)) { autoSubmit = true; @@ -817,7 +812,7 @@ let url = currentUrl.path + (locationQuery ? '?' + locationQuery : ''); if (req.autosubmit || autoSubmit) { // Also update a form's action if it doesn't differ from the container's url - var $form = $(referrer.forceFocus).closest('form'); + var $form = $(req.forceFocus).closest('form'); var formAction = $form.attr('action'); if (!! formAction) { formAction = this.icinga.utils.parseUrl(formAction); From a2c143d75ec8c401051e0f38cbd6bdbd1306fadf Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 26 Oct 2023 12:05:49 +0200 Subject: [PATCH 3/3] Response: Only preserve `showCompact` for explicit redirects In case of a `__SELF__` redirect, the client should still have the parameter in the location and its preserved this way then. --- library/Icinga/Web/Response.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Response.php b/library/Icinga/Web/Response.php index 182076f92a..555d3fa8b9 100644 --- a/library/Icinga/Web/Response.php +++ b/library/Icinga/Web/Response.php @@ -322,7 +322,9 @@ protected function prepare() if ($request->isXmlHttpRequest()) { if ($redirectUrl !== null) { if ($request->isGet() && Icinga::app()->getViewRenderer()->view->compact) { - $redirectUrl->getParams()->set('showCompact', true); + if ($redirectUrl->getParam('redirect') !== '__SELF__') { + $redirectUrl->getParams()->set('showCompact', true); + } } $encodedRedirectUrl = rawurlencode($redirectUrl->getAbsoluteUrl());