2016-02-25 11:23:04 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
2016-04-06 14:58:13 +01:00
|
|
|
import itertools
|
2016-01-19 11:23:09 +00:00
|
|
|
from flask import (
|
|
|
|
|
Blueprint,
|
|
|
|
|
jsonify,
|
2016-02-22 17:17:29 +00:00
|
|
|
request,
|
2016-03-01 13:30:10 +00:00
|
|
|
current_app,
|
2016-03-10 17:29:17 +00:00
|
|
|
url_for,
|
|
|
|
|
json
|
2016-02-16 11:22:44 +00:00
|
|
|
)
|
2016-04-13 15:31:08 +01:00
|
|
|
from notifications_utils.recipients import allowed_to_send_to, first_column_heading
|
|
|
|
|
from notifications_utils.template import Template
|
2016-04-06 16:34:45 +01:00
|
|
|
from app.clients.email.aws_ses import get_aws_responses
|
2016-03-09 11:06:37 +00:00
|
|
|
from app import api_user, encryption, create_uuid, DATETIME_FORMAT, DATE_FORMAT
|
2016-03-01 13:30:10 +00:00
|
|
|
from app.authentication.auth import require_admin
|
2016-02-22 17:17:29 +00:00
|
|
|
from app.dao import (
|
|
|
|
|
templates_dao,
|
|
|
|
|
services_dao,
|
2016-02-25 11:35:32 +00:00
|
|
|
notifications_dao
|
2016-02-22 17:17:29 +00:00
|
|
|
)
|
2016-04-06 14:31:33 +01:00
|
|
|
from app.notifications.process_client_response import (
|
|
|
|
|
validate_callback_data,
|
|
|
|
|
process_sms_client_response
|
|
|
|
|
)
|
2016-02-03 13:16:19 +00:00
|
|
|
from app.schemas import (
|
2016-02-16 11:22:44 +00:00
|
|
|
email_notification_schema,
|
|
|
|
|
sms_template_notification_schema,
|
2016-03-21 12:37:34 +00:00
|
|
|
notification_status_schema,
|
|
|
|
|
notifications_filter_schema
|
2016-02-16 11:22:44 +00:00
|
|
|
)
|
2016-02-22 17:17:29 +00:00
|
|
|
from app.celery.tasks import send_sms, send_email
|
2016-01-19 11:23:09 +00:00
|
|
|
|
|
|
|
|
notifications = Blueprint('notifications', __name__)
|
|
|
|
|
|
2016-02-17 17:04:50 +00:00
|
|
|
from app.errors import register_errors
|
2016-02-22 17:17:29 +00:00
|
|
|
|
2016-02-17 17:04:50 +00:00
|
|
|
register_errors(notifications)
|
2016-03-21 13:24:37 +00:00
|
|
|
|
2016-01-19 11:23:09 +00:00
|
|
|
|
2016-03-10 17:29:17 +00:00
|
|
|
@notifications.route('/notifications/email/ses', methods=['POST'])
|
|
|
|
|
def process_ses_response():
|
2016-04-06 16:34:45 +01:00
|
|
|
client_name = 'SES'
|
2016-03-10 17:29:17 +00:00
|
|
|
try:
|
|
|
|
|
ses_request = json.loads(request.data)
|
2016-04-06 16:34:45 +01:00
|
|
|
|
|
|
|
|
errors = validate_callback_data(data=ses_request, fields=['Message'], client_name=client_name)
|
|
|
|
|
if errors:
|
2016-03-10 17:29:17 +00:00
|
|
|
return jsonify(
|
2016-04-06 16:34:45 +01:00
|
|
|
result="error", message=errors
|
2016-03-10 17:29:17 +00:00
|
|
|
), 400
|
|
|
|
|
|
2016-03-14 14:49:02 +00:00
|
|
|
ses_message = json.loads(ses_request['Message'])
|
2016-04-06 16:34:45 +01:00
|
|
|
errors = validate_callback_data(data=ses_message, fields=['notificationType'], client_name=client_name)
|
|
|
|
|
if errors:
|
2016-03-10 17:29:17 +00:00
|
|
|
return jsonify(
|
2016-04-06 16:34:45 +01:00
|
|
|
result="error", message=errors
|
2016-03-10 17:29:17 +00:00
|
|
|
), 400
|
|
|
|
|
|
2016-04-06 16:34:45 +01:00
|
|
|
notification_type = ses_message['notificationType']
|
2016-03-21 13:24:37 +00:00
|
|
|
try:
|
2016-04-06 16:34:45 +01:00
|
|
|
aws_response_dict = get_aws_responses(notification_type)
|
2016-03-21 13:24:37 +00:00
|
|
|
except KeyError:
|
2016-04-06 16:34:45 +01:00
|
|
|
message = "{} callback failed: status {} not found".format(client_name, notification_type)
|
|
|
|
|
current_app.logger.info(message)
|
2016-03-10 17:29:17 +00:00
|
|
|
return jsonify(
|
|
|
|
|
result="error",
|
2016-04-06 16:34:45 +01:00
|
|
|
message=message
|
2016-03-10 17:29:17 +00:00
|
|
|
), 400
|
|
|
|
|
|
2016-04-06 16:34:45 +01:00
|
|
|
notification_status = aws_response_dict['notification_status']
|
|
|
|
|
notification_statistics_status = aws_response_dict['notification_statistics_status']
|
2016-03-21 13:24:37 +00:00
|
|
|
|
2016-03-10 17:29:17 +00:00
|
|
|
try:
|
2016-03-14 14:49:02 +00:00
|
|
|
source = ses_message['mail']['source']
|
|
|
|
|
if is_not_a_notification(source):
|
2016-03-11 10:19:40 +00:00
|
|
|
current_app.logger.info(
|
2016-03-21 13:24:37 +00:00
|
|
|
"SES callback for notify success:. source {} status {}".format(source, notification_status)
|
2016-03-11 10:19:40 +00:00
|
|
|
)
|
|
|
|
|
return jsonify(
|
|
|
|
|
result="success", message="SES callback succeeded"
|
|
|
|
|
), 200
|
2016-03-10 17:29:17 +00:00
|
|
|
|
2016-03-14 14:49:02 +00:00
|
|
|
reference = ses_message['mail']['messageId']
|
2016-03-21 13:24:37 +00:00
|
|
|
if notifications_dao.update_notification_status_by_reference(
|
|
|
|
|
reference,
|
|
|
|
|
notification_status,
|
|
|
|
|
notification_statistics_status
|
|
|
|
|
) == 0:
|
2016-03-10 17:29:17 +00:00
|
|
|
current_app.logger.info(
|
2016-03-21 13:24:37 +00:00
|
|
|
"SES callback failed: notification not found. Status {}".format(notification_status)
|
2016-03-10 17:29:17 +00:00
|
|
|
)
|
|
|
|
|
return jsonify(
|
|
|
|
|
result="error",
|
2016-03-21 13:24:37 +00:00
|
|
|
message="SES callback failed: notification not found. Status {}".format(notification_status)
|
2016-03-10 17:29:17 +00:00
|
|
|
), 404
|
2016-03-21 13:24:37 +00:00
|
|
|
|
2016-04-06 16:34:45 +01:00
|
|
|
if not aws_response_dict['success']:
|
2016-03-21 13:24:37 +00:00
|
|
|
current_app.logger.info(
|
|
|
|
|
"SES delivery failed: notification {} has error found. Status {}".format(
|
|
|
|
|
reference,
|
2016-04-06 16:34:45 +01:00
|
|
|
aws_response_dict['message']
|
2016-03-21 13:24:37 +00:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
2016-03-10 17:29:17 +00:00
|
|
|
return jsonify(
|
|
|
|
|
result="success", message="SES callback succeeded"
|
|
|
|
|
), 200
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
current_app.logger.error(
|
2016-03-11 10:19:40 +00:00
|
|
|
"SES callback failed: messageId missing"
|
2016-03-10 17:29:17 +00:00
|
|
|
)
|
|
|
|
|
return jsonify(
|
2016-03-11 10:19:40 +00:00
|
|
|
result="error", message="SES callback failed: messageId missing"
|
2016-03-10 17:29:17 +00:00
|
|
|
), 400
|
|
|
|
|
|
2016-03-11 09:06:22 +00:00
|
|
|
except ValueError as ex:
|
2016-03-11 08:37:04 +00:00
|
|
|
current_app.logger.exception(
|
2016-04-06 16:34:45 +01:00
|
|
|
"{} callback failed: invalid json {}".format(client_name, ex)
|
2016-03-10 17:29:17 +00:00
|
|
|
)
|
|
|
|
|
return jsonify(
|
2016-04-06 16:34:45 +01:00
|
|
|
result="error", message="{} callback failed: invalid json".format(client_name)
|
2016-03-10 17:29:17 +00:00
|
|
|
), 400
|
|
|
|
|
|
|
|
|
|
|
2016-03-11 10:19:40 +00:00
|
|
|
def is_not_a_notification(source):
|
|
|
|
|
invite_email = "{}@{}".format(
|
|
|
|
|
current_app.config['INVITATION_EMAIL_FROM'],
|
|
|
|
|
current_app.config['NOTIFY_EMAIL_DOMAIN']
|
|
|
|
|
)
|
|
|
|
|
if current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'] == source:
|
|
|
|
|
return True
|
|
|
|
|
if invite_email == source:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
2016-04-04 15:02:21 +01:00
|
|
|
@notifications.route('/notifications/sms/mmg', methods=['POST'])
|
|
|
|
|
def process_mmg_response():
|
2016-04-06 14:31:33 +01:00
|
|
|
client_name = 'MMG'
|
|
|
|
|
data = json.loads(request.data)
|
|
|
|
|
validation_errors = validate_callback_data(data=data,
|
|
|
|
|
fields=['status', 'CID'],
|
|
|
|
|
client_name=client_name)
|
|
|
|
|
if validation_errors:
|
|
|
|
|
[current_app.logger.info(e) for e in validation_errors]
|
|
|
|
|
return jsonify(result='error', message=validation_errors), 400
|
|
|
|
|
|
2016-04-20 09:45:13 +01:00
|
|
|
success, errors = process_sms_client_response(status=str(data.get('status')),
|
2016-04-06 14:31:33 +01:00
|
|
|
reference=data.get('CID'),
|
2016-04-21 11:37:38 +01:00
|
|
|
client_name=client_name)
|
2016-04-06 14:31:33 +01:00
|
|
|
if errors:
|
|
|
|
|
[current_app.logger.info(e) for e in errors]
|
2016-04-04 18:08:37 +01:00
|
|
|
return jsonify(result='error', message=errors), 400
|
|
|
|
|
else:
|
2016-04-06 14:31:33 +01:00
|
|
|
return jsonify(result='success', message=success), 200
|
2016-04-04 18:08:37 +01:00
|
|
|
|
2016-03-10 15:40:41 +00:00
|
|
|
|
2016-04-04 18:08:37 +01:00
|
|
|
@notifications.route('/notifications/sms/firetext', methods=['POST'])
|
|
|
|
|
def process_firetext_response():
|
2016-04-06 14:31:33 +01:00
|
|
|
client_name = 'Firetext'
|
|
|
|
|
validation_errors = validate_callback_data(data=request.form,
|
|
|
|
|
fields=['status', 'reference'],
|
|
|
|
|
client_name=client_name)
|
|
|
|
|
if validation_errors:
|
|
|
|
|
current_app.logger.info(validation_errors)
|
|
|
|
|
return jsonify(result='error', message=validation_errors), 400
|
|
|
|
|
|
|
|
|
|
success, errors = process_sms_client_response(status=request.form.get('status'),
|
|
|
|
|
reference=request.form.get('reference'),
|
|
|
|
|
client_name=client_name)
|
|
|
|
|
if errors:
|
|
|
|
|
[current_app.logger.info(e) for e in errors]
|
2016-04-04 18:08:37 +01:00
|
|
|
return jsonify(result='error', message=errors), 400
|
2016-04-06 14:31:33 +01:00
|
|
|
else:
|
|
|
|
|
return jsonify(result='success', message=success), 200
|
2016-03-10 15:40:41 +00:00
|
|
|
|
|
|
|
|
|
2016-03-11 12:39:55 +00:00
|
|
|
@notifications.route('/notifications/<uuid:notification_id>', methods=['GET'])
|
2016-01-19 13:45:57 +00:00
|
|
|
def get_notifications(notification_id):
|
2016-03-11 12:39:55 +00:00
|
|
|
notification = notifications_dao.get_notification(api_user['client'], notification_id)
|
2016-03-24 13:34:45 +00:00
|
|
|
return jsonify(data={"notification": notification_status_schema.dump(notification).data}), 200
|
2016-01-19 11:23:09 +00:00
|
|
|
|
|
|
|
|
|
2016-03-01 13:30:10 +00:00
|
|
|
@notifications.route('/notifications', methods=['GET'])
|
|
|
|
|
def get_all_notifications():
|
2016-03-21 12:37:34 +00:00
|
|
|
data, errors = notifications_filter_schema.load(request.args)
|
|
|
|
|
if errors:
|
|
|
|
|
return jsonify(result="error", message=errors), 400
|
2016-03-01 13:30:10 +00:00
|
|
|
|
2016-03-21 12:37:34 +00:00
|
|
|
page = data['page'] if 'page' in data else 1
|
2016-04-19 10:52:52 +01:00
|
|
|
page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
|
2016-03-01 13:30:10 +00:00
|
|
|
|
2016-03-21 12:37:34 +00:00
|
|
|
pagination = notifications_dao.get_notifications_for_service(
|
|
|
|
|
api_user['client'],
|
|
|
|
|
filter_dict=data,
|
2016-04-19 10:52:52 +01:00
|
|
|
page=page,
|
|
|
|
|
page_size=page_size)
|
2016-03-01 13:30:10 +00:00
|
|
|
return jsonify(
|
2016-03-21 12:37:34 +00:00
|
|
|
notifications=notification_status_schema.dump(pagination.items, many=True).data,
|
2016-04-19 10:52:52 +01:00
|
|
|
page_size=page_size,
|
|
|
|
|
total=pagination.total,
|
2016-03-01 13:30:10 +00:00
|
|
|
links=pagination_links(
|
2016-03-21 12:37:34 +00:00
|
|
|
pagination,
|
2016-03-01 13:30:10 +00:00
|
|
|
'.get_all_notifications',
|
2016-03-16 16:47:18 +00:00
|
|
|
**request.args.to_dict()
|
2016-03-01 13:30:10 +00:00
|
|
|
)
|
|
|
|
|
), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@notifications.route('/service/<service_id>/notifications', methods=['GET'])
|
|
|
|
|
@require_admin()
|
|
|
|
|
def get_all_notifications_for_service(service_id):
|
2016-03-21 12:37:34 +00:00
|
|
|
data, errors = notifications_filter_schema.load(request.args)
|
|
|
|
|
if errors:
|
|
|
|
|
return jsonify(result="error", message=errors), 400
|
2016-03-01 13:30:10 +00:00
|
|
|
|
2016-03-21 12:37:34 +00:00
|
|
|
page = data['page'] if 'page' in data else 1
|
2016-04-19 10:52:52 +01:00
|
|
|
page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
|
2016-03-01 13:30:10 +00:00
|
|
|
|
2016-03-21 12:37:34 +00:00
|
|
|
pagination = notifications_dao.get_notifications_for_service(
|
|
|
|
|
service_id,
|
|
|
|
|
filter_dict=data,
|
2016-04-19 10:52:52 +01:00
|
|
|
page=page,
|
|
|
|
|
page_size=page_size)
|
2016-03-16 16:47:18 +00:00
|
|
|
kwargs = request.args.to_dict()
|
|
|
|
|
kwargs['service_id'] = service_id
|
2016-03-01 13:30:10 +00:00
|
|
|
return jsonify(
|
2016-03-21 12:37:34 +00:00
|
|
|
notifications=notification_status_schema.dump(pagination.items, many=True).data,
|
2016-04-19 10:52:52 +01:00
|
|
|
page_size=page_size,
|
|
|
|
|
total=pagination.total,
|
2016-03-01 13:30:10 +00:00
|
|
|
links=pagination_links(
|
2016-03-21 12:37:34 +00:00
|
|
|
pagination,
|
2016-03-01 13:30:10 +00:00
|
|
|
'.get_all_notifications_for_service',
|
2016-03-16 16:47:18 +00:00
|
|
|
**kwargs
|
2016-03-01 13:30:10 +00:00
|
|
|
)
|
|
|
|
|
), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@notifications.route('/service/<service_id>/job/<job_id>/notifications', methods=['GET'])
|
|
|
|
|
@require_admin()
|
|
|
|
|
def get_all_notifications_for_service_job(service_id, job_id):
|
2016-03-21 12:37:34 +00:00
|
|
|
data, errors = notifications_filter_schema.load(request.args)
|
|
|
|
|
if errors:
|
|
|
|
|
return jsonify(result="error", message=errors), 400
|
2016-03-01 13:30:10 +00:00
|
|
|
|
2016-03-21 12:37:34 +00:00
|
|
|
page = data['page'] if 'page' in data else 1
|
2016-04-19 10:52:52 +01:00
|
|
|
page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
|
2016-03-01 13:30:10 +00:00
|
|
|
|
2016-03-21 12:37:34 +00:00
|
|
|
pagination = notifications_dao.get_notifications_for_job(
|
|
|
|
|
service_id,
|
|
|
|
|
job_id,
|
|
|
|
|
filter_dict=data,
|
2016-04-19 10:52:52 +01:00
|
|
|
page=page,
|
|
|
|
|
page_size=page_size)
|
2016-03-16 16:47:18 +00:00
|
|
|
kwargs = request.args.to_dict()
|
|
|
|
|
kwargs['service_id'] = service_id
|
|
|
|
|
kwargs['job_id'] = job_id
|
2016-03-01 13:30:10 +00:00
|
|
|
return jsonify(
|
2016-03-21 12:37:34 +00:00
|
|
|
notifications=notification_status_schema.dump(pagination.items, many=True).data,
|
2016-04-19 10:52:52 +01:00
|
|
|
page_size=page_size,
|
|
|
|
|
total=pagination.total,
|
2016-03-01 13:30:10 +00:00
|
|
|
links=pagination_links(
|
2016-03-21 12:37:34 +00:00
|
|
|
pagination,
|
2016-03-01 13:30:10 +00:00
|
|
|
'.get_all_notifications_for_service_job',
|
2016-03-16 16:47:18 +00:00
|
|
|
**kwargs
|
2016-03-01 13:30:10 +00:00
|
|
|
)
|
|
|
|
|
), 200
|
|
|
|
|
|
|
|
|
|
|
2016-03-16 16:47:18 +00:00
|
|
|
def pagination_links(pagination, endpoint, **kwargs):
|
|
|
|
|
if 'page' in kwargs:
|
|
|
|
|
kwargs.pop('page', None)
|
2016-03-01 13:30:10 +00:00
|
|
|
links = dict()
|
|
|
|
|
if pagination.has_prev:
|
2016-03-16 16:47:18 +00:00
|
|
|
links['prev'] = url_for(endpoint, page=pagination.prev_num, **kwargs)
|
2016-03-01 13:30:10 +00:00
|
|
|
if pagination.has_next:
|
2016-03-16 16:47:18 +00:00
|
|
|
links['next'] = url_for(endpoint, page=pagination.next_num, **kwargs)
|
|
|
|
|
links['last'] = url_for(endpoint, page=pagination.pages, **kwargs)
|
2016-03-01 13:30:10 +00:00
|
|
|
return links
|
|
|
|
|
|
|
|
|
|
|
2016-02-29 11:03:48 +00:00
|
|
|
@notifications.route('/notifications/<string:notification_type>', methods=['POST'])
|
2016-02-25 11:35:32 +00:00
|
|
|
def send_notification(notification_type):
|
2016-02-29 11:03:48 +00:00
|
|
|
if notification_type not in ['sms', 'email']:
|
|
|
|
|
assert False
|
2016-02-24 09:55:05 +00:00
|
|
|
|
2016-02-25 11:35:32 +00:00
|
|
|
service_id = api_user['client']
|
2016-03-09 11:06:37 +00:00
|
|
|
service = services_dao.dao_fetch_service_by_id(api_user['client'])
|
|
|
|
|
|
|
|
|
|
service_stats = notifications_dao.dao_get_notification_statistics_for_service_and_day(
|
|
|
|
|
service_id,
|
|
|
|
|
datetime.utcnow().strftime(DATE_FORMAT)
|
|
|
|
|
)
|
2016-03-10 09:48:29 +00:00
|
|
|
|
2016-03-09 11:06:37 +00:00
|
|
|
if service_stats:
|
|
|
|
|
total_sms_count = service_stats.sms_requested
|
|
|
|
|
total_email_count = service_stats.emails_requested
|
|
|
|
|
|
2016-04-08 16:13:10 +01:00
|
|
|
if (total_email_count + total_sms_count >= service.message_limit) and service.restricted:
|
|
|
|
|
return jsonify(result="error", message='Exceeded send limits ({}) for today'.format(
|
|
|
|
|
service.message_limit)), 429
|
2016-02-22 17:17:29 +00:00
|
|
|
|
2016-02-29 11:03:48 +00:00
|
|
|
notification, errors = (
|
|
|
|
|
sms_template_notification_schema if notification_type == 'sms' else email_notification_schema
|
|
|
|
|
).load(request.get_json())
|
2016-02-15 16:01:14 +00:00
|
|
|
|
2016-02-23 17:30:50 +00:00
|
|
|
if errors:
|
|
|
|
|
return jsonify(result="error", message=errors), 400
|
|
|
|
|
|
2016-02-29 11:23:34 +00:00
|
|
|
template = templates_dao.dao_get_template_by_id_and_service_id(
|
2016-02-23 17:30:50 +00:00
|
|
|
template_id=notification['template'],
|
|
|
|
|
service_id=service_id
|
2016-02-29 11:23:34 +00:00
|
|
|
)
|
2016-02-23 17:30:50 +00:00
|
|
|
|
2016-02-29 14:43:44 +00:00
|
|
|
template_object = Template(template.__dict__, notification.get('personalisation', {}))
|
2016-02-29 11:23:34 +00:00
|
|
|
if template_object.missing_data:
|
|
|
|
|
return jsonify(
|
|
|
|
|
result="error",
|
|
|
|
|
message={
|
|
|
|
|
'template': ['Missing personalisation: {}'.format(
|
|
|
|
|
", ".join(template_object.missing_data)
|
|
|
|
|
)]
|
|
|
|
|
}
|
|
|
|
|
), 400
|
|
|
|
|
if template_object.additional_data:
|
|
|
|
|
return jsonify(
|
|
|
|
|
result="error",
|
|
|
|
|
message={
|
|
|
|
|
'template': ['Personalisation not needed for template: {}'.format(
|
|
|
|
|
", ".join(template_object.additional_data)
|
|
|
|
|
)]
|
|
|
|
|
}
|
|
|
|
|
), 400
|
|
|
|
|
|
2016-04-04 15:02:25 +01:00
|
|
|
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
|
|
|
|
|
|
2016-02-24 17:12:30 +00:00
|
|
|
notification_id = create_uuid()
|
2016-02-22 17:17:29 +00:00
|
|
|
|
2016-02-29 11:03:48 +00:00
|
|
|
if notification_type == 'sms':
|
2016-02-24 09:55:05 +00:00
|
|
|
send_sms.apply_async((
|
2016-02-24 11:11:02 +00:00
|
|
|
service_id,
|
2016-02-24 09:55:05 +00:00
|
|
|
notification_id,
|
2016-02-25 11:23:04 +00:00
|
|
|
encryption.encrypt(notification),
|
2016-03-08 17:45:37 +00:00
|
|
|
datetime.utcnow().strftime(DATETIME_FORMAT)
|
2016-02-29 11:03:48 +00:00
|
|
|
), queue='sms')
|
2016-02-24 09:55:05 +00:00
|
|
|
else:
|
|
|
|
|
send_email.apply_async((
|
2016-02-24 11:11:02 +00:00
|
|
|
service_id,
|
2016-02-24 09:55:05 +00:00
|
|
|
notification_id,
|
2016-04-25 16:37:55 +01:00
|
|
|
'"{}" <{}@{}>'.format(service.name, service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
2016-02-25 11:23:04 +00:00
|
|
|
encryption.encrypt(notification),
|
2016-03-08 17:45:37 +00:00
|
|
|
datetime.utcnow().strftime(DATETIME_FORMAT)
|
2016-02-29 11:03:48 +00:00
|
|
|
), queue='email')
|
2016-03-24 13:34:45 +00:00
|
|
|
|
|
|
|
|
return jsonify(data={"notification": {"id": notification_id}}), 201
|