[FIX] ir_translation: do not raise access errors on list view
Have a translation linked to a record unreadable because of a record rule (e.g. a product that is not shared between companies). Display the translations list view; if one such translation is in the view, it will raise an access error. When computing the source value, _compute_source will fail to read the record, and raise an access error. This will make it impossible to access untranslated terms. Instead we guard this error. Since it is displayed in the view, we display an informative message. Note that since we make this error go away, we also fix the check method. Only the superuser bypasses the record rules; so if we made the check on write with _is_admin, it means than a user in group_erp_manager cannot read a record but can edit its translations. opw 2000817 closes odoo/odoo#33989 Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
This commit is contained in:
@@ -7234,6 +7234,12 @@ msgstr ""
|
||||
msgid "Cannot aggregate field %r."
|
||||
msgstr ""
|
||||
|
||||
#. module: base
|
||||
#: code:addons/base/models/ir_translation.py:256
|
||||
#, python-format
|
||||
msgid "Cannot be translated; record not accessible."
|
||||
msgstr ""
|
||||
|
||||
#. module: base
|
||||
#: code:addons/base/models/res_lang.py:228
|
||||
#, python-format
|
||||
|
||||
@@ -247,7 +247,13 @@ class IrTranslation(models.Model):
|
||||
continue
|
||||
if not callable(field.translate):
|
||||
# Pass context without lang, need to read real stored field, not translation
|
||||
result = model.browse(record.res_id).with_context(lang=None).read([field_name])
|
||||
try:
|
||||
result = model.browse(record.res_id).with_context(lang=None).read([field_name])
|
||||
except AccessError:
|
||||
# because we can read self but not the record,
|
||||
# that means we would get an access error when accessing the translations
|
||||
# so instead we defer the access right to the "check" method
|
||||
result = [{field_name: _("Cannot be translated; record not accessible.")}]
|
||||
record.source = result[0][field_name] if result else False
|
||||
|
||||
def _inverse_source(self):
|
||||
@@ -539,7 +545,7 @@ class IrTranslation(models.Model):
|
||||
""" Check access rights of operation ``mode`` on ``self`` for the
|
||||
current user. Raise an AccessError in case conditions are not met.
|
||||
"""
|
||||
if self.env.user._is_admin():
|
||||
if self.env.user._is_superuser():
|
||||
return
|
||||
|
||||
# collect translated field records (model_ids) and other translations
|
||||
|
||||
Reference in New Issue
Block a user