Fix issue where test key cannot send messages to external numbers

This commit is contained in:
Imdad Ahad
2016-09-07 09:57:20 +01:00
parent 727c00af21
commit 840b99b277
2 changed files with 69 additions and 6 deletions

View File

@@ -28,7 +28,8 @@ from app.models import (
Notification,
EMAIL_TYPE,
SMS_TYPE,
KEY_TYPE_NORMAL
KEY_TYPE_NORMAL,
KEY_TYPE_TEST
)
from app.statsd_decorators import statsd
@@ -126,7 +127,7 @@ def send_sms(self,
notification = encryption.decrypt(encrypted_notification)
service = dao_fetch_service_by_id(service_id)
if not service_allowed_to_send_to(notification['to'], service):
if not service_allowed_to_send_to(notification['to'], service, key_type):
current_app.logger.info(
"SMS {} failed as restricted service".format(notification_id)
)
@@ -160,10 +161,12 @@ def send_email(self, service_id,
created_at,
api_key_id=None,
key_type=KEY_TYPE_NORMAL):
notification = encryption.decrypt(encrypted_notification)
service = dao_fetch_service_by_id(service_id)
if not service_allowed_to_send_to(notification['to'], service):
if not service_allowed_to_send_to(notification['to'], service, key_type):
current_app.logger.info("Email {} failed as restricted service".format(notification_id))
return
@@ -203,8 +206,8 @@ def _save_notification(created_at, notification, notification_id, service_id, no
dao_create_notification(notification_db_object)
def service_allowed_to_send_to(recipient, service):
if not service.restricted:
def service_allowed_to_send_to(recipient, service, key_type):
if not service.restricted or key_type == KEY_TYPE_TEST:
return True
return allowed_to_send_to(