[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:
Raphael Collet 2016-04-25 12:13:14 +02:00
parent 0c2f7bdbc2
commit 233c7780e6
1 changed files with 9 additions and 6 deletions

View File

@ -1713,12 +1713,15 @@ class _RelationalMulti(_Relational):
def _compute_related(self, records):
""" Compute the related field ``self`` on ``records``. """
for record in records:
value = record
# traverse the intermediate fields, and keep at most one record
for name in self.related[:-1]:
value = value[name][:1]
record[self.name] = value[self.related[-1]]
super(_RelationalMulti, self)._compute_related(records)
if self.related_sudo:
# determine which records in the relation are actually accessible
target = records.mapped(self.name)
target_ids = set(target.search([('id', 'in', target.ids)]).ids)
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):