From e3ae81bd0ae17db3e4751dbbcfb2c838c3744fe8 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 24 Mar 2016 16:57:25 +0000 Subject: [PATCH] Strip trailing CSV rows, relax phone validation Implements (and depends on): - https://github.com/alphagov/notifications-utils/pull/14 - https://github.com/alphagov/notifications-utils/pull/15 --- app/celery/tasks.py | 6 +++--- app/schemas.py | 6 ++---- requirements.txt | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 5aef56d93..84b2a8f8d 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -25,7 +25,7 @@ from sqlalchemy.exc import SQLAlchemyError from app.aws import s3 from datetime import datetime from utils.template import Template -from utils.recipients import RecipientCSV, format_phone_number, validate_phone_number +from utils.recipients import RecipientCSV, validate_and_format_phone_number from app.validation import (allowed_send_to_email, allowed_send_to_number) @@ -205,7 +205,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at): ) client.send_sms( - to=format_phone_number(validate_phone_number(notification['to'])), + to=validate_and_format_phone_number(notification['to']), content=template.replaced, reference=str(notification_id) ) @@ -288,7 +288,7 @@ def send_sms_code(encrypted_verification): verification_message = encryption.decrypt(encrypted_verification) try: firetext_client.send_sms( - format_phone_number(validate_phone_number(verification_message['to'])), + validate_and_format_phone_number(verification_message['to']), verification_message['secret_code'], 'send-sms-code' ) diff --git a/app/schemas.py b/app/schemas.py index c812ca689..e943e8419 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -7,7 +7,7 @@ from marshmallow_sqlalchemy import field_for from utils.recipients import ( validate_email_address, InvalidEmailError, validate_phone_number, InvalidPhoneError, - format_phone_number + validate_and_format_phone_number ) @@ -132,9 +132,7 @@ class SmsNotificationSchema(NotificationSchema): @post_load def format_phone_number(self, item): - item['to'] = format_phone_number(validate_phone_number( - item['to']) - ) + item['to'] = validate_and_format_phone_number(item['to']) return item diff --git a/requirements.txt b/requirements.txt index 118a5876a..3f4ed5ceb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,4 +21,4 @@ monotonic==0.3 git+https://github.com/alphagov/notifications-python-client.git@0.2.6#egg=notifications-python-client==0.2.6 -git+https://github.com/alphagov/notifications-utils.git@3.1.0#egg=notifications-utils==3.1.0 +git+https://github.com/alphagov/notifications-utils.git@3.1.3#egg=notifications-utils==3.1.3