diff --git a/trytond/ir/rule.py b/trytond/ir/rule.py index 878fc3e2e9..b673640e20 100644 --- a/trytond/ir/rule.py +++ b/trytond/ir/rule.py @@ -115,7 +115,7 @@ class Rule(OSV): return res - def get_operand(self, cursor, user, context): + def get_operand(self, cursor, user, context=None): res = [] operands = self._operand_get(cursor, user, 'res.user', level=1, recur=['many2one'], root_tech='user', root='User') @@ -123,10 +123,18 @@ class Rule(OSV): res.append((i, i)) return res - def domain_get(self, cursor, user, model_name): + def domain_get(self, cursor, user, model_name, context=None): + if context is None: + context = {} + # root user above constraint if user == 0: - return '', [] + if not context.get('user'): + return '', [] + ctx = context.copy() + del ctx['user'] + return self.domain_get(cursor, context['user'], model_name, + context=ctx) cursor.execute("SELECT r.id FROM ir_rule r " \ "JOIN (ir_rule_group g " \ @@ -151,7 +159,7 @@ class Rule(OSV): clause_global = {} operand2query = self._operand_get(cursor, user, 'res.user', level=1, recur=['many2one'], root_tech='user', root='User') - # Use root user to prevent recursion + # Use root user without context to prevent recursion for rule in self.browse(cursor, 0, ids): dom = eval("[('%s', '%s', %s)]" % \ (rule.field.name, rule.operator, @@ -194,7 +202,7 @@ class Rule(OSV): clause = ['AND', clause_global, clause] query, val, _, _ = obj._where_calc(cursor, user, - clause, active_test=False) + clause, active_test=False, context=context) return query, val diff --git a/trytond/osv/fields.py b/trytond/osv/fields.py index b1afeb1e95..5e72c78376 100644 --- a/trytond/osv/fields.py +++ b/trytond/osv/fields.py @@ -487,7 +487,7 @@ class Many2Many(Column): obj = obj.pool.get(self._obj) domain1, domain2 = obj.pool.get('ir.rule').domain_get(cursor, - user, obj._name) + user, obj._name, context=context) if domain1: domain1 = ' and '+domain1 @@ -564,7 +564,7 @@ class Many2Many(Column): else: ids = list(act[1]) domain1, domain2 = obj.pool.get('ir.rule').domain_get(cursor, - user, obj._name) + user, obj._name, context=context) if domain1: domain1 = ' AND ' + domain1 cursor.execute('DELETE FROM "' + self._rel + '" ' \ diff --git a/trytond/osv/orm.py b/trytond/osv/orm.py index 86c6986c36..722939afe7 100644 --- a/trytond/osv/orm.py +++ b/trytond/osv/orm.py @@ -1034,7 +1034,7 @@ class ORM(object): # construct a clause for the rules : domain1, domain2 = self.pool.get('ir.rule').domain_get(cursor, user, - self._name) + self._name, context=context) # all inherited fields + all non inherited fields # for which the attribute whose name is in load is True @@ -1467,7 +1467,7 @@ class ORM(object): tree_ids[k] = [x[0] for x in cursor.fetchall()] domain1, domain2 = self.pool.get('ir.rule').domain_get(cursor, user, - self._name) + self._name, context=context) if domain1: domain1 = ' AND (' + domain1 + ') ' for i in range(0, len(ids), cursor.IN_MAX): @@ -1635,7 +1635,7 @@ class ORM(object): if len(upd0): domain1, domain2 = self.pool.get('ir.rule').domain_get(cursor, - user, self._name) + user, self._name, context=context) if domain1: domain1 = ' AND (' + domain1 + ') ' for i in range(0, len(ids), cursor.IN_MAX): @@ -2913,7 +2913,7 @@ class ORM(object): # construct a clause for the rules : domain1, domain2 = self.pool.get('ir.rule').domain_get(cursor, user, - self._name) + self._name, context=context) if domain1: if qu1: qu1 += ' AND ' + domain1