From 34a8f63332e8269c2dbf5fa2b3ca16913798532c Mon Sep 17 00:00:00 2001 From: "Nasreddin (bon)" Date: Thu, 4 Jun 2020 09:33:27 +0000 Subject: [PATCH] [FIX] mass_mailing_sms: Handle same sms_code in multiple traces Issue - Go to unsubsribe sms page where the 'sms_code' is the same in multiple traces - Fill the correct phone number (same one of any traces) - Click on 'Unsubscribe me' Traceback is raised. Also, if empty phone number, still have successfull message. Cause Multiple traces with same "sms_code" but different "sms_number". The current behavior does not handle multiple traces. Solution - Filter and retrieve the trace with the correct "sms_number". - Add 'required' attribute on phone number input. opw-2264200 closes odoo/odoo#52414 Signed-off-by: Nicolas Martinelli (nim) --- addons/mass_mailing_sms/controllers/main.py | 10 +++++----- .../views/mass_mailing_sms_templates_portal.xml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/mass_mailing_sms/controllers/main.py b/addons/mass_mailing_sms/controllers/main.py index 0fc9569641f88..fbc6cb9c403ba 100644 --- a/addons/mass_mailing_sms/controllers/main.py +++ b/addons/mass_mailing_sms/controllers/main.py @@ -42,19 +42,19 @@ def blacklist_number(self, mailing_id, trace_code, **post): if not check_res.get('trace'): return werkzeug.utils.redirect('/web') country_code = request.session.get('geoip', False) and request.session.geoip.get('country_code', False) if request.session.get('geoip') else None - trace = check_res['trace'] - mailing_list_ids = trace.mass_mailing_id.contact_list_ids - # parse and validate number sms_number = post.get('sms_number', '').strip(' ') sanitize_res = phone_validation.phone_sanitize_numbers([sms_number], country_code, None)[sms_number] tocheck_number = sanitize_res['sanitized'] or sms_number + trace = check_res['trace'].filtered(lambda r: r.sms_number == tocheck_number)[:1] + mailing_list_ids = trace.mass_mailing_id.contact_list_ids + # compute opt-out / blacklist information lists_optout = request.env['mailing.list'].sudo() lists_optin = request.env['mailing.list'].sudo() unsubscribe_error = False - if tocheck_number and trace.sms_number == tocheck_number: + if tocheck_number and trace: if mailing_list_ids: subscriptions = request.env['mailing.contact.subscription'].sudo().search([ ('list_id', 'in', mailing_list_ids.ids), @@ -72,7 +72,7 @@ def blacklist_number(self, mailing_id, trace_code, **post): ('list_id', 'not in', mailing_list_ids.ids), ('opt_out', '=', False), ]).mapped('list_id') - elif tocheck_number and trace.sms_number != tocheck_number: + elif tocheck_number: unsubscribe_error = _('Number %s not found' % tocheck_number) else: unsubscribe_error = sanitize_res['msg'] diff --git a/addons/mass_mailing_sms/views/mass_mailing_sms_templates_portal.xml b/addons/mass_mailing_sms/views/mass_mailing_sms_templates_portal.xml index bd1f927eb9db9..bf5a7683dc003 100644 --- a/addons/mass_mailing_sms/views/mass_mailing_sms_templates_portal.xml +++ b/addons/mass_mailing_sms/views/mass_mailing_sms_templates_portal.xml @@ -12,7 +12,7 @@
- +