mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-27 09:28:03 -04:00
Check the service is active before sending the notification to the provider.
This commit is contained in:
@@ -203,7 +203,7 @@ class Test(Config):
|
||||
Queue('send-email', Exchange('default'), routing_key='send-email'),
|
||||
Queue('research-mode', Exchange('default'), routing_key='research-mode')
|
||||
]
|
||||
REDIS_ENABLED = False
|
||||
REDIS_ENABLED = True
|
||||
API_HOST_NAME = "http://localhost:6011"
|
||||
|
||||
|
||||
|
||||
@@ -13,19 +13,24 @@ from app.dao.provider_details_dao import (
|
||||
get_provider_details_by_notification_type,
|
||||
dao_toggle_sms_provider
|
||||
)
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.celery.research_mode_tasks import send_sms_response, send_email_response
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.models import SMS_TYPE, KEY_TYPE_TEST, BRANDING_ORG, EMAIL_TYPE
|
||||
|
||||
|
||||
def send_sms_to_provider(notification):
|
||||
service = dao_fetch_service_by_id(notification.service_id)
|
||||
provider = provider_to_use(SMS_TYPE, notification.id)
|
||||
current_app.logger.info(
|
||||
"Starting sending SMS {} to provider at {}".format(notification.id, datetime.utcnow())
|
||||
)
|
||||
service = notification.service
|
||||
if not notification.service.active:
|
||||
current_app.logger.warn(
|
||||
"Send sms for notification id {} to provider is not allowed: service {} is inactive".format(notification.id,
|
||||
service.id))
|
||||
return
|
||||
|
||||
if notification.status == 'created':
|
||||
provider = provider_to_use(SMS_TYPE, notification.id)
|
||||
current_app.logger.info(
|
||||
"Starting sending SMS {} to provider at {}".format(notification.id, datetime.utcnow())
|
||||
)
|
||||
template_model = dao_get_template_by_id(notification.template_id, notification.template_version)
|
||||
template = SMSMessageTemplate(
|
||||
template_model.__dict__,
|
||||
@@ -61,12 +66,18 @@ def send_sms_to_provider(notification):
|
||||
|
||||
|
||||
def send_email_to_provider(notification):
|
||||
service = dao_fetch_service_by_id(notification.service_id)
|
||||
provider = provider_to_use(EMAIL_TYPE, notification.id)
|
||||
current_app.logger.info(
|
||||
"Starting sending EMAIL {} to provider at {}".format(notification.id, datetime.utcnow())
|
||||
)
|
||||
service = notification.service
|
||||
if not notification.service.active:
|
||||
current_app.logger.warn(
|
||||
"Send email for notification id {} to provider is not allowed: service {} is inactive".format(
|
||||
notification.id,
|
||||
service.id))
|
||||
return
|
||||
if notification.status == 'created':
|
||||
provider = provider_to_use(EMAIL_TYPE, notification.id)
|
||||
current_app.logger.info(
|
||||
"Starting sending EMAIL {} to provider at {}".format(notification.id, datetime.utcnow())
|
||||
)
|
||||
template_dict = dao_get_template_by_id(notification.template_id, notification.template_version).__dict__
|
||||
|
||||
html_email = HTMLEmailTemplate(
|
||||
|
||||
@@ -112,7 +112,7 @@ def get_jobs_by_service(service_id):
|
||||
def create_job(service_id):
|
||||
service = dao_fetch_service_by_id(service_id)
|
||||
if not service.active:
|
||||
raise InvalidRequest("Unable to create job to inactive service", 400)
|
||||
raise InvalidRequest("Create job is not allowed: service is inactive ", 403)
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user