[FIX] fields: add a flag "compute_sudo" to recompute fields as user admin
This reverts commit 8cd2cc8910
.
It turned out that forcing recomputing fields as user admin breaks some
existing behavior. Instead, we make the recomputation as user admin explicit
by adding compute_sudo=True in the field's definition.
This commit is contained in:
parent
1553ac99e1
commit
4fd8e40ff7
|
@ -845,8 +845,7 @@ class Environment(object):
|
||||||
def add_todo(self, field, records):
|
def add_todo(self, field, records):
|
||||||
""" Mark `field` to be recomputed on `records`. """
|
""" Mark `field` to be recomputed on `records`. """
|
||||||
recs_list = self.all.todo.setdefault(field, [])
|
recs_list = self.all.todo.setdefault(field, [])
|
||||||
# use user admin for accessing records without access rights issues
|
recs_list.append(records)
|
||||||
recs_list.append(records.sudo())
|
|
||||||
|
|
||||||
def remove_todo(self, field, records):
|
def remove_todo(self, field, records):
|
||||||
""" Mark `field` as recomputed on `records`. """
|
""" Mark `field` as recomputed on `records`. """
|
||||||
|
|
|
@ -146,6 +146,9 @@ class Field(object):
|
||||||
:param store: whether the field is stored in database (boolean, by
|
:param store: whether the field is stored in database (boolean, by
|
||||||
default ``False`` on computed fields)
|
default ``False`` on computed fields)
|
||||||
|
|
||||||
|
:param compute_sudo: whether the field should be recomputed as superuser
|
||||||
|
to bypass access rights (boolean, by default ``False``)
|
||||||
|
|
||||||
The methods given for `compute`, `inverse` and `search` are model
|
The methods given for `compute`, `inverse` and `search` are model
|
||||||
methods. Their signature is shown in the following example::
|
methods. Their signature is shown in the following example::
|
||||||
|
|
||||||
|
@ -271,6 +274,7 @@ class Field(object):
|
||||||
depends = () # collection of field dependencies
|
depends = () # collection of field dependencies
|
||||||
recursive = False # whether self depends on itself
|
recursive = False # whether self depends on itself
|
||||||
compute = None # compute(recs) computes field on recs
|
compute = None # compute(recs) computes field on recs
|
||||||
|
compute_sudo = False # whether field should be recomputed as admin
|
||||||
inverse = None # inverse(recs) inverses field on recs
|
inverse = None # inverse(recs) inverses field on recs
|
||||||
search = None # search(recs, operator, value) searches on self
|
search = None # search(recs, operator, value) searches on self
|
||||||
related = None # sequence of field names, for related fields
|
related = None # sequence of field names, for related fields
|
||||||
|
@ -903,7 +907,13 @@ class Field(object):
|
||||||
target = env[field.model_name].search([(path, 'in', records.ids)])
|
target = env[field.model_name].search([(path, 'in', records.ids)])
|
||||||
if target:
|
if target:
|
||||||
spec.append((field, target._ids))
|
spec.append((field, target._ids))
|
||||||
target.with_env(records.env)._recompute_todo(field)
|
# recompute field on target in the environment of records,
|
||||||
|
# and as user admin if required
|
||||||
|
if field.compute_sudo:
|
||||||
|
target = target.with_env(records.env(user=SUPERUSER_ID))
|
||||||
|
else:
|
||||||
|
target = target.with_env(records.env)
|
||||||
|
target._recompute_todo(field)
|
||||||
else:
|
else:
|
||||||
spec.append((field, None))
|
spec.append((field, None))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue