mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
Validate column heading.
Still need to show that it is the heading that is wrong.
This commit is contained in:
16
app/utils.py
16
app/utils.py
@@ -3,7 +3,7 @@ import re
|
||||
from functools import wraps
|
||||
from flask import (abort, session)
|
||||
|
||||
from utils.process_csv import get_recipient_from_row
|
||||
from utils.process_csv import get_recipient_from_row, first_column_heading
|
||||
|
||||
|
||||
class BrowsableItem(object):
|
||||
@@ -42,6 +42,11 @@ class InvalidPhoneError(Exception):
|
||||
self.message = message
|
||||
|
||||
|
||||
class InvalidHeaderError(Exception):
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
|
||||
def validate_phone_number(number):
|
||||
sanitised_number = number.replace('(', '')
|
||||
sanitised_number = sanitised_number.replace(')', '')
|
||||
@@ -90,12 +95,21 @@ def validate_email_address(email_address):
|
||||
|
||||
|
||||
def validate_recipient(row, template_type):
|
||||
validate_header_row(row, template_type)
|
||||
return {
|
||||
'email': validate_email_address,
|
||||
'sms': validate_phone_number
|
||||
}[template_type](get_recipient_from_row(row, template_type))
|
||||
|
||||
|
||||
def validate_header_row(row, template_type):
|
||||
try:
|
||||
column_heading = first_column_heading[template_type]
|
||||
row[column_heading]
|
||||
except KeyError as e:
|
||||
raise InvalidHeaderError('Invalid header name, should be {}'.format(column_heading))
|
||||
|
||||
|
||||
def user_has_permissions(*permissions, or_=False):
|
||||
def wrap(func):
|
||||
@wraps(func)
|
||||
|
||||
Reference in New Issue
Block a user