mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-20 16:13:35 -04:00
Validate recipient for restricted service w/ utils
Implements https://github.com/alphagov/notifications-utils/pull/16 Once https://github.com/alphagov/notifications-admin/pull/376 is merged it will no longer be possible for a user to upload a CSV file containing recipients that they’re not allowed to send to. So this commit also removes any restricted service checks in the task, because any public phone numbers/email addresses no longer have any way of reach this point if the service is restricted.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
import itertools
|
||||
|
||||
from flask import (
|
||||
Blueprint,
|
||||
@@ -11,6 +12,7 @@ from flask import (
|
||||
)
|
||||
|
||||
from utils.template import Template
|
||||
from utils.recipients import allowed_to_send_to, first_column_heading
|
||||
from app.clients.sms.firetext import FiretextResponses
|
||||
from app.clients.email.aws_ses import AwsSesResponses
|
||||
from app import api_user, encryption, create_uuid, DATETIME_FORMAT, DATE_FORMAT
|
||||
@@ -28,7 +30,6 @@ from app.schemas import (
|
||||
notifications_filter_schema
|
||||
)
|
||||
from app.celery.tasks import send_sms, send_email
|
||||
from app.validation import allowed_send_to_number, allowed_send_to_email
|
||||
|
||||
notifications = Blueprint('notifications', __name__)
|
||||
|
||||
@@ -356,12 +357,21 @@ def send_notification(notification_type):
|
||||
}
|
||||
), 400
|
||||
|
||||
if service.restricted and not allowed_to_send_to(
|
||||
notification['to'],
|
||||
itertools.chain.from_iterable(
|
||||
[user.mobile_number, user.email_address] for user in service.users
|
||||
)
|
||||
):
|
||||
return jsonify(
|
||||
result="error", message={
|
||||
'to': ['Invalid {} for restricted service'.format(first_column_heading[notification_type])]
|
||||
}
|
||||
), 400
|
||||
|
||||
notification_id = create_uuid()
|
||||
|
||||
if notification_type == 'sms':
|
||||
if not allowed_send_to_number(service, notification['to']):
|
||||
return jsonify(
|
||||
result="error", message={'to': ['Invalid phone number for restricted service']}), 400
|
||||
send_sms.apply_async((
|
||||
service_id,
|
||||
notification_id,
|
||||
@@ -369,9 +379,6 @@ def send_notification(notification_type):
|
||||
datetime.utcnow().strftime(DATETIME_FORMAT)
|
||||
), queue='sms')
|
||||
else:
|
||||
if not allowed_send_to_email(service, notification['to']):
|
||||
return jsonify(
|
||||
result="error", message={'to': ['Email address not permitted for restricted service']}), 400
|
||||
send_email.apply_async((
|
||||
service_id,
|
||||
notification_id,
|
||||
|
||||
Reference in New Issue
Block a user