Get the sms sender from the notificaiton_sms_sender mapping table if that does not exist get the default sms sender to pass on to the sms provider.

This commit is contained in:
Rebecca Law
2017-10-30 14:55:44 +00:00
parent 4eec11b633
commit 0887910b1b
5 changed files with 69 additions and 9 deletions

View File

@@ -44,7 +44,9 @@ from app.models import (
NOTIFICATION_TEMPORARY_FAILURE,
NOTIFICATION_PERMANENT_FAILURE,
NOTIFICATION_SENT,
NotificationSmsSender)
NotificationSmsSender,
ServiceSmsSender
)
from app.dao.dao_utils import transactional
from app.statsd_decorators import statsd
@@ -659,3 +661,14 @@ def dao_create_notification_sms_sender_mapping(notification_id, sms_sender_id):
service_sms_sender_id=sms_sender_id
)
db.session.add(notification_to_sms_sender)
def dao_get_notification_sms_sender_mapping(notification_id):
sms_sender = ServiceSmsSender.query.join(
NotificationSmsSender
).filter(
NotificationSmsSender.notification_id == notification_id
).first()
if sms_sender:
return sms_sender.sms_sender

View File

@@ -11,8 +11,8 @@ from notifications_utils.template import HTMLEmailTemplate, PlainTextEmailTempla
from app import clients, statsd_client, create_uuid
from app.dao.notifications_dao import (
dao_update_notification,
dao_get_notification_email_reply_for_notification
)
dao_get_notification_email_reply_for_notification,
dao_get_notification_sms_sender_mapping)
from app.dao.provider_details_dao import (
get_provider_details_by_notification_type,
dao_toggle_sms_provider
@@ -69,11 +69,15 @@ def send_sms_to_provider(notification):
raise
else:
try:
sms_sender = dao_get_notification_sms_sender_mapping(notification.id)
if not sms_sender:
sms_sender = service.get_default_sms_sender()
provider.send_sms(
to=validate_and_format_phone_number(notification.to, international=notification.international),
content=str(template),
reference=str(notification.id),
sender=service.get_default_sms_sender()
sender=sms_sender
)
except Exception as e:
dao_toggle_sms_provider(provider.name)