Merge branch 'master' of https://github.com/alphagov/notifications-api into letter_ack_send_deskpro_prod_only

This commit is contained in:
venusbb
2018-01-22 14:54:06 +00:00
6 changed files with 49 additions and 10 deletions

View File

@@ -67,8 +67,8 @@ def check_template_is_active(template):
message="Template has been deleted")
def service_can_send_to_recipient(send_to, key_type, service):
if not service_allowed_to_send_to(send_to, service, key_type):
def service_can_send_to_recipient(send_to, key_type, service, allow_whitelisted_recipients=True):
if not service_allowed_to_send_to(send_to, service, key_type, allow_whitelisted_recipients):
if key_type == KEY_TYPE_TEAM:
message = 'Cant send to this recipient using a team-only API key'
else:
@@ -97,11 +97,11 @@ def check_service_can_schedule_notification(permissions, scheduled_for):
raise BadRequestError(message="Cannot schedule notifications (this feature is invite-only)")
def validate_and_format_recipient(send_to, key_type, service, notification_type):
def validate_and_format_recipient(send_to, key_type, service, notification_type, allow_whitelisted_recipients=True):
if send_to is None:
raise BadRequestError(message="Recipient can't be empty")
service_can_send_to_recipient(send_to, key_type, service)
service_can_send_to_recipient(send_to, key_type, service, allow_whitelisted_recipients)
if notification_type == SMS_TYPE:
international_phone_info = get_international_phone_info(send_to)

View File

@@ -49,7 +49,8 @@ def send_one_off_notification(service_id, post_data):
send_to=post_data['to'],
key_type=KEY_TYPE_NORMAL,
service=service,
notification_type=template.template_type
notification_type=template.template_type,
allow_whitelisted_recipients=False,
)
validate_created_by(service, post_data['created_by'])

View File

@@ -26,7 +26,7 @@ def get_whitelist_objects(service_id, request_json):
]
def service_allowed_to_send_to(recipient, service, key_type):
def service_allowed_to_send_to(recipient, service, key_type, allow_whitelisted_recipients=True):
if key_type == KEY_TYPE_TEST:
return True
@@ -38,6 +38,7 @@ def service_allowed_to_send_to(recipient, service, key_type):
)
whitelist_members = [
member.recipient for member in service.whitelist
if allow_whitelisted_recipients
]
if (