From 301d63b8c96deece3084be319a2f99843f7823d2 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 28 Feb 2013 11:16:14 +0100 Subject: [PATCH 01/19] [WIP] wip , lots of troubles ! bzr revid: fme@openerp.com-20130228101614-zn4prwhi6zk0h13d --- addons/web/controllers/main.py | 3 +++ addons/web/static/src/js/chrome.js | 31 ++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 247d6f5dd00..7758510ecba 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -535,6 +535,9 @@ class Home(openerpweb.Controller): @openerpweb.httprequest def index(self, req, s_action=None, db=None, **kw): + if not db: + # TODO: maybe redirect to ?db=xxx instead of implicit db set ?? + db = req.httprequest.cookies.get('last_db_login_success') js = "\n ".join('' % i for i in manifest_list(req, 'js', db=db)) css = "\n ".join('' % i for i in manifest_list(req, 'css', db=db)) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 6b16204932b..a207d37dd41 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -619,10 +619,19 @@ instance.web.Login = instance.web.Widget.extend({ self.$el.find('.oe_login_manage_db').click(function() { self.do_action("database_manager"); }); + self.on('change:database_selector', this, function() { + var params = $.deparam.querystring(); + params.db = self.get('database_selector'); + self.$('.oe_login_dbpane').empty().text(_t('Loading...')); + window.location = '/?' + $.param(params); + }); var d = $.when(); if ($.deparam.querystring().db) { self.params.db = $.deparam.querystring().db; } + if (self.params.db) { + self.selected_db = self.params.db; + } if ($.param.fragment().token) { self.params.token = $.param.fragment().token; } @@ -630,17 +639,22 @@ instance.web.Login = instance.web.Widget.extend({ if (self.params.db && self.params.login && self.params.password) { d = self.do_login(self.params.db, self.params.login, self.params.password); } else { - if (self.params.db) { - self.on_db_loaded([self.params.db]) - } else { + // TODO: removing following code breaks portal anonymous + //if (self.params.db) { + // self.on_db_loaded([self.params.db]) + //} else { d = self.rpc("/web/database/get_list", {}).done(self.on_db_loaded).fail(self.on_db_failed); - } + //} } return d; }, on_db_loaded: function (result) { + var self = this; this.db_list = result; this.$("[name=db]").replaceWith(QWeb.render('Login.dblist', { db_list: this.db_list, selected_db: this.selected_db})); + this.$('select[name=db]').on('change', function(ev) { + self.set('database_selector', $(this).val()); + }); if(this.db_list.length === 0) { this.do_action("database_manager"); } else if(this.db_list.length === 1) { @@ -680,6 +694,15 @@ instance.web.Login = instance.web.Widget.extend({ self.hide_error(); self.$(".oe_login_pane").fadeOut("slow"); return this.session.session_authenticate(db, login, password).then(function() { + // This cookie will be used server side in order to avoid db reloading on next visit + var ttl = 24 * 60 * 60 * 365; + document.cookie = [ + 'last_db_login_success=' + db, + 'path=/', + 'max-age=' + ttl, + 'expires=' + new Date(new Date().getTime() + ttl * 1000).toGMTString() + ].join(';'); + if (self.has_local_storage) { if(self.remember_credentials) { localStorage.setItem('last_db_login_success', db); From d6e460d9e760f76e37efe1e4d4b51c1adb1b78f1 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 28 Feb 2013 17:15:37 +0100 Subject: [PATCH 02/19] [FIX] Correctly handles db param in url. Home controller redirects on db if more than one db bzr revid: fme@openerp.com-20130228161537-cen2lyknfifqtyu0 --- addons/web/controllers/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 7758510ecba..fe2c7c5f543 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -15,6 +15,7 @@ import simplejson import time import urllib import urllib2 +import urlparse import xmlrpclib import zlib from xml.etree import ElementTree @@ -84,6 +85,7 @@ def rjsmin(script): return result def db_list(req): + return ['v7bis'] proxy = req.session.proxy("db") dbs = proxy.list() h = req.httprequest.environ['HTTP_HOST'].split(':')[0] @@ -535,9 +537,17 @@ class Home(openerpweb.Controller): @openerpweb.httprequest def index(self, req, s_action=None, db=None, **kw): + dbl = db_list(req) if not db: - # TODO: maybe redirect to ?db=xxx instead of implicit db set ?? - db = req.httprequest.cookies.get('last_db_login_success') + first = dbl[0] if dbl else None + db = req.httprequest.cookies.get('last_used_database') or first + if db not in dbl: + db = None + if db and req.params.get('db') is not db and len(dbl) > 1: + query = dict(urlparse.parse_qsl(req.httprequest.query_string, keep_blank_values=True)) + query.update({ 'db': db }) + return werkzeug.utils.redirect('?' + urllib.urlencode(query), 303) + js = "\n ".join('' % i for i in manifest_list(req, 'js', db=db)) css = "\n ".join('' % i for i in manifest_list(req, 'css', db=db)) From cb9c598ca4a66a7efb4df9cc6a6d7b4b8f1cd9c3 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 28 Feb 2013 17:17:57 +0100 Subject: [PATCH 03/19] [FIX] correctly set cookie for last used database bzr revid: fme@openerp.com-20130228161757-le1halu03kesu3fa --- addons/web/static/src/js/chrome.js | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index a207d37dd41..4226463b90d 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -622,6 +622,7 @@ instance.web.Login = instance.web.Widget.extend({ self.on('change:database_selector', this, function() { var params = $.deparam.querystring(); params.db = self.get('database_selector'); + self.remember_last_used_database(params.db); self.$('.oe_login_dbpane').empty().text(_t('Loading...')); window.location = '/?' + $.param(params); }); @@ -639,18 +640,26 @@ instance.web.Login = instance.web.Widget.extend({ if (self.params.db && self.params.login && self.params.password) { d = self.do_login(self.params.db, self.params.login, self.params.password); } else { - // TODO: removing following code breaks portal anonymous - //if (self.params.db) { - // self.on_db_loaded([self.params.db]) - //} else { - d = self.rpc("/web/database/get_list", {}).done(self.on_db_loaded).fail(self.on_db_failed); - //} + d = self.rpc("/web/database/get_list", {}).done(self.on_db_loaded).fail(self.on_db_failed); } return d; }, + remember_last_used_database: function(db) { + // This cookie will be used server side in order to avoid db reloading on first visit + var ttl = 24 * 60 * 60 * 365; + document.cookie = [ + 'last_used_database=' + db, + 'path=/', + 'max-age=' + ttl, + 'expires=' + new Date(new Date().getTime() + ttl * 1000).toGMTString() + ].join(';'); + }, on_db_loaded: function (result) { var self = this; this.db_list = result; + if (!this.selected_db) { + this.selected_db = result[0]; + } this.$("[name=db]").replaceWith(QWeb.render('Login.dblist', { db_list: this.db_list, selected_db: this.selected_db})); this.$('select[name=db]').on('change', function(ev) { self.set('database_selector', $(this).val()); @@ -694,15 +703,7 @@ instance.web.Login = instance.web.Widget.extend({ self.hide_error(); self.$(".oe_login_pane").fadeOut("slow"); return this.session.session_authenticate(db, login, password).then(function() { - // This cookie will be used server side in order to avoid db reloading on next visit - var ttl = 24 * 60 * 60 * 365; - document.cookie = [ - 'last_db_login_success=' + db, - 'path=/', - 'max-age=' + ttl, - 'expires=' + new Date(new Date().getTime() + ttl * 1000).toGMTString() - ].join(';'); - + self.remember_last_used_database(db); if (self.has_local_storage) { if(self.remember_credentials) { localStorage.setItem('last_db_login_success', db); From 686e919b8dd3074d355af7fc3cb3e05e93a3e21c Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 28 Feb 2013 17:19:01 +0100 Subject: [PATCH 04/19] [FIX] Also check dbname in session_is_valid() bzr revid: fme@openerp.com-20130228161901-8ff2t1km24t1im3b --- addons/web/static/src/js/coresetup.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 43d292b66db..dedb4a49710 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -89,6 +89,10 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess }); }, session_is_valid: function() { + var db = $.deparam.querystring().db; + if (db && this.db !== db) { + return false; + } return !!this.uid; }, /** From 02d4ab6597664c76c20e93ba62a43082479455f4 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 28 Feb 2013 18:34:44 +0100 Subject: [PATCH 05/19] [FIX] Make credential autocomplete per database bzr revid: fme@openerp.com-20130228173444-th4grlsz70lewf9h --- addons/web/controllers/main.py | 1 - addons/web/static/src/js/chrome.js | 29 ++++++++++------------------- addons/web/static/src/xml/base.xml | 4 ++-- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index fe2c7c5f543..6eb5d89d567 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -85,7 +85,6 @@ def rjsmin(script): return result def db_list(req): - return ['v7bis'] proxy = req.session.proxy("db") dbs = proxy.list() h = req.httprequest.environ['HTTP_HOST'].split(':')[0] diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 4226463b90d..1bf6299816b 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -604,14 +604,6 @@ instance.web.Login = instance.web.Widget.extend({ if (this.params.login_successful) { this.on('login_successful', this, this.params.login_successful); } - - if (this.has_local_storage && this.remember_credentials) { - this.selected_db = localStorage.getItem('last_db_login_success'); - this.selected_login = localStorage.getItem('last_login_login_success'); - if (jQuery.deparam(jQuery.param.querystring()).debug !== undefined) { - this.selected_password = localStorage.getItem('last_password_login_success'); - } - } }, start: function() { var self = this; @@ -671,6 +663,12 @@ instance.web.Login = instance.web.Widget.extend({ } else { this.$('div.oe_login_dbpane').show(); } + if (this.has_local_storage && this.remember_credentials) { + this.$("[name=login]").val(localStorage.getItem(this.selected_db + '|last_login') || ''); + if (this.session.debug) { + this.$("[name=password]").val(localStorage.getItem(this.selected_db + '|last_password') || ''); + } + } }, on_db_failed: function (error, event) { if (error.data.fault_code === 'AccessDenied') { @@ -704,17 +702,10 @@ instance.web.Login = instance.web.Widget.extend({ self.$(".oe_login_pane").fadeOut("slow"); return this.session.session_authenticate(db, login, password).then(function() { self.remember_last_used_database(db); - if (self.has_local_storage) { - if(self.remember_credentials) { - localStorage.setItem('last_db_login_success', db); - localStorage.setItem('last_login_login_success', login); - if (jQuery.deparam(jQuery.param.querystring()).debug !== undefined) { - localStorage.setItem('last_password_login_success', password); - } - } else { - localStorage.setItem('last_db_login_success', ''); - localStorage.setItem('last_login_login_success', ''); - localStorage.setItem('last_password_login_success', ''); + if (self.has_local_storage && self.remember_credentials) { + localStorage.setItem(db + '|last_login', login); + if (self.session.debug) { + localStorage.setItem(db + '|last_password', password); } } self.trigger('login_successful'); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index bf2542b2052..090eaa0cd62 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -71,9 +71,9 @@
  • Username
  • -
  • +
  • Password
  • -
  • +
From fc74aaf7602aaa2182112b6e61e492659c1d45c8 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 5 Mar 2013 10:24:26 +0100 Subject: [PATCH 06/19] [FIX] Fixed for --no-database-list option bzr revid: fme@openerp.com-20130305092426-48h757qc62taugpl --- addons/web/controllers/main.py | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 6eb5d89d567..885871654d5 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -94,15 +94,25 @@ def db_list(req): return dbs def db_monodb(req): - # if only one db exists, return it else return False try: dbs = db_list(req) - if len(dbs) == 1: - return dbs[0] except xmlrpclib.Fault: # ignore access denied - pass - return False + dbs = [] + + db = db_url = req.params.get('db') or False + if not db: + first_db = dbs[0] if dbs else False + db = req.httprequest.cookies.get('last_used_database') or first_db + if db not in dbs: + db = False + + redirect = False + if db and db_url is not db and len(dbs) > 1: + query = dict(urlparse.parse_qsl(req.httprequest.query_string, keep_blank_values=True)) + query.update({ 'db': db }) + redirect = req.httprequest.path + '?' + urllib.urlencode(query) + return [db, dbs, redirect] def module_topological_sort(modules): """ Return a list of module names sorted so that their dependencies of the @@ -197,7 +207,7 @@ def module_boot(req, db=None): for i in server_wide_modules: if i in openerpweb.addons_manifest: serverside.append(i) - monodb = db or db_monodb(req) + monodb = db or db_monodb(req)[0] if monodb: dbside = module_installed_bypass_session(monodb) dbside = [i for i in dbside if i not in serverside] @@ -536,16 +546,9 @@ class Home(openerpweb.Controller): @openerpweb.httprequest def index(self, req, s_action=None, db=None, **kw): - dbl = db_list(req) - if not db: - first = dbl[0] if dbl else None - db = req.httprequest.cookies.get('last_used_database') or first - if db not in dbl: - db = None - if db and req.params.get('db') is not db and len(dbl) > 1: - query = dict(urlparse.parse_qsl(req.httprequest.query_string, keep_blank_values=True)) - query.update({ 'db': db }) - return werkzeug.utils.redirect('?' + urllib.urlencode(query), 303) + db, dbs, redir = db_monodb(req) + if redir: + return werkzeug.utils.redirect(redir, 303) js = "\n ".join('' % i for i in manifest_list(req, 'js', db=db)) css = "\n ".join('' % i for i in manifest_list(req, 'css', db=db)) @@ -1331,7 +1334,7 @@ class Binary(openerpweb.Controller): dbname = req.session._db uid = req.session._uid elif dbname is None: - dbname = db_monodb(req) + dbname = db_monodb(req)[0] if uid is None: uid = openerp.SUPERUSER_ID From de658646e091153f97aaafc3e845d7bf69f7444b Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 5 Mar 2013 11:40:54 +0100 Subject: [PATCH 07/19] [FIX] Correctly handle --no-database-list bzr revid: fme@openerp.com-20130305104054-s0r4g02954fd8qmw --- addons/web/static/src/js/chrome.js | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 1bf6299816b..a14153fc8f5 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -589,6 +589,11 @@ instance.web.client_actions.add("database_manager", "instance.web.DatabaseManage instance.web.Login = instance.web.Widget.extend({ template: "Login", remember_credentials: true, + events: { + 'change input[name=db],select[name=db]': function(ev) { + this.set('database_selector', $(ev.currentTarget).val()); + }, + }, init: function(parent, action) { this._super(parent); @@ -600,6 +605,12 @@ instance.web.Login = instance.web.Widget.extend({ if (_.isEmpty(this.params)) { this.params = $.bbq.getState(true); } + if ($.deparam.querystring().db) { + this.params.db = $.deparam.querystring().db; + } + if (this.params.db) { + this.selected_db = this.params.db; + } if (this.params.login_successful) { this.on('login_successful', this, this.params.login_successful); @@ -612,19 +623,9 @@ instance.web.Login = instance.web.Widget.extend({ self.do_action("database_manager"); }); self.on('change:database_selector', this, function() { - var params = $.deparam.querystring(); - params.db = self.get('database_selector'); - self.remember_last_used_database(params.db); - self.$('.oe_login_dbpane').empty().text(_t('Loading...')); - window.location = '/?' + $.param(params); + this.database_selected(this.get('database_selector')); }); var d = $.when(); - if ($.deparam.querystring().db) { - self.params.db = $.deparam.querystring().db; - } - if (self.params.db) { - self.selected_db = self.params.db; - } if ($.param.fragment().token) { self.params.token = $.param.fragment().token; } @@ -646,6 +647,13 @@ instance.web.Login = instance.web.Widget.extend({ 'expires=' + new Date(new Date().getTime() + ttl * 1000).toGMTString() ].join(';'); }, + database_selected: function(db) { + var params = $.deparam.querystring(); + params.db = db; + this.remember_last_used_database(db); + this.$('.oe_login_dbpane').empty().text(_t('Loading...')); + window.location = '/?' + $.param(params); + }, on_db_loaded: function (result) { var self = this; this.db_list = result; @@ -653,9 +661,6 @@ instance.web.Login = instance.web.Widget.extend({ this.selected_db = result[0]; } this.$("[name=db]").replaceWith(QWeb.render('Login.dblist', { db_list: this.db_list, selected_db: this.selected_db})); - this.$('select[name=db]').on('change', function(ev) { - self.set('database_selector', $(this).val()); - }); if(this.db_list.length === 0) { this.do_action("database_manager"); } else if(this.db_list.length === 1) { From 96ddbcd2c7bc0d94c0e20848c0df070067a2c0b9 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 5 Mar 2013 11:51:12 +0100 Subject: [PATCH 08/19] [FIX] Make 'remember credential' option work with --no-database-list bzr revid: fme@openerp.com-20130305105112-6d5q0qyxw1p2k9d6 --- addons/web/static/src/js/chrome.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index a14153fc8f5..91adfad9ebd 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -633,7 +633,17 @@ instance.web.Login = instance.web.Widget.extend({ if (self.params.db && self.params.login && self.params.password) { d = self.do_login(self.params.db, self.params.login, self.params.password); } else { - d = self.rpc("/web/database/get_list", {}).done(self.on_db_loaded).fail(self.on_db_failed); + d = self.rpc("/web/database/get_list", {}) + .done(self.on_db_loaded) + .fail(self.on_db_failed) + .always(function() { + if (self.selected_db && self.has_local_storage && self.remember_credentials) { + self.$("[name=login]").val(localStorage.getItem(self.selected_db + '|last_login') || ''); + if (self.session.debug) { + self.$("[name=password]").val(localStorage.getItem(self.selected_db + '|last_password') || ''); + } + } + }); } return d; }, @@ -652,6 +662,7 @@ instance.web.Login = instance.web.Widget.extend({ params.db = db; this.remember_last_used_database(db); this.$('.oe_login_dbpane').empty().text(_t('Loading...')); + this.$('[name=login], [name=password]').prop('readonly', true); window.location = '/?' + $.param(params); }, on_db_loaded: function (result) { @@ -668,12 +679,6 @@ instance.web.Login = instance.web.Widget.extend({ } else { this.$('div.oe_login_dbpane').show(); } - if (this.has_local_storage && this.remember_credentials) { - this.$("[name=login]").val(localStorage.getItem(this.selected_db + '|last_login') || ''); - if (this.session.debug) { - this.$("[name=password]").val(localStorage.getItem(this.selected_db + '|last_password') || ''); - } - } }, on_db_failed: function (error, event) { if (error.data.fault_code === 'AccessDenied') { From 44f8d5f1a0df7371eb94375e95a5d2cd4085b49b Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 5 Mar 2013 12:09:47 +0100 Subject: [PATCH 09/19] [IMP] Use instance.web.redirect bzr revid: fme@openerp.com-20130305110947-ztgb4cbyjso5r4so --- addons/web/static/src/js/chrome.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 91adfad9ebd..420cedd81e4 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -663,7 +663,7 @@ instance.web.Login = instance.web.Widget.extend({ this.remember_last_used_database(db); this.$('.oe_login_dbpane').empty().text(_t('Loading...')); this.$('[name=login], [name=password]').prop('readonly', true); - window.location = '/?' + $.param(params); + instance.web.redirect('/?' + $.param(params)); }, on_db_loaded: function (result) { var self = this; From 1a00c2953882ced789f396076999e86e7b5e66c9 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 5 Mar 2013 12:17:03 +0100 Subject: [PATCH 10/19] [FIX] unbreak api bzr revid: fme@openerp.com-20130305111703-5l6iw2s970j76f43 --- addons/web/controllers/main.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 885871654d5..2ac6fbca98e 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -94,6 +94,17 @@ def db_list(req): return dbs def db_monodb(req): + # if only one db exists, return it else return False + try: + dbs = db_list(req) + if len(dbs) == 1: + return dbs[0] + except xmlrpclib.Fault: + # ignore access denied + pass + return False + +def db_monodb_list(req): try: dbs = db_list(req) except xmlrpclib.Fault: @@ -207,7 +218,7 @@ def module_boot(req, db=None): for i in server_wide_modules: if i in openerpweb.addons_manifest: serverside.append(i) - monodb = db or db_monodb(req)[0] + monodb = db or db_monodb(req) if monodb: dbside = module_installed_bypass_session(monodb) dbside = [i for i in dbside if i not in serverside] @@ -546,7 +557,7 @@ class Home(openerpweb.Controller): @openerpweb.httprequest def index(self, req, s_action=None, db=None, **kw): - db, dbs, redir = db_monodb(req) + db, dbs, redir = db_monodb_list(req) if redir: return werkzeug.utils.redirect(redir, 303) @@ -1334,7 +1345,7 @@ class Binary(openerpweb.Controller): dbname = req.session._db uid = req.session._uid elif dbname is None: - dbname = db_monodb(req)[0] + dbname = db_monodb(req) if uid is None: uid = openerp.SUPERUSER_ID From 0f03ed38f0e259e5e13c19a543ec6380364bb9da Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 5 Mar 2013 12:19:32 +0100 Subject: [PATCH 11/19] [IMP] forgot a change in previous commit bzr revid: fme@openerp.com-20130305111932-lytw8pax3bjihg9d --- addons/web/controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 2ac6fbca98e..71294d66ac6 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -123,7 +123,7 @@ def db_monodb_list(req): query = dict(urlparse.parse_qsl(req.httprequest.query_string, keep_blank_values=True)) query.update({ 'db': db }) redirect = req.httprequest.path + '?' + urllib.urlencode(query) - return [db, dbs, redirect] + return (db, dbs, redirect) def module_topological_sort(modules): """ Return a list of module names sorted so that their dependencies of the From 7b154aa8e02f8b46f119319c36e04a693057775c Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 5 Mar 2013 17:51:44 +0100 Subject: [PATCH 12/19] [REM] Removed database check, this is not the role of the controller to reject a bad database name bzr revid: fme@openerp.com-20130305165144-1nzgf3urk4ke20ty --- addons/web/controllers/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 71294d66ac6..1b28b3f8503 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -115,8 +115,6 @@ def db_monodb_list(req): if not db: first_db = dbs[0] if dbs else False db = req.httprequest.cookies.get('last_used_database') or first_db - if db not in dbs: - db = False redirect = False if db and db_url is not db and len(dbs) > 1: From b5b625932abd6d546f1a498826c210c72c7d86d9 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Tue, 5 Mar 2013 22:14:33 +0100 Subject: [PATCH 13/19] db_monodb use the new implementation bzr revid: al@openerp.com-20130305211433-cz7jopkmehxbbbsh --- addons/web/controllers/main.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 1b28b3f8503..e51deacd57b 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -93,17 +93,6 @@ def db_list(req): dbs = [i for i in dbs if re.match(r, i)] return dbs -def db_monodb(req): - # if only one db exists, return it else return False - try: - dbs = db_list(req) - if len(dbs) == 1: - return dbs[0] - except xmlrpclib.Fault: - # ignore access denied - pass - return False - def db_monodb_list(req): try: dbs = db_list(req) @@ -117,12 +106,16 @@ def db_monodb_list(req): db = req.httprequest.cookies.get('last_used_database') or first_db redirect = False - if db and db_url is not db and len(dbs) > 1: + if db and db_url != db and len(dbs) > 1: query = dict(urlparse.parse_qsl(req.httprequest.query_string, keep_blank_values=True)) query.update({ 'db': db }) redirect = req.httprequest.path + '?' + urllib.urlencode(query) return (db, dbs, redirect) +def db_monodb(req): + # if only one db exists, return it else return False + return db_monodb_list(req)[0] + def module_topological_sort(modules): """ Return a list of module names sorted so that their dependencies of the modules are listed before the module itself From 88e0e2933c0e445d082eb8caaac623498562abc3 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Wed, 6 Mar 2013 01:57:55 +0100 Subject: [PATCH 14/19] db_monodb better version and naming bzr revid: al@openerp.com-20130306005755-bgyl65f03st6mn6x --- addons/web/controllers/main.py | 36 ++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index e51deacd57b..876f8c8a26d 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -93,28 +93,40 @@ def db_list(req): dbs = [i for i in dbs if re.match(r, i)] return dbs -def db_monodb_list(req): +def db_monodb_redirect(req): + db = False + redirect = False + + # 1 try the db in the url + db_url = req.params.get('db') + if db_url: + return (db_url, False) + try: dbs = db_list(req) except xmlrpclib.Fault: # ignore access denied dbs = [] - db = db_url = req.params.get('db') or False - if not db: - first_db = dbs[0] if dbs else False - db = req.httprequest.cookies.get('last_used_database') or first_db + # 2 use the database from the cookie if it's listable and still listed + cookie_db = req.httprequest.cookies.get('last_used_database') + if cookie_db in dbs: + db = cookie_db - redirect = False - if db and db_url != db and len(dbs) > 1: + # 3 use the first db + if dbs: + db = dbs[0] + + # redirect to the chosen db if multiple are available + if db and len(dbs) > 1: query = dict(urlparse.parse_qsl(req.httprequest.query_string, keep_blank_values=True)) query.update({ 'db': db }) redirect = req.httprequest.path + '?' + urllib.urlencode(query) - return (db, dbs, redirect) + return (db, redirect) def db_monodb(req): # if only one db exists, return it else return False - return db_monodb_list(req)[0] + return db_monodb_redirect(req)[0] def module_topological_sort(modules): """ Return a list of module names sorted so that their dependencies of the @@ -305,6 +317,10 @@ def manifest_glob(req, extension, addons=None, db=None): return r def manifest_list(req, extension, mods=None, db=None): + """ list ressources to load specifying either: + mods: a comma separated string listing modules + db: a database name (return all installed modules in that database) + """ if not req.debug: path = '/web/webclient/' + extension if mods is not None: @@ -548,7 +564,7 @@ class Home(openerpweb.Controller): @openerpweb.httprequest def index(self, req, s_action=None, db=None, **kw): - db, dbs, redir = db_monodb_list(req) + db, redir = db_monodb_redirect(req) if redir: return werkzeug.utils.redirect(redir, 303) From 28aa304d44368d666a64dcce4e032c48211e46ee Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 6 Mar 2013 09:59:36 +0100 Subject: [PATCH 15/19] [FIX] db_monodb: cookie not used. keep same behavior as previous bzr revid: fme@openerp.com-20130306085936-3mcyorwtgbb0uk0u --- addons/web/controllers/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 876f8c8a26d..bc859f10687 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -109,12 +109,10 @@ def db_monodb_redirect(req): dbs = [] # 2 use the database from the cookie if it's listable and still listed - cookie_db = req.httprequest.cookies.get('last_used_database') - if cookie_db in dbs: - db = cookie_db + db = req.httprequest.cookies.get('last_used_database') or False # 3 use the first db - if dbs: + if dbs and not db: db = dbs[0] # redirect to the chosen db if multiple are available From c41aa09d92796e7e84e0fd892c7bb532af58e683 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 6 Mar 2013 16:21:29 +0100 Subject: [PATCH 16/19] [FIX] Restore cookie_db check bzr revid: fme@openerp.com-20130306152129-945co8a1gljz95eu --- addons/web/controllers/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index bc859f10687..b324e5a18cf 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -109,7 +109,9 @@ def db_monodb_redirect(req): dbs = [] # 2 use the database from the cookie if it's listable and still listed - db = req.httprequest.cookies.get('last_used_database') or False + cookie_db = req.httprequest.cookies.get('last_used_database') + if cookie_db in dbs: + db = cookie_db # 3 use the first db if dbs and not db: From 9223cd6e333ae901370324954509e9b0b78c6536 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 7 Mar 2013 10:59:23 +0100 Subject: [PATCH 17/19] [FIX] Add redirect helper for IE<10 (looses hash on redirects) bzr revid: fme@openerp.com-20130307095923-nh1s5uvzl68455cg --- addons/web/controllers/main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index b324e5a18cf..13ee32e66b5 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -128,6 +128,16 @@ def db_monodb(req): # if only one db exists, return it else return False return db_monodb_redirect(req)[0] +def redirect_with_hash(req, url, code=303): + if req.httprequest.user_agent.browser == 'msie': + try: + version = float(req.httprequest.user_agent.version) + if version < 10: + return "" % url + except Exception: + pass + return werkzeug.utils.redirect(url, code) + def module_topological_sort(modules): """ Return a list of module names sorted so that their dependencies of the modules are listed before the module itself @@ -566,7 +576,7 @@ class Home(openerpweb.Controller): def index(self, req, s_action=None, db=None, **kw): db, redir = db_monodb_redirect(req) if redir: - return werkzeug.utils.redirect(redir, 303) + return redirect_with_hash(req, redir) js = "\n ".join('' % i for i in manifest_list(req, 'js', db=db)) css = "\n ".join('' % i for i in manifest_list(req, 'css', db=db)) From 369137c7a3a9261d52b3c9055e2458300ce185ae Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 7 Mar 2013 15:48:15 +0100 Subject: [PATCH 18/19] [FIX] Use new db parameter after database creation's reload bzr revid: fme@openerp.com-20130307144815-3v2ocglf6p83gyvo --- addons/web/static/src/js/chrome.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 420cedd81e4..7f38f7ebdf4 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -478,7 +478,16 @@ instance.web.DatabaseManager = instance.web.Widget.extend({ 'login': 'admin', 'password': form_obj['create_admin_pwd'], 'login_successful': function() { - self.do_action("reload"); + var action = { + type: "ir.actions.client", + tag: 'reload', + params: { + url_search : { + db: form_obj['db_name'], + }, + } + }; + self.do_action(action); }, }, _push_me: false, @@ -605,7 +614,9 @@ instance.web.Login = instance.web.Widget.extend({ if (_.isEmpty(this.params)) { this.params = $.bbq.getState(true); } - if ($.deparam.querystring().db) { + if (action && action.params && action.params.db) { + this.params.db = action.params.db; + } else if ($.deparam.querystring().db) { this.params.db = $.deparam.querystring().db; } if (this.params.db) { @@ -772,7 +783,9 @@ instance.web.Reload = function(parent, action) { var l = window.location; var sobj = $.deparam(l.search.substr(1)); - sobj.ts = new Date().getTime(); + if (params.url_search) { + sobj = _.extend(sobj, params.url_search); + } var search = '?' + $.param(sobj); var hash = l.hash; From b18bca920b405b59f6189d1b1321e550bef1828b Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 7 Mar 2013 18:36:12 +0100 Subject: [PATCH 19/19] [ADD] Restore timestamp in Reload bzr revid: fme@openerp.com-20130307173612-nso4w37o9ejtu7w4 --- addons/web/static/src/js/chrome.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 7f38f7ebdf4..258b3f5887d 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -783,6 +783,7 @@ instance.web.Reload = function(parent, action) { var l = window.location; var sobj = $.deparam(l.search.substr(1)); + sobj.ts = new Date().getTime(); if (params.url_search) { sobj = _.extend(sobj, params.url_search); }