From af1f9cb48ecfcfe1d941eacd7dcd32326840df52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 18 Aug 2018 23:40:43 +0200 Subject: [PATCH] Avoid multiple login modal Reloading the context should be done with the current session because it can trigger a renewal and so the current session should be renewed. When login is canceled, the session clearing must be stored and we should logout. issue7617 review52431002 --- src/session.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/session.js b/src/session.js index 2168177e6f..668241c2b8 100644 --- a/src/session.js +++ b/src/session.js @@ -52,8 +52,9 @@ }.bind(this), function() { this.user_id = null; this.session = null; + this.store(); dfd.reject(); - }); + }.bind(this)); return dfd.promise(); }, do_logout: function() { @@ -90,10 +91,8 @@ 'method': 'model.res.user.get_preferences', 'params': [true, {}] }; - // Call with custom session to not send context - var session = jQuery.extend({}, this); - session.context = {}; - var prm = Sao.rpc(args, session); + this.context = {}; + var prm = Sao.rpc(args, this); return prm.then(function(context) { this.context = context; }.bind(this)); @@ -245,11 +244,10 @@ } var dfd = jQuery.Deferred(); session.prm = dfd.promise(); - if (!session.login) { + session.do_login(session.login).then(dfd.resolve, function() { + Sao.logout(); dfd.reject(); - return session.prm; - } - session.do_login(session.login).then(dfd.resolve, dfd.reject); + }); return session.prm; }; @@ -313,8 +311,17 @@ dfd.resolve(data.result); } }; + var ajax_error = function(query, status_, error) { + if (query.status == 401) { + // Retry + this.run({}).then(dfd.resolve, dfd.reject); + } else { + Sao.common.error.run(status_, error); + dfd.reject(); + } + }; ajax_prm.done(ajax_success.bind(this)); - ajax_prm.fail(dfd.reject); + ajax_prm.fail(ajax_error.bind(this)); return dfd.promise(); }, get_char: function(message) {