Accept CSVs with 'email address' or 'phone number'

CSV files currently have ‘to’ as the recipient column. This is changing in
https://github.com/alphagov/notifications-api/pull/109

The admin app also has to validate that the CSV files have the right columns,
because the API expects any CSV that it’s given to have been checked (also we
want things to actually work).

This commit is the minimum code change needed. In the future it should reuse
the same code as the API for processing CSV files. This will need more thinking.
This commit is contained in:
Chris Hill-Scott
2016-03-01 09:41:08 +00:00
parent 900f4cd7ff
commit b57ac2f7e5
6 changed files with 48 additions and 30 deletions

View File

@@ -3,6 +3,8 @@ import re
from functools import wraps
from flask import (abort, session)
from utils.process_csv import get_recipient_from_row
class BrowsableItem(object):
"""
@@ -87,11 +89,11 @@ def validate_email_address(email_address):
raise InvalidEmailError('Not a valid email address')
def validate_recipient(recipient, template_type):
def validate_recipient(row, template_type):
return {
'email': validate_email_address,
'sms': validate_phone_number
}[template_type](recipient)
}[template_type](get_recipient_from_row(row, template_type))
def user_has_permissions(*permissions):