Skip to content

Commit

Permalink
Merge pull request #6325 from himdel/change_group-api
Browse files Browse the repository at this point in the history
Fix logout on group change
  • Loading branch information
mzazrivec authored Oct 23, 2019
2 parents c300913 + 36e1bae commit b59885c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions app/assets/javascripts/miq_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,16 +696,6 @@ function miqEnterPressed(e) {
return (keycode === 13);
}

function storeUserFeatures() {
delete window.localStorage.userFeatures;
return window.http.get('/api?attributes=identity')
.then(function(data) {
window.localStorage.userFeatures = JSON.stringify(data.identity.miq_groups.find(function(group) {
return data.identity.group === group.description;
}).product_features);
});
}

// Send login authentication via ajax
function miqAjaxAuth(url) {
miqEnableLoginFields(false);
Expand Down Expand Up @@ -977,9 +967,14 @@ function miqShowAE_Tree(typ) {
return true;
}

// Toggle the user options div in the page header
function miqToggleUserOptions(id) {
miqJqueryRequest(miqPassFields('/dashboard/change_group', {to_group: id}), { done: storeUserFeatures });
// Toggle the user options div in the page header (:onclick from layouts/user_options)
function miqChangeGroup(id) {
miqSparkleOn();

// prevent login redirect once current requests fail after the group gets changed
ManageIQ.logoutInProgress = true;

miqJqueryRequest(miqPassFields('/dashboard/change_group', {to_group: id}));
}

// Check for enter/escape on quick search box
Expand Down Expand Up @@ -1552,7 +1547,7 @@ var fontIconChar = _.memoize(function(klass) {

function redirectLogin(msg) {
if (ManageIQ.logoutInProgress) {
return; // prevent double redirect after pressing the Logout button
return; // prevent double redirect after pressing the Logout button or when changing group
}

add_flash(msg, 'warning');
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/miq_global.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (!window.ManageIQ) {
i18n: {
mark_translated_strings: false,
},
logoutInProgress: false, // prevent redirectLogin *during* logout
logoutInProgress: false, // prevent redirectLogin *during* logout and group change
mouse: {
x: null, // mouse X coordinate for popup menu
y: null, // mouse Y coordinate for popup menu
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_user_options.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
%li
%a{:title => _("Change to this Group"),
:href => "#",
:onclick => "miqSparkle(true); miqToggleUserOptions(#{group.id})"}
:onclick => "miqChangeGroup('#{j_str group.id}')"}
= group.description
- else
%li.disabled
Expand Down

0 comments on commit b59885c

Please sign in to comment.