[FIX] fields: filter result of 2many related fields with related_sudo
When traversing relational fields as superuser, you end up with a recordset for which only a subset is accessible to the current user. An earlier fix to this issue completely dropped the `related_sudo` feature; change its implementation to keep the feature.
This commit is contained in:
parent
0c2f7bdbc2
commit
233c7780e6
|
@ -1713,12 +1713,15 @@ class _RelationalMulti(_Relational):
|
||||||
|
|
||||||
def _compute_related(self, records):
|
def _compute_related(self, records):
|
||||||
""" Compute the related field ``self`` on ``records``. """
|
""" Compute the related field ``self`` on ``records``. """
|
||||||
for record in records:
|
super(_RelationalMulti, self)._compute_related(records)
|
||||||
value = record
|
if self.related_sudo:
|
||||||
# traverse the intermediate fields, and keep at most one record
|
# determine which records in the relation are actually accessible
|
||||||
for name in self.related[:-1]:
|
target = records.mapped(self.name)
|
||||||
value = value[name][:1]
|
target_ids = set(target.search([('id', 'in', target.ids)]).ids)
|
||||||
record[self.name] = value[self.related[-1]]
|
accessible = lambda target: target.id in target_ids
|
||||||
|
# filter values to keep the accessible records only
|
||||||
|
for record in records:
|
||||||
|
record[self.name] = record[self.name].filtered(accessible)
|
||||||
|
|
||||||
|
|
||||||
class One2many(_RelationalMulti):
|
class One2many(_RelationalMulti):
|
||||||
|
|
Loading…
Reference in New Issue