[IMP] mass_mailing: improve routes naming
Rename main routes, and keep a legacy for the main unsubscribe route to keep retro compatibility for existing mailings. Task-2710804 (Mail: Clean MailThread API) Task-2669037 (Mass Mailing: Subscription page code cleaning) Prepares Task-2150462 (Mass Mailing: Unsubscribe flow refactoring) Part-of: odoo/odoo#106568
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import legacy
|
||||
from . import main
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
from odoo.addons.base.models.ir_qweb import keep_query
|
||||
|
||||
class MailingLegacy(http.Controller):
|
||||
""" Retro compatibility layer for legacy endpoint"""
|
||||
|
||||
@http.route(['/mail/mailing/<int:mailing_id>/unsubscribe'], type='http', website=True, auth='public')
|
||||
def mailing_unsubscribe(self, mailing_id, **post):
|
||||
return request.redirect(
|
||||
f'/mailing/{mailing_id}/unsubscribe?{keep_query("*")}'
|
||||
)
|
||||
@@ -24,7 +24,7 @@ class MassMailController(http.Controller):
|
||||
# SUBSCRIPTION MANAGEMENT
|
||||
# ------------------------------------------------------------
|
||||
|
||||
@http.route(['/mail/mailing/<int:mailing_id>/unsubscribe'], type='http', website=True, auth='public')
|
||||
@http.route(['/mailing/<int:mailing_id>/unsubscribe'], type='http', website=True, auth='public')
|
||||
def mailing_unsubscribe(self, mailing_id, email=None, res_id=None, token="", **post):
|
||||
mailing = request.env['mailing.mailing'].sudo().browse(mailing_id)
|
||||
if mailing.exists():
|
||||
@@ -82,7 +82,7 @@ class MassMailController(http.Controller):
|
||||
})
|
||||
return request.redirect('/web')
|
||||
|
||||
@http.route('/mail/mailing/unsubscribe', type='json', auth='public')
|
||||
@http.route('/mailing/list/update', type='json', auth='public')
|
||||
def mailing_update_list_subscription(self, mailing_id, opt_in_ids, opt_out_ids, email, res_id, token):
|
||||
mailing = request.env['mailing.mailing'].sudo().browse(mailing_id)
|
||||
if mailing.exists():
|
||||
|
||||
@@ -1017,7 +1017,7 @@ class MassMailing(models.Model):
|
||||
|
||||
def _get_unsubscribe_url(self, email_to, res_id):
|
||||
url = werkzeug.urls.url_join(
|
||||
self.get_base_url(), 'mail/mailing/%(mailing_id)s/unsubscribe?%(params)s' % {
|
||||
self.get_base_url(), 'mailing/%(mailing_id)s/unsubscribe?%(params)s' % {
|
||||
'mailing_id': self.id,
|
||||
'params': werkzeug.urls.url_encode({
|
||||
'res_id': res_id,
|
||||
|
||||
@@ -71,7 +71,7 @@ odoo.define('mass_mailing.unsubscribe', function (require) {
|
||||
unchecked_ids[i] = parseInt($(this).val());
|
||||
});
|
||||
|
||||
ajax.jsonRpc('/mail/mailing/unsubscribe', 'call', {'opt_in_ids': checked_ids, 'opt_out_ids': unchecked_ids, 'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token})
|
||||
ajax.jsonRpc('/mailing/list/update', 'call', {'opt_in_ids': checked_ids, 'opt_out_ids': unchecked_ids, 'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token})
|
||||
.then(function (result) {
|
||||
if (result == 'unauthorized'){
|
||||
$('#subscription_info').text(_t('You are not authorized to do this!'));
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<template id="unsubscribe_form">
|
||||
<div class="container o_unsubscribe_form">
|
||||
<div class="row">
|
||||
<form action="/mail/mailing/unsubscribe" method="POST" id="unsubscribe_form" class="col-lg-6 offset-lg-3 mt-4">
|
||||
<form action="/mailing/list/update" method="POST" id="unsubscribe_form" class="col-lg-6 offset-lg-3 mt-4">
|
||||
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
|
||||
<input type="hidden" name="email" t-att-value="email"/>
|
||||
<input type="hidden" name="mailing_id" t-att-value="mailing_id"/>
|
||||
|
||||
@@ -74,7 +74,7 @@ class TestMassMailing(TestMailFullCommon):
|
||||
email['body'])
|
||||
# rendered unsubscribe
|
||||
self.assertIn(
|
||||
'%s/mail/mailing/%s/unsubscribe' % (mailing.get_base_url(), mailing.id),
|
||||
'%s/mailing/%s/unsubscribe' % (mailing.get_base_url(), mailing.id),
|
||||
email['body'])
|
||||
unsubscribe_href = self._get_href_from_anchor_id(email['body'], "url6")
|
||||
unsubscribe_url = werkzeug.urls.url_parse(unsubscribe_href)
|
||||
|
||||
Reference in New Issue
Block a user