From 27280fefa9e7cad0143aca688149f19ebdb684f6 Mon Sep 17 00:00:00 2001 From: xmo-odoo Date: Tue, 3 Oct 2017 11:19:18 +0200 Subject: [PATCH] [IMP] website_mail_channel: unsubscribing unsubscribed address Before this fix, if a (non-registered) user tried to unsubscribe an address *not registered*, they'd get an unsub link, click on it, and get a "Invalid or expired confirmation link." message, usually wondering what the bloody hell happened. Provide a clearer message in that case. --- addons/website_mail_channel/controllers/main.py | 14 +++++++++++--- .../i18n/website_mail_channel.pot | 15 +++++++++++++++ .../views/website_mail_channel_templates.xml | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/addons/website_mail_channel/controllers/main.py b/addons/website_mail_channel/controllers/main.py index c9b3deb268e..4a9e2c449a8 100644 --- a/addons/website_mail_channel/controllers/main.py +++ b/addons/website_mail_channel/controllers/main.py @@ -6,7 +6,7 @@ import werkzeug from datetime import datetime from dateutil import relativedelta -from odoo import http, fields, tools +from odoo import http, fields, tools, _ from odoo.http import request from odoo.addons.website.models.website import slug @@ -228,8 +228,16 @@ class MailGroup(http.Controller): def confirm_unsubscribe(self, channel, partner_id, token, **kw): subscriber = request.env['mail.channel.partner'].search([('channel_id', '=', channel.id), ('partner_id', '=', partner_id)]) if not subscriber: - # not registered, maybe already unsubsribed - return request.render('website_mail_channel.invalid_token_subscription') + # FIXME: remove try/except in master + try: + return request.render( + 'website_mail_channel.not_subscribed', { + 'partner_id': partner_id + }) + except ValueError: + return _("The address %s is already unsubscribed or was never subscribed to any mailing list") % ( + partner_id.email + ) subscriber_token = channel._generate_action_token(partner_id, action='unsubscribe') if token != subscriber_token: diff --git a/addons/website_mail_channel/i18n/website_mail_channel.pot b/addons/website_mail_channel/i18n/website_mail_channel.pot index 48fdff70285..183166f9142 100644 --- a/addons/website_mail_channel/i18n/website_mail_channel.pot +++ b/addons/website_mail_channel/i18n/website_mail_channel.pot @@ -291,3 +291,18 @@ msgstr "" msgid "your email..." msgstr "" +#. module: website_mail_channel +#: model:ir.ui.view,arch_db:website_mail_channel.not_subscribed +msgid "The address" +msgstr "" + +#. module: website_mail_channel +#: model:ir.ui.view,arch_db:website_mail_channel.not_subscribed +msgid "is already unsubscribed or was never subscribed to the mailing list, you may want to check that the address was correct." +msgstr "" + +#. module: website_mail_channel +#: code:addons/website_mail_channel/controllers/main.py:238 +#, python-format +msgid "The address %s is already unsubscribed or was never subscribed to any mailing list" +msgstr "" diff --git a/addons/website_mail_channel/views/website_mail_channel_templates.xml b/addons/website_mail_channel/views/website_mail_channel_templates.xml index 5ed8a25e9d6..e225d107b3c 100644 --- a/addons/website_mail_channel/views/website_mail_channel_templates.xml +++ b/addons/website_mail_channel/views/website_mail_channel_templates.xml @@ -338,4 +338,19 @@ + +