[MOV] Move ensure_db() helper from

Since we removed auth="admin" in favor of auth="none" with explicit superuser id usage,
the disable_db clause in ir_http#...auth_none() has only sense for /web and /web/login routes.
The web module is an exception because it's routes are registered for the nodb dispatching.
This is why the ensure_db() helper is moved to web client and will take care of the
web's auth="none" routes that needs a db to work with

bzr revid: fme@openerp.com-20140130091820-xezgqezsv2vnmlq1
This commit is contained in:
Fabien Meghazi 2014-01-30 10:18:20 +01:00
parent 07235017aa
commit 469c5d3f1c
1 changed files with 22 additions and 2 deletions

View File

@ -120,6 +120,26 @@ def redirect_with_hash(*args, **kw):
"""
return http.redirect_with_hash(*args, **kw)
def ensure_db(redirect='/web/database/selector'):
db = request.params.get('db')
# if db not provided, use the session one
if not db:
db = request.session.db
# if no database provided and no database in session, use monodb
if not db:
db = db_monodb(request.httprequest)
# if no db can be found til here, send to the database selector
# the database selector will redirect to database manager if needed
if not db:
werkzeug.exceptions.abort(werkzeug.utils.redirect(redirect, 303))
# always switch the session to the computed db
if db != request.session.db:
request.session.logout()
request.session.db = db
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
@ -584,7 +604,7 @@ class Home(http.Controller):
@http.route('/web', type='http', auth="none")
def web_client(self, s_action=None, **kw):
http.ensure_db()
ensure_db()
if request.session.uid:
html = render_bootstrap_template(request.session.db, "web.webclient_bootstrap")
@ -594,7 +614,7 @@ class Home(http.Controller):
@http.route('/web/login', type='http', auth="none")
def web_login(self, redirect=None, **kw):
http.ensure_db(with_registry=True)
ensure_db()
values = request.params.copy()
if not redirect: