[FIX] mail: check translation

This commit adds a check to prevent saving a translation in a language that was not installed.

Upon adding a translation, the field "language" in the request was not checker,
allowing to add translation for language (or any strings as key) for a given field

This is not ideal and we want to prevent that, it can bloat the database for no reason.

opw-3208305

closes odoo/odoo#114793

X-original-commit: 89cd5ce88a0c666e811410e264e3cb474f9851c0
Signed-off-by: Vranckx Florian (flvr) <flvr@odoo.com>
This commit is contained in:
flvr-odoo
2023-03-09 15:55:10 +01:00
parent 1a0787062d
commit 9fe7c94c06
3 changed files with 19 additions and 5 deletions
+4 -5
View File
@@ -107,12 +107,11 @@ class MailRenderMixin(models.AbstractModel):
def _update_field_translations(self, fname, translations, digest=None):
res = super()._update_field_translations(fname, translations, digest)
# TBD the below check is only for model_term translations.
# Because for model translations, super().update_field_translations will call write to check
if self._unrestricted_rendering:
# If the rendering is unrestricted (e.g. mail.template),
# check the user is part of the mail editor group to modify a template if the template is dynamic
self._check_access_right_dynamic_template()
for lang in translations:
# If the rendering is unrestricted (e.g. mail.template),
# check the user is part of the mail editor group to modify a template if the template is dynamic
self.with_context(lang=lang)._check_access_right_dynamic_template()
return res
# ------------------------------------------------------------
+7
View File
@@ -7359,6 +7359,13 @@ msgstr ""
msgid "Cannot aggregate field %r."
msgstr ""
#. module: base
#. odoo-python
#: code:addons/models.py:0
#, python-format
msgid "The following language is not activated: %(missing_names)s"
msgstr ""
#. module: base
#. odoo-python
#: code:addons/base/models/assetsbundle.py:0
+8
View File
@@ -3041,6 +3041,14 @@ class BaseModel(metaclass=MetaModel):
"""
self.ensure_one()
installed_lang = set(code for code, _ in self.env['res.lang'].get_installed())
missing_languages = set(translations) - installed_lang
if missing_languages:
raise UserError(
_("The following language is not activated: %(missing_names)s",
missing_names=', '.join(missing_languages))
)
field = self._fields[field_name]
if not field.translate: