From b129a3d47f9ea675feab2dabea9b6b997739c3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 4 Dec 2008 18:09:58 +0100 Subject: [PATCH] Add get_groups with cache on res.user for workflow check of groups --- trytond/res/group.py | 2 ++ trytond/res/user.py | 17 +++++++++++++++++ trytond/wkf_service/wkf_expr.py | 3 +-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/trytond/res/group.py b/trytond/res/group.py index 706dd63d7b..31b379b0b3 100644 --- a/trytond/res/group.py +++ b/trytond/res/group.py @@ -27,6 +27,8 @@ class Group(OSV): context=context) # Restart the cache on the domain_get method self.pool.get('ir.rule').domain_get(cursor.dbname) + # Restart the cache for get_groups + self.pool.get('res.user').get_groups(cursor.dbname) return res Group() diff --git a/trytond/res/user.py b/trytond/res/user.py index b499e2d389..06e90fe4db 100644 --- a/trytond/res/user.py +++ b/trytond/res/user.py @@ -5,6 +5,7 @@ import copy from trytond.osv import fields, OSV from trytond.wizard import Wizard, WizardOSV from lxml import etree +from trytond.tools import Cache class User(OSV): @@ -122,6 +123,8 @@ class User(OSV): res = super(User, self).write(cursor, user, ids, vals, context=context) # Restart the cache for domain_get method self.pool.get('ir.rule').domain_get(cursor.dbname) + # Restart the cache for get_groups + self.get_groups(cursor.dbname) return res def delete(self, cursor, user, ids, context=None): @@ -266,6 +269,20 @@ class User(OSV): res = [] return res + def get_groups(self, cursor, user, context=None): + ''' + Return a list of group ids for the user + + :param cursor: the database cursor + :param user: the user id + :param context: the context + :return: a list of group ids + ''' + return self.read(cursor, user, user, ['groups'], + context=context)['groups'] + + get_groups = Cache('res_user.get_groups')(get_groups) + User() diff --git a/trytond/wkf_service/wkf_expr.py b/trytond/wkf_service/wkf_expr.py index 0fba6cc73a..1cc2e83eff 100644 --- a/trytond/wkf_service/wkf_expr.py +++ b/trytond/wkf_service/wkf_expr.py @@ -71,8 +71,7 @@ def check(cursor, ident, transition, signal, context=None): user = ident[0] if transition['group'] and user != 0: user_obj = pooler.get_pool(cursor.dbname).get('res.user') - user_groups = user_obj.read(cursor, user, user, ['groups'], - context=context)['groups'] + user_groups = user_obj.get_groups(cursor, user, context=context) res = res and transition['group'] in user_groups res = res and eval_expr(cursor, ident, transition['condition'], context=context)