Skip to content

Commit

Permalink
Show updated session dialog before doing the final check about if the…
Browse files Browse the repository at this point in the history
… session was removed or changed. Also, only show the dialog if not in embedded mode
  • Loading branch information
aarranz committed Jul 8, 2021
1 parent 729def0 commit dd731e9
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions wirecloud/keycloak/static/js/keycloak/sso.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
(() => {
/*
* Copyright (c) 2021 Future Internet Consulting and Development Solutions S.L.
*
* This file is part of Wirecloud Platform.
*
* Wirecloud Platform is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Wirecloud is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Wirecloud Platform. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

/* globals Wirecloud */


((utils) => {
"use strict";

const login_status_iframe = document.createElement("iframe");
Expand All @@ -21,16 +45,11 @@
}

window.removeEventListener("message", handleChange);
const dialog = new Wirecloud.ui.MessageWindowMenu(
"Browser will be reloaded to accomodate to the new session info",
"User Session Updated"
);
if (event.data === "changed") {
dialog.addEventListener("hide", () => Wirecloud.login());
Wirecloud.login();
} else {
dialog.addEventListener("hide", () => Wirecloud.logout());
Wirecloud.logout();
}
dialog.show();
};

const processResponse = function processResponse(event) {
Expand All @@ -42,20 +61,29 @@
clearInterval(interval);
window.removeEventListener("message", processResponse);
const session_state = Wirecloud.contextManager.get("keycloak_session");
let action;
if (session_state === "") {
action = () => Wirecloud.login();
} else {
action = () => {
const client_id = Wirecloud.contextManager.get("keycloak_client_id");
window.addEventListener("message", handleChange);
// string literals/templates are not supported by the django-compressor module used by WireCloud <= 1.4
login_status_iframe.contentWindow.postMessage(client_id + " ", iframe_url.origin);
};
}

if (Wirecloud.contextManager.get("mode") !== "embedded") {
const dialog = new Wirecloud.ui.MessageWindowMenu(
"Browser will be reloaded to accomodate to the new session info",
"User Session Updated"
utils.gettext("Browser will be reloaded to accomodate to the new session info"),
utils.gettext("User Session Updated")
);
dialog.addEventListener("hide", () => Wirecloud.login());
dialog.addEventListener("hide", action);
dialog.show();
} else {
const client_id = Wirecloud.contextManager.get("keycloak_client_id");
window.addEventListener("message", handleChange);
// string literals/templates are not supported by the django-compressor module used by WireCloud <= 1.4
login_status_iframe.contentWindow.postMessage(client_id + " ", iframe_url.origin);
action();
}
}
};
window.addEventListener("message", processResponse);
})();
})(Wirecloud.Utils);

0 comments on commit dd731e9

Please sign in to comment.