[FIX] Restore /login redirection on SessionExpired

The feature was broken due to an incompatibility
when forward porting 624f256 and a78e27f
This commit is contained in:
Fabien Meghazi 2014-09-04 16:31:30 +02:00 committed by Olivier Dony
parent fc5c53ca47
commit c981d068ab
3 changed files with 20 additions and 16 deletions

View File

@ -54,10 +54,14 @@ class ir_http(orm.AbstractModel):
request.website_multilang = request.website_enabled and func and func.routing.get('multilang', True)
if request.website_enabled:
if func:
self._authenticate(func.routing['auth'])
else:
self._auth_method_public()
try:
if func:
self._authenticate(func.routing['auth'])
else:
self._auth_method_public()
except Exception as e:
return self._handle_exception(e)
request.redirect = lambda url: werkzeug.utils.redirect(url_for(url))
request.website = request.registry['website'].get_current_website(request.cr, request.uid, context=request.context)
if first_pass:

View File

@ -58,12 +58,6 @@ class ir_http(osv.AbstractModel):
def _auth_method_user(self):
request.uid = request.session.uid
if not request.uid:
if not request.params.get('noredirect'):
query = werkzeug.url_encode({
'redirect': request.httprequest.url,
})
response = werkzeug.utils.redirect('/web/login?%s' % query)
werkzeug.exceptions.abort(response)
raise http.SessionExpiredException("Session expired")
def _auth_method_none(self):
@ -97,7 +91,10 @@ class ir_http(osv.AbstractModel):
def _handle_exception(self, exception):
# If handle_exception returns something different than None, it will be used as a response
return request._handle_exception(exception)
try:
return request._handle_exception(exception)
except openerp.exceptions.AccessDenied:
return werkzeug.exceptions.Forbidden()
def _dispatch(self):
# locate the controller method
@ -110,11 +107,8 @@ class ir_http(osv.AbstractModel):
# check authentication level
try:
auth_method = self._authenticate(func.routing["auth"])
except Exception:
# force a Forbidden exception with the original traceback
return self._handle_exception(
convert_exception_to(
werkzeug.exceptions.Forbidden))
except Exception as e:
return self._handle_exception(e)
processing = self._postprocess_args(arguments, rule)
if processing:

View File

@ -542,6 +542,12 @@ class HttpRequest(WebRequest):
be used as response."""
try:
return super(HttpRequest, self)._handle_exception(exception)
except SessionExpiredException:
if not request.params.get('noredirect'):
query = werkzeug.urls.url_encode({
'redirect': request.httprequest.url,
})
return werkzeug.utils.redirect('/web/login?%s' % query)
except werkzeug.exceptions.HTTPException, e:
return e