From f15f706313f86ca76e8f75eed0e70a000a1d4fb9 Mon Sep 17 00:00:00 2001 From: chs <> Date: Tue, 2 Jul 2013 14:24:04 +0200 Subject: [PATCH] [FIX] monodb: correct behaviour in no-db-list mode (manual forward port of 7.0 rev 3991 mat@openerp.com-20130702122014-6l79a748lb946hkq) bzr revid: mat@openerp.com-20130702122404-sngh0g283tuvj8ll --- addons/web/controllers/main.py | 16 ++-------------- addons/web/http.py | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index d82f4a85775..5641d991397 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -89,19 +89,7 @@ def rjsmin(script): db_list = http.db_list def db_monodb_redirect(): - db = db_monodb() - - if request.params.get('db'): - return (db, False) - - dbs = db_list(True) - # redirect to the chosen db if multiple are available - redirect = False - if db and len(dbs) > 1: - query = dict(urlparse.parse_qsl(request.httprequest.query_string, keep_blank_values=True)) - query.update({ 'db': db }) - redirect = request.httprequest.path + '?' + urllib.urlencode(query) - return (db, redirect) + return http.db_redirect(not config['list_db']) db_monodb = http.db_monodb @@ -737,7 +725,7 @@ class Database(http.Controller): try: return db_list() except openerp.exceptions.AccessDenied: - monodb = db_monodb(req) + monodb = db_monodb() if monodb: return [monodb] raise diff --git a/addons/web/http.py b/addons/web/http.py index 7acadc11fbc..8b49e8f9636 100644 --- a/addons/web/http.py +++ b/addons/web/http.py @@ -31,6 +31,7 @@ import werkzeug.utils import werkzeug.wrappers import werkzeug.wsgi import werkzeug.routing as routing +import urllib import urllib2 import openerp @@ -1114,26 +1115,37 @@ def db_list(force=False): dbs = [i for i in dbs if re.match(r, i)] return dbs -def db_monodb(): - db = None +def db_redirect(match_first_only_if_unique): + req = request + db = False + redirect = False # 1 try the db in the url - db_url = request.params.get('db') + db_url = req.params.get('db') if db_url: - return db_url + return (db_url, False) - dbs = db_list(True) + dbs = db_list(True) # 2 use the database from the cookie if it's listable and still listed - cookie_db = request.httprequest.cookies.get('last_used_database') + cookie_db = req.httprequest.cookies.get('last_used_database') if cookie_db in dbs: db = cookie_db # 3 use the first db if user can list databases - if dbs and not db and (config['list_db'] or len(dbs) == 1): + if dbs and not db and (not match_first_only_if_unique or len(dbs) == 1): db = dbs[0] - return db + # 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, redirect) + +def db_monodb(): + # if only one db exists, return it else return False + return db_redirect(True)[0] class JsonRpcController(Controller):