Beispiel #1
0
    def blacklist_number(self, mailing_id, trace_code, **post):
        check_res = self._check_trace(mailing_id, trace_code)
        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
        # 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:
            if mailing_list_ids:
                subscriptions = request.env[
                    'mailing.contact.subscription'].sudo().search([
                        ('list_id', 'in', mailing_list_ids.ids),
                        ('contact_id.phone_sanitized', '=', tocheck_number),
                    ])
                subscriptions.write({'opt_out': True})
                lists_optout = subscriptions.mapped('list_id')
            else:
                blacklist_rec = request.env['phone.blacklist'].sudo().add(
                    tocheck_number)
                blacklist_rec._message_log(body=_(
                    'Blacklist through SMS Marketing unsubscribe (mailing ID: %s - model: %s)'
                ) % (trace.mass_mailing_id.id,
                     trace.mass_mailing_id.mailing_model_id.display_name))
            lists_optin = request.env['mailing.contact.subscription'].sudo(
            ).search([
                ('contact_id.phone_sanitized', '=', tocheck_number),
                ('list_id', 'not in', mailing_list_ids.ids),
                ('opt_out', '=', False),
            ]).mapped('list_id')
        elif tocheck_number:
            unsubscribe_error = _('Number %s not found' % tocheck_number)
        else:
            unsubscribe_error = sanitize_res['msg']

        return request.render(
            'mass_mailing_sms.blacklist_number', {
                'mailing_id': mailing_id,
                'trace_code': trace_code,
                'sms_number': sms_number,
                'lists_optin': lists_optin,
                'lists_optout': lists_optout,
                'unsubscribe_error': unsubscribe_error,
            })
Beispiel #2
0
 def _check_values(self, acquirer, iban, phone=None):
     validate_iban(iban)
     # TO CHECK: should we restrict to country code from iban country?
     sanitized_number = None
     if acquirer.sepa_direct_debit_sms_enabled:
         if not phone:
             raise ValidationError(_('No phone number provided.'))
         sanitized_number = phone_sanitize_numbers([phone], None, None).get(phone, {}).get('sanitized')
         if not sanitized_number:
             raise ValidationError(_('Incorrect phone number.'))
     return (iban, sanitized_number)