diff options
| author | niv-openerp <nicolas.vanhoren@openerp.com> | 2013-08-01 13:31:36 +0200 |
|---|---|---|
| committer | niv-openerp <nicolas.vanhoren@openerp.com> | 2013-08-01 13:31:36 +0200 |
| commit | f3d634a278411f4a4fdcc0d38da31265042e4bc0 (patch) | |
| tree | 5f6dfac53c98fd8cbedcc8836936e356afab9959 /addons/web | |
| parent | adfe3e7ec9c1e98f648a644c5e5d3972e71397b3 (diff) | |
[IMP] http.py: Make it possible to implement a new authentication method for the routes
bzr revid: nicolas.vanhoren@openerp.com-20130801113136-5fg9hyrptjckhtkm
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/http.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/addons/web/http.py b/addons/web/http.py index 687af164e72..c41c32169ad 100644 --- a/addons/web/http.py +++ b/addons/web/http.py @@ -124,17 +124,7 @@ class WebRequest(object): except SessionExpiredException, e: self.session.logout() raise SessionExpiredException("Session expired for request %s" % self.httprequest) - if self.auth_method == "none": - self.disable_db = True - self.uid = None - elif self.auth_method == "admin": - self.disable_db = False - if not self.db: - raise SessionExpiredException("No valid database for request %s" % self.httprequest) - self.uid = openerp.SUPERUSER_ID - else: # auth - self.disable_db = False - self.uid = self.session.uid + auth_methods[self.auth_method]() @property def registry(self): """ @@ -187,6 +177,24 @@ class WebRequest(object): self.disable_db = True self.uid = None +def auth_method_user(): + request.uid = request.session.uid + +def auth_method_admin(): + if not request.db: + raise SessionExpiredException("No valid database for request %s" % request.httprequest) + request.uid = openerp.SUPERUSER_ID + +def auth_method_none(): + request.disable_db = True + request.uid = None + +auth_methods = { + "user": auth_method_user, + "admin": auth_method_admin, + "none": auth_method_none, +} + def route(route, type="http", auth="user"): """ Decorator marking the decorated method as being a handler for requests. The method must be part of a subclass @@ -206,7 +214,7 @@ def route(route, type="http", auth="user"): configuration indicating the current database nor the current user. """ assert type in ["http", "json"] - assert auth in ["user", "admin", "none"] + assert auth in auth_methods.keys() def decorator(f): if isinstance(route, list): f.routes = route |
