Check the service is active before sending the notification to the provider.

This commit is contained in:
Rebecca Law
2017-01-31 13:53:13 +00:00
parent ef0f708da0
commit fde3216f9e
5 changed files with 42 additions and 15 deletions

View File

@@ -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"

View File

@@ -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(

View File

@@ -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()