mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Merge pull request #1228 from GSA/wrong_phone_numbers2
raise exception if phone number doesn't match
This commit is contained in:
@@ -10,6 +10,7 @@ from app.celery.test_key_tasks import send_email_response, send_sms_response
|
||||
from app.dao.email_branding_dao import dao_get_email_branding_by_id
|
||||
from app.dao.notifications_dao import dao_update_notification
|
||||
from app.dao.provider_details_dao import get_provider_details_by_notification_type
|
||||
from app.dao.service_sms_sender_dao import dao_get_sms_senders_by_service_id
|
||||
from app.enums import BrandType, KeyType, NotificationStatus, NotificationType
|
||||
from app.exceptions import NotificationTechnicalFailureException
|
||||
from app.serialised_models import SerialisedService, SerialisedTemplate
|
||||
@@ -101,6 +102,13 @@ def send_sms_to_provider(notification):
|
||||
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:
|
||||
raise ValueError(
|
||||
f"{notification.reply_to_text} not in {sender_numbers} #notify-admin-1701"
|
||||
)
|
||||
|
||||
send_sms_kwargs = {
|
||||
"to": recipient,
|
||||
"content": str(template),
|
||||
@@ -130,6 +138,14 @@ def send_sms_to_provider(notification):
|
||||
return message_id
|
||||
|
||||
|
||||
def get_sender_numbers(notification):
|
||||
possible_senders = dao_get_sms_senders_by_service_id(notification.service_id)
|
||||
sender_numbers = []
|
||||
for possible_sender in possible_senders:
|
||||
sender_numbers.append(possible_sender.sms_sender)
|
||||
return sender_numbers
|
||||
|
||||
|
||||
def send_email_to_provider(notification):
|
||||
# Someone needs an email, possibly new registration
|
||||
recipient = redis_store.get(f"email-address-{notification.id}")
|
||||
|
||||
Reference in New Issue
Block a user