From 64674be817065f8ab5db2bd7e355a374ddfb3e1a Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 23 Apr 2020 16:06:34 +0100 Subject: [PATCH] Make allowed notification types explicit in search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By not having a catch-all else, it makes it clearer what we’re expecting. And then we think it’s worth adding a comment explaining why we normalise as we do for letters and the `None` case. --- app/dao/notifications_dao.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index a06174f49..d348660df 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -599,9 +599,20 @@ def dao_get_notifications_by_recipient_or_reference(service_id, search_term, not except InvalidEmailError: normalised = search_term.lower() - else: + elif notification_type in {LETTER_TYPE, None}: + # For letters, we store the address without spaces, so we need + # to removes spaces from the search term to match. We also do + # this when a notification type isn’t provided (this will + # happen if a user doesn’t have permission to see the dashboard) + # because email addresses and phone numbers will never be stored + # with spaces either. normalised = ''.join(search_term.split()).lower() + else: + raise TypeError( + f'Notification type must be {EMAIL_TYPE}, {SMS_TYPE}, {LETTER_TYPE} or None' + ) + normalised = escape_special_characters(normalised) search_term = escape_special_characters(search_term)