[MOV] mass_mailing: reorganize controllers and templates

PURPOSE

Reorganize addon according to guidelines, helping finding and updating

SPECIFICATIONS

Reorganize templates in order to see a bit what's going on here. Notably split
subscription (opt-out, blacklist) from management (view, reporting) templates.

Reorganize controller code by main section in order to separate a bit various
code purpose.

This commit contains only file split / renaming and code move.

Task-2864264 (Mass Mailing Module Reorganization)

Part-of: odoo/odoo#92509
This commit is contained in:
Thibault Delavallée
2022-05-31 16:02:25 +02:00
parent 4f39a80e76
commit f446e54cbd
6 changed files with 134 additions and 111 deletions
+4 -2
View File
@@ -48,7 +48,9 @@
'views/utm_campaign_views.xml',
'views/mailing_menus.xml',
'views/assets.xml',
'views/mass_mailing_templates_portal.xml',
'views/mailing_templates_portal_layouts.xml',
'views/mailing_templates_portal_management.xml',
'views/mailing_templates_portal_unsubscribe.xml',
'views/themes_templates.xml',
'views/snippets_themes.xml',
'views/snippets/s_alert.xml',
@@ -94,7 +96,7 @@
'mass_mailing/static/src/js/mass_mailing_design_constants.js',
'mass_mailing/static/src/js/mass_mailing_widget.js',
'mass_mailing/static/src/js/mailing_mailing_view_form_full_width.js',
'mass_mailing/static/src/js/unsubscribe.js',
'mass_mailing/static/src/js/mailing_portal.js',
],
'mass_mailing.assets_mail_themes': [
'mass_mailing/static/src/scss/themes/**/*',
+62 -46
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import base64
import base64
import werkzeug
from odoo import _, exceptions, http, tools
@@ -23,10 +23,9 @@ class MassMailController(http.Controller):
model_display = mailing.mailing_model_id.display_name
blacklist_entry._message_log(body=description + " ({})".format(model_display))
@http.route(['/unsubscribe_from_list'], type='http', website=True, multilang=False, auth='public', sitemap=False)
def unsubscribe_placeholder_link(self, **post):
"""Dummy route so placeholder is not prefixed by language, MUST have multilang=False"""
raise werkzeug.exceptions.NotFound()
# ------------------------------------------------------------
# SUBSCRIPTION MANAGEMENT
# ------------------------------------------------------------
@http.route(['/mail/mailing/<int:mailing_id>/unsubscribe'], type='http', website=True, auth='public')
def mailing(self, mailing_id, email=None, res_id=None, token="", **post):
@@ -92,6 +91,28 @@ class MassMailController(http.Controller):
return True
return 'error'
@http.route('/mailing/feedback', type='json', auth='public')
def send_feedback(self, mailing_id, res_id, email, feedback, token):
mailing = request.env['mailing.mailing'].sudo().browse(mailing_id)
if mailing.exists() and email:
if not self._valid_unsubscribe_token(mailing_id, res_id, email, token):
return 'unauthorized'
model = request.env[mailing.mailing_model_real]
records = model.sudo().search([('email_normalized', '=', tools.email_normalize(email))])
for record in records:
record.sudo().message_post(body=_("Feedback from %(email)s: %(feedback)s", email=email, feedback=feedback))
return bool(records)
return 'error'
@http.route(['/unsubscribe_from_list'], type='http', website=True, multilang=False, auth='public', sitemap=False)
def unsubscribe_placeholder_link(self, **post):
"""Dummy route so placeholder is not prefixed by language, MUST have multilang=False"""
raise werkzeug.exceptions.NotFound()
# ------------------------------------------------------------
# TRACKING
# ------------------------------------------------------------
@http.route('/mail/track/<int:mail_id>/<string:token>/blank.gif', type='http', auth='public')
def track_mail_open(self, mail_id, token, **post):
""" Email tracking. """
@@ -105,6 +126,39 @@ class MassMailController(http.Controller):
return response
@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
# which mass_mailing doesn't depend on
country_code = request.geoip.get('country_code')
request.env['link.tracker.click'].sudo().add_click(
code,
ip=request.httprequest.remote_addr,
country_code=country_code,
mailing_trace_id=mailing_trace_id
)
return request.redirect(request.env['link.tracker'].get_url_from_code(code), code=301, local=False)
# ------------------------------------------------------------
# MAILING MANAGEMENT
# ------------------------------------------------------------
@http.route('/mailing/report/unsubscribe', type='http', website=True, auth='public')
def turn_off_mailing_reports(self, token, user_id):
if not token or not user_id:
raise werkzeug.exceptions.NotFound()
user_id = int(user_id)
correct_token = consteq(token, request.env['mailing.mailing']._get_unsubscribe_token(user_id))
user = request.env['res.users'].sudo().browse(user_id)
if correct_token and user.has_group('mass_mailing.group_mass_mailing_user'):
request.env['ir.config_parameter'].sudo().set_param('mass_mailing.mass_mailing_reports', False)
if user.has_group('base.group_system'):
menu_id = request.env.ref('mass_mailing.menu_mass_mailing_global_settings').id
return request.render('mass_mailing.mailing_report_deactivated', {'menu_id': menu_id})
return request.render('mass_mailing.mailing_report_deactivated')
raise werkzeug.exceptions.NotFound()
@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)
@@ -134,19 +188,9 @@ class MassMailController(http.Controller):
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
# which mass_mailing doesn't depend on
country_code = request.geoip.get('country_code')
request.env['link.tracker.click'].sudo().add_click(
code,
ip=request.httprequest.remote_addr,
country_code=country_code,
mailing_trace_id=mailing_trace_id
)
return request.redirect(request.env['link.tracker'].get_url_from_code(code), code=301, local=False)
# ------------------------------------------------------------
# BLACKLIST
# ------------------------------------------------------------
@http.route('/mailing/blacklist/check', type='json', auth='public')
def blacklist_check(self, mailing_id, res_id, email, token):
@@ -182,31 +226,3 @@ class MassMailController(http.Controller):
_("""Requested de-blacklisting via unsubscription page."""))
return True
return 'error'
@http.route('/mailing/feedback', type='json', auth='public')
def send_feedback(self, mailing_id, res_id, email, feedback, token):
mailing = request.env['mailing.mailing'].sudo().browse(mailing_id)
if mailing.exists() and email:
if not self._valid_unsubscribe_token(mailing_id, res_id, email, token):
return 'unauthorized'
model = request.env[mailing.mailing_model_real]
records = model.sudo().search([('email_normalized', '=', tools.email_normalize(email))])
for record in records:
record.sudo().message_post(body=_("Feedback from %(email)s: %(feedback)s", email=email, feedback=feedback))
return bool(records)
return 'error'
@http.route('/mailing/report/unsubscribe', type='http', website=True, auth='public')
def turn_off_mailing_reports(self, token, user_id):
if not token or not user_id:
raise werkzeug.exceptions.NotFound()
user_id = int(user_id)
correct_token = consteq(token, request.env['mailing.mailing']._get_unsubscribe_token(user_id))
user = request.env['res.users'].sudo().browse(user_id)
if correct_token and user.has_group('mass_mailing.group_mass_mailing_user'):
request.env['ir.config_parameter'].sudo().set_param('mass_mailing.mass_mailing_reports', False)
if user.has_group('base.group_system'):
menu_id = request.env.ref('mass_mailing.menu_mass_mailing_global_settings').id
return request.render('mass_mailing.mailing_report_deactivated', {'menu_id': menu_id})
return request.render('mass_mailing.mailing_report_deactivated')
raise werkzeug.exceptions.NotFound()
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- new layout for mass_mailing -->
<template id="mass_mailing.layout" name="Mass Mailing Layout">
<t t-call="web.layout">
<t t-set="head">
<t t-call-assets="web.assets_common"/>
<t t-call-assets="web.assets_backend"/>
</t>
<body class="o_white_body">
<header>
<div><title>Odoo</title></div>
<div class="text-center">
<img t-attf-src="/web/binary/company_logo?company={{ res_company.id }}"/>
</div>
</header>
<div id="wrap" class="oe_structure oe_empty"/>
<main>
<t t-out="0"/>
</main>
</body>
<xpath expr="//footer" position="replace">
<div class="container mt16 mb8">
<div class="float-end" t-ignore="true" t-if="not editable">
Create a <a target="_blank" href="https://www.odoo.com/app/website">free website</a> with
<a target="_blank" class="label label-danger" href="https://www.odoo.com/app/website">Odoo</a>
</div>
<div class="float-start text-muted" itemscope="itemscope" itemtype="https://schema.org/Organization">
<t t-call="web.debug_icon"/>
Copyright &amp;copy; <span t-field="res_company.name" itemprop="name">Company name</span>
</div>
</div>
</xpath>
</t>
</template>
</odoo>
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="mailing_report_deactivated" name="Report Unsubscribed">
<t t-call="mass_mailing.layout">
<div class="container mt8">
<div class="row">
<div class="col-lg-6 offset-lg-3">
<h3>Mailing Reports Turned Off</h3>
<div class="alert alert-success text-center" role="status">
<p>
Mailing Reports have been turned off for all users. <br/>
If needed, they can be turned back on from the
<a t-if="menu_id" t-attf-href="/web#menu_id=#{menu_id}">
Settings Menu.
</a>
<t t-else="">
Settings Menu.
</t>
</p>
</div>
</div>
</div>
</div>
</t>
</template>
<!-- Dummy layout to "view" a template content (html) -->
<template id="view" name="Browser View">
<!-- Raw body inserted here because it is a rendered mailing, therefore internal content -->
<t t-out="body"/>
</template>
</odoo>
@@ -1,29 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="mailing_report_deactivated" name="Report Unsubscribed">
<t t-call="mass_mailing.layout">
<div class="container mt8">
<div class="row">
<div class="col-lg-6 offset-lg-3">
<h3>Mailing Reports Turned Off</h3>
<div class="alert alert-success text-center" role="status">
<p>
Mailing Reports have been turned off for all users. <br/>
If needed, they can be turned back on from the
<a t-if="menu_id" t-attf-href="/web#menu_id=#{menu_id}">
Settings Menu.
</a>
<t t-else="">
Settings Menu.
</t>
</p>
</div>
</div>
</div>
</div>
</t>
</template>
<template id="unsubscribe">
<div class="container o_unsubscribe_form">
<div class="row">
@@ -121,11 +97,6 @@
</div>
</template>
<template id="view" name="Browser View">
<!-- Raw body inserted here because it is a rendered mailing, therefore internal content -->
<t t-out="body"/>
</template>
<template id="page_unsubscribe" name="Unsubscribe">
<t t-call="mass_mailing.layout">
<t t-call="mass_mailing.unsubscribe"/>
@@ -137,38 +108,4 @@
<t t-call="mass_mailing.unsubscribed"/>
</t>
</template>
<!-- new layout for mass_mailing -->
<template id="mass_mailing.layout" name="Mass Mailing Layout">
<t t-call="web.layout">
<t t-set="head">
<t t-call-assets="web.assets_common"/>
<t t-call-assets="web.assets_backend"/>
</t>
<body class="o_white_body">
<header>
<div><title>Odoo</title></div>
<div class="text-center">
<img t-attf-src="/web/binary/company_logo?company={{ res_company.id }}"/>
</div>
</header>
<div id="wrap" class="oe_structure oe_empty"/>
<main>
<t t-out="0"/>
</main>
</body>
<xpath expr="//footer" position="replace">
<div class="container mt16 mb8">
<div class="float-end" t-ignore="true" t-if="not editable">
Create a <a target="_blank" href="https://www.odoo.com/app/website">free website</a> with
<a target="_blank" class="label label-danger" href="https://www.odoo.com/app/website">Odoo</a>
</div>
<div class="float-start text-muted" itemscope="itemscope" itemtype="https://schema.org/Organization">
<t t-call="web.debug_icon"/>
Copyright &amp;copy; <span t-field="res_company.name" itemprop="name">Company name</span>
</div>
</div>
</xpath>
</t>
</template>
</odoo>