From ab0d415263cfd62473dcda802a0fd9ef3bd1c2b1 Mon Sep 17 00:00:00 2001 From: Mitul Shah Date: Tue, 14 Dec 2021 06:17:23 +0000 Subject: [PATCH] [IMP] digest: fix tip description Before this Commit, while sending the digest emails, the tip description was incorrect due to sanitizing. Some jinja was also badly converted into inline qweb instead of regular qweb. After this Commit, we have fixed the tip description field value. We do the html_sanitize after rendering the QWEB template. So, we get the proper values of conditions and aliases. Replacing jinja with qweb template, should use to print the dynamic value so, remove the inline_template expression `{{` and `}}` and put the . Task-2704083 closes odoo/odoo#88937 X-original-commit: c08cdc39965df1941b12a98dc80a015673f502e0 Related: odoo/enterprise#26293 Signed-off-by: Thibault Delavallee (tde) --- addons/digest/models/digest.py | 2 +- addons/digest/models/digest_tip.py | 2 +- addons/digest/tests/test_digest.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/addons/digest/models/digest.py b/addons/digest/models/digest.py index 36900546771..4ef250018e8 100644 --- a/addons/digest/models/digest.py +++ b/addons/digest/models/digest.py @@ -259,7 +259,7 @@ class Digest(models.Model): '|', ('group_id', 'in', user.groups_id.ids), ('group_id', '=', False) ], limit=tips_count) tip_descriptions = [ - self.env['mail.render.mixin'].sudo()._render_template(tools.html_sanitize(tip.tip_description), 'digest.tip', tip.ids, post_process=True, engine="qweb")[tip.id] + tools.html_sanitize(self.env['mail.render.mixin'].sudo()._render_template(tip.tip_description, 'digest.tip', tip.ids, post_process=True, engine="qweb")[tip.id]) for tip in tips ] if consumed: diff --git a/addons/digest/models/digest_tip.py b/addons/digest/models/digest_tip.py index c382700f8f5..8c0208db9ad 100644 --- a/addons/digest/models/digest_tip.py +++ b/addons/digest/models/digest_tip.py @@ -16,7 +16,7 @@ class DigestTip(models.Model): user_ids = fields.Many2many( 'res.users', string='Recipients', help='Users having already received this tip') - tip_description = fields.Html('Tip description', translate=html_translate) + tip_description = fields.Html('Tip description', translate=html_translate, sanitize=False) group_id = fields.Many2one( 'res.groups', string='Authorized Group', default=lambda self: self.env.ref('base.group_user')) diff --git a/addons/digest/tests/test_digest.py b/addons/digest/tests/test_digest.py index 196550b1bd1..2fbe72dec77 100644 --- a/addons/digest/tests/test_digest.py +++ b/addons/digest/tests/test_digest.py @@ -142,6 +142,35 @@ class TestDigest(mail_test.MailCommon): self.assertEqual(digest.periodicity, 'quarterly') + @users('admin') + def test_digest_tip_description(self): + self.env["digest.tip"].create({ + 'name': "Test digest tips", + 'tip_description': """ + + +

Record exists.

+
+ +

Record doesn't exist.

+
+ """, + }) + with self.mock_mail_gateway(): + self.test_digest._action_send_to_user(self.user_employee) + self.assertEqual(len(self._new_mails), 1, "A new Email should have been created") + sent_mail_body = html.fromstring(self._new_mails.body_html) + values_to_check = [ + sent_mail_body.xpath('//t[@t-set="record_exists"]'), + sent_mail_body.xpath('//p[@class="rendered"]/text()'), + sent_mail_body.xpath('//p[@class="not-rendered"]/text()') + ] + self.assertEqual( + values_to_check, + [[], ['Record exists.'], []], + "Sent mail should contain properly rendered tip content" + ) + @users('admin') def test_digest_tone_down_wlogs(self): digest = self.env['digest.digest'].browse(self.test_digest.ids)