[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#52452 X-original-commit: 34a8f63332e8269c2dbf5fa2b3ca16913798532c Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com> Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
This commit is contained in:
@@ -42,19 +42,19 @@ class MailingSMSController(http.Controller):
|
||||
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 @@ class MailingSMSController(http.Controller):
|
||||
('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']
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<div class="form-group row">
|
||||
<label for="sms_number" class="col-sm-2 col-form-label">Number</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" name="sms_number" id="sms_number"/>
|
||||
<input type="text" class="form-control" name="sms_number" id="sms_number" t-att-required="true"/>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
|
||||
|
||||
Reference in New Issue
Block a user