Add get_groups with cache on res.user for workflow check of groups
This commit is contained in:
1 parent
25b4e9d6c0
commit
b129a3d47f
3 files changed
+20
-2
No files matched your search
@@ -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()
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user