diff options
| author | Sébastien Mottet (oms) <oms@odoo.com> | 2020-04-20 15:02:30 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-08-05 13:55:04 +0000 |
| commit | ac0579263bc2996321f55cb20da3332f027dbb36 (patch) | |
| tree | 56e47c6bded008e4833c87e52ba5e35a125eb04d /addons/mass_mailing/controllers/main.py | |
| parent | 0809601d6da21fcf00be3ad4b28cbcf350c7d09d (diff) | |
[IMP] mass_mailing: add 'view in browser' link in mailings
PURPOSE
Add a block that allows recipients to check the email in a browser in case
their mail service provider does not render it well or to see it full screen.
SPECIFICATIONS
A thumbnail has been added in the snippet thumbnails list of the mail editor.
It allows to add an header snippet. This snippet contains a link allowing the
recipient to see the mail in its browser instead of its mail client.
Add a route to display a mailing content. This route should be recipient
dependent as mailings could contain jinja markers. Using the same access token
and check as unsubscribe route this public route allows to display a mailing
content directly rendered for a given customer.
_get_unsubscribe_url method is moved from mail_mail to mailing as it does
not really belong to the mail model. Indeed it is mailing dependent.
A view URL leading to the view in browser route is added. It is managed like
the unsubscribe url: magically avoid shortening, magically rewrite when
sending email.
Task ID-2239327
PR #49886
Diffstat (limited to 'addons/mass_mailing/controllers/main.py')
| -rw-r--r-- | addons/mass_mailing/controllers/main.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/addons/mass_mailing/controllers/main.py b/addons/mass_mailing/controllers/main.py index 30653260425..bae258f9bf1 100644 --- a/addons/mass_mailing/controllers/main.py +++ b/addons/mass_mailing/controllers/main.py @@ -105,6 +105,35 @@ class MassMailController(http.Controller): return response + @http.route(['/mailing/<int:mailing_id>/view'], type='http', website=True, auth='public') + def view(self, mailing_id, email=None, res_id=None, token=""): + mailing = request.env['mailing.mailing'].sudo().browse(mailing_id) + if mailing.exists(): + res_id = int(res_id) if res_id else False + 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 = request.env['ir.config_parameter'].sudo().get_param('web.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;"' + ) + + return request.render('mass_mailing.view', { + 'body': res[mailing_id], + }) + + return request.redirect('/web') + @http.route('/r/<string:code>/m/<int:mailing_trace_id>', type='http', auth="public") def full_url_redirect(self, code, mailing_trace_id, **post): # don't assume geoip is set, it is part of the website module |
