diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 0533487ae83..0f713a8c3b0 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -856,6 +856,9 @@ class orm_template(object): def __view_look_dom_arch(self, cr, user, node, context=None): fields_def = self.__view_look_dom(cr, user, node, context=context) + rolesobj = self.pool.get('res.roles') + usersobj = self.pool.get('res.users') + buttons = xpath.Evaluate('//button', node) if buttons: for button in buttons: @@ -865,13 +868,12 @@ class orm_template(object): ok = True if user != 1: # admin user has all roles - serv = netsvc.LocalService('object_proxy') - user_roles = serv.execute_cr(cr, user, 'res.users', 'read', [user], ['roles_id'])[0]['roles_id'] - cr.execute("select role_id from wkf_transition where signal='%s'" % button.getAttribute('name')) + user_roles = usersobj.read(cr, user, [user], ['roles_id'])[0]['roles_id'] + cr.execute("select role_id from wkf_transition where signal=%s", (button.getAttribute('name'),)) roles = cr.fetchall() for role in roles: if role[0]: - ok = ok and serv.execute_cr(cr, user, 'res.roles', 'check', user_roles, role[0]) + ok = ok and rolesobj.check(cr, user, user_roles, role[0]) if not ok: button.setAttribute('readonly', '1') diff --git a/bin/workflow/wkf_expr.py b/bin/workflow/wkf_expr.py index fff74884e3f..dee4167bf48 100644 --- a/bin/workflow/wkf_expr.py +++ b/bin/workflow/wkf_expr.py @@ -25,22 +25,8 @@ import netsvc import osv as base import pooler - -class EnvCall(object): - - def __init__(self,wf_service,d_arg): - self.wf_service=wf_service - self.d_arg=d_arg - - def __call__(self,*args): - arg=self.d_arg+args - return self.wf_service.execute_cr(*arg) - - class Env(dict): - - def __init__(self, wf_service, cr, uid, model, ids): - self.wf_service = wf_service + def __init__(self, cr, uid, model, ids): self.cr = cr self.uid = uid self.model = model @@ -52,13 +38,6 @@ class Env(dict): if (key in self.columns) or (key in dir(self.obj)): res = self.obj.browse(self.cr, self.uid, self.ids[0]) return res[key] - #res=self.wf_service.execute_cr(self.cr, self.uid, self.model, 'read',\ - # self.ids, [key])[0][key] - #super(Env, self).__setitem__(key, res) - #return res - #elif key in dir(self.obj): - # return EnvCall(self.wf_service, (self.cr, self.uid, self.model, key,\ - # self.ids)) else: return super(Env, self).__getitem__(key) @@ -75,13 +54,11 @@ def _eval_expr(cr, ident, workitem, action): elif line =='False': ret=False else: - wf_service = netsvc.LocalService("object_proxy") - env = Env(wf_service, cr, uid, model, ids) + env = Env(cr, uid, model, ids) ret = eval(line, env) return ret def execute_action(cr, ident, workitem, activity): - wf_service = netsvc.LocalService("object_proxy") obj = pooler.get_pool(cr.dbname).get('ir.actions.server') ctx = {'active_id':ident[2], 'active_ids':[ident[2]]} result = obj.run(cr, ident[0], [activity['action_id']], ctx) @@ -97,9 +74,9 @@ def check(cr, workitem, ident, transition, signal): uid = ident[0] if transition['role_id'] and uid != 1: - serv = netsvc.LocalService('object_proxy') - user_roles = serv.execute_cr(cr, uid, 'res.users', 'read', [uid], ['roles_id'])[0]['roles_id'] - ok = ok and serv.execute_cr(cr, uid, 'res.roles', 'check', user_roles, transition['role_id']) + pool = pooler.get_pool(cr.dbname) + user_roles = pool.get('res.users').read(cr, uid, [uid], ['roles_id'])[0]['roles_id'] + ok = ok and pool.get('res.roles').check(cr, uid, user_roles, transition['role_id']) ok = ok and _eval_expr(cr, ident, workitem, transition['condition']) return ok