[FIX] http: Implicit session deactivation -> Explicit destruction
- Replace the implicit session deactivation with explicit destruction.
This commit is contained in:
@@ -14,6 +14,7 @@ from odoo.exceptions import AccessDenied, AccessError, UserError, ValidationErro
|
||||
from odoo.osv import expression
|
||||
from odoo.service.db import check_super
|
||||
from odoo.tools import partition
|
||||
from odoo.http import root
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -373,6 +374,8 @@ class Users(models.Model):
|
||||
if any(key.startswith('context_') or key in ('lang', 'tz') for key in values):
|
||||
self.context_get.clear_cache(self)
|
||||
if any(key in values for key in ['active'] + USER_PRIVATE_FIELDS):
|
||||
# force deletion of all sessions for these users
|
||||
root.session_store.delete_sessions_for_uids(self.ids)
|
||||
db = self._cr.dbname
|
||||
for id in self.ids:
|
||||
self.__uid_cache[db].pop(id, None)
|
||||
@@ -386,7 +389,10 @@ class Users(models.Model):
|
||||
db = self._cr.dbname
|
||||
for id in self.ids:
|
||||
self.__uid_cache[db].pop(id, None)
|
||||
return super(Users, self).unlink()
|
||||
res = super(Users, self).unlink()
|
||||
# force deletion of all sessions for these users
|
||||
root.session_store.delete_sessions_for_uids(self.ids)
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||||
|
||||
+12
-4
@@ -1035,7 +1035,6 @@ class OpenERPSession(werkzeug.contrib.sessions.Session):
|
||||
self.db = db
|
||||
self.uid = uid
|
||||
self.login = login
|
||||
self.password = password
|
||||
request.uid = uid
|
||||
request.disable_db = False
|
||||
|
||||
@@ -1050,7 +1049,6 @@ class OpenERPSession(werkzeug.contrib.sessions.Session):
|
||||
"""
|
||||
if not self.db or not self.uid:
|
||||
raise SessionExpiredException("Session expired")
|
||||
security.check(self.db, self.uid, self.password)
|
||||
|
||||
def logout(self, keep_db=False):
|
||||
for k in self.keys():
|
||||
@@ -1063,7 +1061,6 @@ class OpenERPSession(werkzeug.contrib.sessions.Session):
|
||||
self.setdefault("db", None)
|
||||
self.setdefault("uid", None)
|
||||
self.setdefault("login", None)
|
||||
self.setdefault("password", None)
|
||||
self.setdefault("context", {})
|
||||
|
||||
def get_context(self):
|
||||
@@ -1276,6 +1273,17 @@ class DisableCacheMiddleware(object):
|
||||
start_response(status, new_headers)
|
||||
return self.app(environ, start_wrapped)
|
||||
|
||||
class OdooSessionStore(werkzeug.contrib.sessions.FilesystemSessionStore):
|
||||
def delete_sessions_for_uids(self, uids):
|
||||
# pretty expensive on large session stores, especially non-local!
|
||||
uids = set(uids)
|
||||
_logger.info('Deleting all HTTP sessions for UIDs %s', uids)
|
||||
for sid in self.list():
|
||||
s = self.get(sid)
|
||||
if s.uid and s.uid in uids:
|
||||
_logger.debug('Deleting session %s', sid)
|
||||
self.delete(s)
|
||||
|
||||
class Root(object):
|
||||
"""Root WSGI application for the OpenERP Web Client.
|
||||
"""
|
||||
@@ -1287,7 +1295,7 @@ class Root(object):
|
||||
# Setup http sessions
|
||||
path = odoo.tools.config.session_dir
|
||||
_logger.debug('HTTP sessions stored in: %s', path)
|
||||
return werkzeug.contrib.sessions.FilesystemSessionStore(path, session_class=OpenERPSession)
|
||||
return OdooSessionStore(path, session_class=OpenERPSession)
|
||||
|
||||
@lazy_property
|
||||
def nodb_routing_map(self):
|
||||
|
||||
Reference in New Issue
Block a user