This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 4c2c30a25e614409819790b0e9ed4d1ee0a1a01a Author: Kevin Morin <morin@codelutin.com> Date: Tue Sep 19 17:37:54 2017 +0200 erreur quand on recharge une page réservée à l'admin --- pollen-ui-riot-js/src/main/web/js/Session.js | 20 ++++++++++++-- pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html | 32 +++++++++++----------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/js/Session.js b/pollen-ui-riot-js/src/main/web/js/Session.js index 3524ec10..251dcd1c 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -127,8 +127,24 @@ class Session { return document.cookie.indexOf("pollen-connected=true") !== -1; } - isAdminConnected() { - return this.isConnected() && this.getUser().administrator; + isAdminConnected(callback, fallback) { + let userConnectedCallback = (user) => { + if (user.administrator) { + callback(); + } else { + fallback(); + } + bus.off("user", this); + }; + if (this.isConnected()) { + if (this.user) { + userConnectedCallback(this.user); + } else { + bus.on("user", userConnectedCallback); + } + } else { + fallback(); + } } connect() { diff --git a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html index cf0c4fc5..b3ff983d 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html @@ -141,30 +141,30 @@ require("./popup/GtuChangeModal.tag.html"); }); route("/poll", () => { - if (!session.isAdminConnected()) { - route("/signin?url=/poll"); - } else { + session.isAdminConnected(() => { this.bus.trigger("pageChanged", "admin_polls"); riot.mount(this.refs.content, "polls", {method: "polls", session: session}); - } + }, () => { + route("/signin?url=/poll"); + }); }); route("/user", () => { - if (!session.isAdminConnected()) { - route("/signin?url=/user"); - } else { + session.isAdminConnected(() => { this.bus.trigger("pageChanged", "admin_users"); riot.mount(this.refs.content, "users", {session: session}); - } + }, () => { + route("/signin?url=/user"); + }); }); route("/gtu", () => { - if (!session.isAdminConnected()) { - route("/signin?url=/user"); - } else { + session.isAdminConnected(() => { this.bus.trigger("pageChanged", "admin_gtus"); riot.mount(this.refs.content, "gtus", {session: session}); - } + }, () => { + route("/signin?url=/user"); + }); }); route("/poll/*/choice", (pollId) => { @@ -241,12 +241,12 @@ require("./popup/GtuChangeModal.tag.html"); }); route("/loginProviders", () => { - if (!session.isAdminConnected()) { - route("/signin?url=/loginProviders"); - } else { + session.isAdminConnected(() => { this.bus.trigger("pageChanged", "loginProviders"); riot.mount(this.refs.content, "loginproviders"); - } + }, () => { + route("/signin?url=/loginProviders"); + }); }); route("/privacy", () => { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.