From 32b4b1593752025d563d425617c16fb60865c813 Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Tue, 20 Aug 2019 11:10:20 +0000 Subject: [PATCH] Prevent login redirect with ?timeout during logout When logging out via the Logout button, when there are multiple HTTP requests happening, the logout can cause API requests to fail with a 401 before the browser redirects to the login screen, causing the response handler to call redirectLogin, to redirec to the login screen with a "session timed out" message. We should not be claiming a timeout *during* logout, adding a check for that. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1741283 --- app/assets/javascripts/miq_application.js | 4 ++++ app/assets/javascripts/miq_global.js | 1 + app/views/layouts/_user_options.html.haml | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/miq_application.js b/app/assets/javascripts/miq_application.js index 27d4e4b8cdf..184a27b66f0 100644 --- a/app/assets/javascripts/miq_application.js +++ b/app/assets/javascripts/miq_application.js @@ -1718,6 +1718,10 @@ var fontIconChar = _.memoize(function(klass) { }); function redirectLogin(msg) { + if (ManageIQ.logoutInProgress) { + return; // prevent double redirect after pressing the Logout button + } + add_flash(msg, 'warning'); window.document.location.href = '/dashboard/login?timeout=true'; } diff --git a/app/assets/javascripts/miq_global.js b/app/assets/javascripts/miq_global.js index 66d73e859b0..28765478a12 100644 --- a/app/assets/javascripts/miq_global.js +++ b/app/assets/javascripts/miq_global.js @@ -48,6 +48,7 @@ if (!window.ManageIQ) { i18n: { mark_translated_strings: false, }, + logoutInProgress: false, // prevent redirectLogin *during* logout mouse: { x: null, // mouse X coordinate for popup menu y: null, // mouse Y coordinate for popup menu diff --git a/app/views/layouts/_user_options.html.haml b/app/views/layouts/_user_options.html.haml index 2e65161a4ba..a5275a3799f 100644 --- a/app/views/layouts/_user_options.html.haml +++ b/app/views/layouts/_user_options.html.haml @@ -46,7 +46,7 @@ = _(menu_item.name) %li.divider %li - %a{:href => "/dashboard/logout", :onclick => 'return miqCheckForChanges()', :title => _("Click to Logout")} + %a{:href => "/dashboard/logout", :onclick => 'ManageIQ.logoutInProgress = true; return miqCheckForChanges()', :title => _("Click to Logout")} = _('Logout') - else