Add context to domain_get and use user context for root
This commit is contained in:
1 parent
1c0a70c85c
commit
dab3f3aa8b
3 files changed
+19
-11
No files matched your search
+13
-5
@@ -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
|
||||
|
||||
|
||||
@@ -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 + '" ' \
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
Reference in new issue
Block a user