mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Merge branch 'master' into integrate_MMG
Conflicts: app/notifications/rest.py
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
import itertools
|
||||
from flask import (
|
||||
Blueprint,
|
||||
jsonify,
|
||||
@@ -8,7 +9,7 @@ from flask import (
|
||||
url_for,
|
||||
json
|
||||
)
|
||||
|
||||
from utils.recipients import allowed_to_send_to, first_column_heading
|
||||
from utils.template import Template
|
||||
from app.clients.email.aws_ses import AwsSesResponses
|
||||
from app import api_user, encryption, create_uuid, DATETIME_FORMAT, DATE_FORMAT
|
||||
@@ -29,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__)
|
||||
|
||||
@@ -327,12 +327,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,
|
||||
@@ -340,9 +349,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