From 9fe7c94c06f49740bb0dc0536b74c4599fcffcfe Mon Sep 17 00:00:00 2001 From: flvr-odoo Date: Wed, 1 Mar 2023 08:25:14 +0000 Subject: [PATCH] [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) --- addons/mail/models/mail_render_mixin.py | 9 ++++----- odoo/addons/base/i18n/base.pot | 7 +++++++ odoo/models.py | 8 ++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/addons/mail/models/mail_render_mixin.py b/addons/mail/models/mail_render_mixin.py index d281d78e529..2132b06ba15 100644 --- a/addons/mail/models/mail_render_mixin.py +++ b/addons/mail/models/mail_render_mixin.py @@ -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 # ------------------------------------------------------------ diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index c77bb02df1b..3eb54b095bc 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -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 diff --git a/odoo/models.py b/odoo/models.py index 7b119b6f996..009beb6c1bd 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -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: