merge from main

This commit is contained in:
Kenneth Kehl
2024-08-22 08:38:01 -07:00
29 changed files with 855 additions and 1374 deletions

View File

@@ -1,4 +1,5 @@
import json
from contextlib import suppress
from urllib import parse
from cachetools import TTLCache, cached
@@ -81,27 +82,15 @@ def send_sms_to_provider(notification):
# We start by trying to get the phone number from a job in s3. If we fail, we assume
# the phone number is for the verification code on login, which is not a job.
recipient = None
try:
# It is our 2facode, maybe
recipient = _get_verify_code(notification)
if recipient is None:
recipient = get_phone_number_from_s3(
notification.service_id,
notification.job_id,
notification.job_row_number,
)
except Exception:
# It is our 2facode, maybe
key = f"2facode-{notification.id}".replace(" ", "")
recipient = redis_store.get(key)
if recipient:
recipient = recipient.decode("utf-8")
if recipient is None:
si = notification.service_id
ji = notification.job_id
jrn = notification.job_row_number
raise Exception(
f"The recipient for (Service ID: {si}; Job ID: {ji}; Job Row Number {jrn} was not found."
)
sender_numbers = get_sender_numbers(notification)
if notification.reply_to_text not in sender_numbers:
@@ -138,6 +127,14 @@ def send_sms_to_provider(notification):
return message_id
def _get_verify_code(notification):
key = f"2facode-{notification.id}".replace(" ", "")
recipient = redis_store.get(key)
with suppress(AttributeError):
recipient = recipient.decode("utf-8")
return recipient
def get_sender_numbers(notification):
possible_senders = dao_get_sms_senders_by_service_id(notification.service_id)
sender_numbers = []