From 93fc52c8e1a95b5314b29b0569a1ed25ca3a5d02 Mon Sep 17 00:00:00 2001 From: std-odoo Date: Thu, 23 Jun 2022 07:55:09 +0000 Subject: [PATCH] [FIX] mail: allow a normal user to view the template body Followup of odoo/odoo@1a3e713 Bug === If the user doesn't have the template editor, he cannot open the template preview. Technical ========= The reason for that is because the web editor moves some CSS properties, and so when the user tries to open the preview, an access error is raised. Ideally, the template form view should not be editable if the access rules do not allow it. But in _postprocess_tag_field, we only check for access right because we don't have the record. So a user without write access rules, but having write access right can edit the template in the UI, and gets an error when saving. Also, the web editor should not save the HTML value if no change are made on the field (like all other text / char field). To mitigate the issue in stable, we add a computed field that check the access rules and make the body readonly if he can not edit the template. So the web editor is not loaded, the CSS properties are not moved. Other possible solutions are way to complex technically speaking (editor internals to update in frontend, complex comparison of html blobs in backend, cache usage making fields_view_get override not working in all cases, ... ) As the HTML body look weird in readonly mode, add the same border as the web editor. Task-2845877 X-original-commit: dcf3ab5fb41aa9ef6e59b2155bfd192e551b6476 Part-of: odoo/odoo#99256 --- addons/mail/models/mail_template.py | 10 ++++++++++ addons/mail/static/src/scss/composer.scss | 7 +++++++ addons/mail/views/mail_template_views.xml | 5 ++++- addons/mail/wizard/mail_compose_message_views.xml | 2 +- addons/survey/wizard/survey_invite_views.xml | 2 +- .../wizard/slide_channel_invite_views.xml | 2 +- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index e647dfcf122..ca6500d9b2d 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -69,12 +69,22 @@ class MailTemplate(models.Model): help="Sidebar action to make this template available on records " "of the related document model") + # access + can_write = fields.Boolean(compute='_compute_can_write', + help='The current user can edit the template.') + # Overrides of mail.render.mixin @api.depends('model') def _compute_render_model(self): for template in self: template.render_model = template.model + @api.depends_context('uid') + def _compute_can_write(self): + writable_templates = self._filter_access_rules('write') + for template in self: + template.can_write = template in writable_templates + # ------------------------------------------------------------ # CRUD # ------------------------------------------------------------ diff --git a/addons/mail/static/src/scss/composer.scss b/addons/mail/static/src/scss/composer.scss index 33a61c521ba..a7fc3eb484b 100644 --- a/addons/mail/static/src/scss/composer.scss +++ b/addons/mail/static/src/scss/composer.scss @@ -175,3 +175,10 @@ background-color: rgba($white, 0.1); } } + +.o_mail_composer_form { + .oe-bordered-editor[name=body] .o_readonly { + border: 1px solid $o-gray-300; + padding: 4px; + } +} diff --git a/addons/mail/views/mail_template_views.xml b/addons/mail/views/mail_template_views.xml index ee814dba4d2..664d09697f7 100644 --- a/addons/mail/views/mail_template_views.xml +++ b/addons/mail/views/mail_template_views.xml @@ -53,7 +53,10 @@

- + + diff --git a/addons/mail/wizard/mail_compose_message_views.xml b/addons/mail/wizard/mail_compose_message_views.xml index d785d7a1fb5..9114efd14b9 100644 --- a/addons/mail/wizard/mail_compose_message_views.xml +++ b/addons/mail/wizard/mail_compose_message_views.xml @@ -6,7 +6,7 @@ mail.compose.message -
+ diff --git a/addons/survey/wizard/survey_invite_views.xml b/addons/survey/wizard/survey_invite_views.xml index 834d4181cc9..9da8fdb2322 100644 --- a/addons/survey/wizard/survey_invite_views.xml +++ b/addons/survey/wizard/survey_invite_views.xml @@ -5,7 +5,7 @@ survey.invite.view.form survey.invite - + diff --git a/addons/website_slides/wizard/slide_channel_invite_views.xml b/addons/website_slides/wizard/slide_channel_invite_views.xml index 42a9cd87fd4..35f1a035953 100644 --- a/addons/website_slides/wizard/slide_channel_invite_views.xml +++ b/addons/website_slides/wizard/slide_channel_invite_views.xml @@ -5,7 +5,7 @@ slide.channel.invite.view.form slide.channel.invite - +