mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Notification_type is a required parameter, admin app always passes it in.
Normalise for notificaiton type. Throw InvalidRequest exception is the notification type is invalid.
This commit is contained in:
committed by
Chris Hill-Scott
parent
5f25fc0db4
commit
e3a75d1b7d
@@ -8,10 +8,9 @@ from datetime import (
|
||||
from flask import current_app
|
||||
|
||||
from notifications_utils.recipients import (
|
||||
validate_and_format_phone_number,
|
||||
validate_and_format_email_address,
|
||||
InvalidPhoneError,
|
||||
InvalidEmailError,
|
||||
try_validate_and_format_phone_number
|
||||
)
|
||||
from notifications_utils.statsd_decorators import statsd
|
||||
from werkzeug.datastructures import MultiDict
|
||||
@@ -23,6 +22,7 @@ from notifications_utils.international_billing_rates import INTERNATIONAL_BILLIN
|
||||
|
||||
from app import db, create_uuid
|
||||
from app.dao import days_ago
|
||||
from app.errors import InvalidRequest
|
||||
from app.models import (
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
@@ -40,7 +40,9 @@ from app.models import (
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_SENT
|
||||
NOTIFICATION_SENT,
|
||||
SMS_TYPE,
|
||||
EMAIL_TYPE
|
||||
)
|
||||
|
||||
from app.dao.dao_utils import transactional
|
||||
@@ -435,19 +437,23 @@ def dao_update_notifications_by_reference(references, update_dict):
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notifications_by_to_field(service_id, search_term, statuses=None, notification_type=None):
|
||||
try:
|
||||
normalised = validate_and_format_phone_number(search_term)
|
||||
except InvalidPhoneError:
|
||||
def dao_get_notifications_by_to_field(service_id, search_term, notification_type, statuses=None):
|
||||
|
||||
if notification_type == SMS_TYPE:
|
||||
normalised = try_validate_and_format_phone_number(search_term)
|
||||
|
||||
for character in {'(', ')', ' ', '-'}:
|
||||
normalised = normalised.replace(character, '')
|
||||
|
||||
normalised = normalised.lstrip('+0')
|
||||
|
||||
elif notification_type == EMAIL_TYPE:
|
||||
try:
|
||||
normalised = validate_and_format_email_address(search_term)
|
||||
except InvalidEmailError:
|
||||
normalised = search_term
|
||||
|
||||
for character in ['(', ')', ' ']:
|
||||
normalised = normalised.replace(character, '')
|
||||
|
||||
normalised = normalised.lstrip('+0')
|
||||
normalised = search_term.lower()
|
||||
else:
|
||||
raise InvalidRequest("Only email and SMS can use search by recipient", 400)
|
||||
|
||||
filters = [
|
||||
Notification.service_id == service_id,
|
||||
|
||||
Reference in New Issue
Block a user