mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 23:41:17 -05:00
Stop guessing notification type
Before the search term was either: - an email address (or partial email address) - a phone number (or partial phone number) Now it can also be: - a reference (or partial reference) We can take a pretty good guess, by looking at the search term, whether the thing the user is searching by email address or phone number. This helps us: - only show relevant notifications - normalise the search term to give the best chance of matching what we store in the `normalised_to` field However we can’t look at a search term and guess whether it’s a reference, because a reference could take any format. Therefore if the user hasn’t told us what kind of thing their search term is, we should stop trying to guess.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import functools
|
||||
import string
|
||||
from itertools import groupby
|
||||
from operator import attrgetter
|
||||
from datetime import (
|
||||
@@ -570,8 +569,6 @@ def dao_update_notifications_by_reference(references, update_dict):
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notifications_by_recipient_or_reference(service_id, search_term, notification_type=None, statuses=None):
|
||||
if notification_type is None:
|
||||
notification_type = guess_notification_type(search_term)
|
||||
|
||||
if notification_type == SMS_TYPE:
|
||||
normalised = try_validate_and_format_phone_number(search_term)
|
||||
@@ -587,9 +584,12 @@ def dao_get_notifications_by_recipient_or_reference(service_id, search_term, not
|
||||
except InvalidEmailError:
|
||||
normalised = search_term.lower()
|
||||
|
||||
else:
|
||||
elif notification_type == LETTER_TYPE:
|
||||
raise InvalidRequest("Only email and SMS can use search by recipient", 400)
|
||||
|
||||
else:
|
||||
normalised = search_term.lower()
|
||||
|
||||
normalised = escape_special_characters(normalised)
|
||||
search_term = escape_special_characters(search_term)
|
||||
|
||||
@@ -765,13 +765,6 @@ def dao_precompiled_letters_still_pending_virus_check():
|
||||
return notifications
|
||||
|
||||
|
||||
def guess_notification_type(search_term):
|
||||
if set(search_term) & set(string.ascii_letters + '@'):
|
||||
return EMAIL_TYPE
|
||||
else:
|
||||
return SMS_TYPE
|
||||
|
||||
|
||||
def _duplicate_update_warning(notification, status):
|
||||
current_app.logger.info(
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user