From 5ae80f1dccaffc74ea5b751b03367fed75097235 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Thu, 1 Sep 2022 14:44:23 +0000 Subject: [PATCH] [FIX] mass_mailing: render placeholder in mailing web view The placeholders were rendered as empty string in the web version of the mailing (accessed through the "view online" link in the email). This fixes the problem. Technical note: we cannot use mail_mail.body_html (which contains already the rendered placeholder for the specific user) as it is marked for deletion so we render it from mailing_mailing.body_html. Task-2954282 closes odoo/odoo#100984 X-original-commit: 6b2d5db762ef198e9f07af95116c166b027eb383 Signed-off-by: Thibault Delavallee (tde) --- addons/mass_mailing/controllers/main.py | 20 +++++-------------- .../mailing_templates_portal_management.xml | 17 +++++++++++++++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/addons/mass_mailing/controllers/main.py b/addons/mass_mailing/controllers/main.py index 517fa7fa227..5f6a42b11ec 100644 --- a/addons/mass_mailing/controllers/main.py +++ b/addons/mass_mailing/controllers/main.py @@ -167,23 +167,13 @@ class MassMailController(http.Controller): if not self._valid_unsubscribe_token(mailing_id, res_id, email, str(token)) and not request.env.user.has_group('mass_mailing.group_mass_mailing_user'): raise exceptions.AccessDenied() - res = mailing.convert_links() - base_url = mailing.get_base_url().rstrip('/') - urls_to_replace = [ - (base_url + '/unsubscribe_from_list', mailing._get_unsubscribe_url(email, res_id)), - (base_url + '/view', mailing._get_view_url(email, res_id)) - ] - for url_to_replace, new_url in urls_to_replace: - if url_to_replace in res[mailing_id]: - res[mailing_id] = res[mailing_id].replace(url_to_replace, new_url if new_url else '#') - - res[mailing_id] = res[mailing_id].replace( - 'class="o_snippet_view_in_browser"', - 'class="o_snippet_view_in_browser" style="display: none;"' - ) + html_markupsafe = mailing._render_field('body_html', [res_id])[res_id] + # Update generic URLs (without parameters) to final ones + html_markupsafe = html_markupsafe.replace('/unsubscribe_from_list', + mailing._get_unsubscribe_url(email, res_id)) return request.render('mass_mailing.view', { - 'body': res[mailing_id], + 'body': html_markupsafe, }) return request.redirect('/web') diff --git a/addons/mass_mailing/views/mailing_templates_portal_management.xml b/addons/mass_mailing/views/mailing_templates_portal_management.xml index 03dafe2cd6c..43b141f3a8b 100644 --- a/addons/mass_mailing/views/mailing_templates_portal_management.xml +++ b/addons/mass_mailing/views/mailing_templates_portal_management.xml @@ -26,7 +26,22 @@ - \ No newline at end of file +