mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Small refactor to reuse code.
This commit is contained in:
@@ -20,12 +20,7 @@ from app.models import SMS_TYPE, KEY_TYPE_TEST, BRANDING_ORG, EMAIL_TYPE, NOTIFI
|
|||||||
|
|
||||||
def send_sms_to_provider(notification):
|
def send_sms_to_provider(notification):
|
||||||
service = notification.service
|
service = notification.service
|
||||||
if not service.active:
|
if service_is_inactive(service, notification):
|
||||||
notification.status = NOTIFICATION_TECHNICAL_FAILURE
|
|
||||||
dao_update_notification(notification)
|
|
||||||
current_app.logger.warn(
|
|
||||||
"Send sms for notification id {} to provider is not allowed: service {} is inactive".format(notification.id,
|
|
||||||
service.id))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if notification.status == 'created':
|
if notification.status == 'created':
|
||||||
@@ -69,13 +64,7 @@ def send_sms_to_provider(notification):
|
|||||||
|
|
||||||
def send_email_to_provider(notification):
|
def send_email_to_provider(notification):
|
||||||
service = notification.service
|
service = notification.service
|
||||||
if not service.active:
|
if service_is_inactive(service, notification):
|
||||||
notification.status = NOTIFICATION_TECHNICAL_FAILURE
|
|
||||||
dao_update_notification(notification)
|
|
||||||
current_app.logger.warn(
|
|
||||||
"Send email for notification id {} to provider is not allowed: service {} is inactive".format(
|
|
||||||
notification.id,
|
|
||||||
service.id))
|
|
||||||
return
|
return
|
||||||
if notification.status == 'created':
|
if notification.status == 'created':
|
||||||
provider = provider_to_use(EMAIL_TYPE, notification.id)
|
provider = provider_to_use(EMAIL_TYPE, notification.id)
|
||||||
@@ -199,3 +188,21 @@ def get_html_email_options(service):
|
|||||||
branding = {}
|
branding = {}
|
||||||
|
|
||||||
return dict(govuk_banner=govuk_banner, **branding)
|
return dict(govuk_banner=govuk_banner, **branding)
|
||||||
|
|
||||||
|
|
||||||
|
def service_is_inactive(service, notification):
|
||||||
|
"""
|
||||||
|
If service is inactive update the notification to technical failure and return true.
|
||||||
|
:param service:
|
||||||
|
:param notification:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
if not service.active:
|
||||||
|
notification.status = NOTIFICATION_TECHNICAL_FAILURE
|
||||||
|
dao_update_notification(notification)
|
||||||
|
current_app.logger.warn(
|
||||||
|
"Send {} for notification id {} to provider is not allowed: service {} is inactive".format(
|
||||||
|
notification.notification_type,
|
||||||
|
notification.id,
|
||||||
|
service.id))
|
||||||
|
return not service.active
|
||||||
|
|||||||
Reference in New Issue
Block a user