[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
<t t-out="variable"/> to print the dynamic value so, remove the inline_template
expression `{{` and `}}` and put the <t t-out="variable"/>.

Task-2704083

closes odoo/odoo#88937

X-original-commit: c08cdc39965df1941b12a98dc80a015673f502e0
Related: odoo/enterprise#26293
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Mitul Shah
2022-04-15 21:01:56 +02:00
committed by Thibault Delavallée
parent 85ec1d37c4
commit ab0d415263
3 changed files with 31 additions and 2 deletions
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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'))
+29
View File
@@ -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': """
<t t-set="record_exists" t-value="True" />
<t t-if="record_exists">
<p class="rendered">Record exists.</p>
</t>
<t t-else="">
<p class="not-rendered">Record doesn't exist.</p>
</t>
""",
})
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)