Skip to content

Commit

Permalink
[FIX] mass_mailing_sms: Handle same sms_code in multiple traces
Browse files Browse the repository at this point in the history
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 #52452

X-original-commit: 34a8f63
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
  • Loading branch information
nboulif committed Jun 4, 2020
1 parent 842497e commit 896b5bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions addons/mass_mailing_sms/controllers/main.py
Expand Up @@ -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),
Expand All @@ -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']
Expand Down
Expand Up @@ -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()"/>
Expand Down

0 comments on commit 896b5bb

Please sign in to comment.