mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Use the template version at the time the notification is created or at the time the job is created.
Update notifications/sms|email endpoint to send the template version to the queue. Update the process_job celery talk to send the template version to the queue. When the send_sms|send_email task runs it will get the template by id and version. Created a data migration script to add the template_vesion column for jobs and notifications. The existing jobs and notifications are given the template_version of the current template. There is a chance this is the wrong template version, but deemed okay since the application is not live. Create unit test for the dao_get_template_versions method. Rename /template/<id>/version to /template/<id>/versions which returns all versions for that template id and service id.
This commit is contained in:
@@ -285,6 +285,7 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
|
||||
notification_db_object = Notification(
|
||||
id=notification_id,
|
||||
template_id=notification['template'],
|
||||
template_version=notification['template_version'],
|
||||
to=notification['to'],
|
||||
service_id=service_id,
|
||||
job_id=notification.get('job', None),
|
||||
@@ -301,7 +302,7 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
|
||||
|
||||
try:
|
||||
template = Template(
|
||||
dao_get_template_by_id(notification['template']).__dict__,
|
||||
dao_get_template_by_id(notification['template'], notification['template_version']).__dict__,
|
||||
values=notification.get('personalisation', {})
|
||||
)
|
||||
reference = provider.send_email(
|
||||
@@ -315,8 +316,8 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
|
||||
except EmailClientException as e:
|
||||
current_app.logger.exception(e)
|
||||
notification_db_object.status = 'failed'
|
||||
dao_update_notification(notification_db_object)
|
||||
|
||||
dao_update_notification(notification_db_object)
|
||||
current_app.logger.info(
|
||||
"Email {} created at {} sent at {}".format(notification_id, created_at, sent_at)
|
||||
)
|
||||
|
||||
@@ -49,4 +49,5 @@ def dao_get_all_templates_for_service(service_id):
|
||||
|
||||
def dao_get_template_versions(service_id, template_id):
|
||||
history_model = Template.get_history_model()
|
||||
return history_model.query.filter_by(service_id=service_id, id=template_id).order_by(desc(history_model.version))
|
||||
return history_model.query.filter_by(service_id=service_id, id=template_id).order_by(
|
||||
desc(history_model.version)).all()
|
||||
|
||||
@@ -357,7 +357,7 @@ def send_notification(notification_type):
|
||||
), 400
|
||||
|
||||
notification_id = create_uuid()
|
||||
|
||||
notification.update({"template_version": template.version})
|
||||
if notification_type == 'sms':
|
||||
send_sms.apply_async((
|
||||
service_id,
|
||||
|
||||
@@ -107,18 +107,18 @@ def get_template_version(service_id, template_id, version):
|
||||
)
|
||||
)
|
||||
if errors:
|
||||
return json_resp(result='error', message=errors), 400
|
||||
return jsonify(result='error', message=errors), 400
|
||||
return jsonify(data=data)
|
||||
|
||||
|
||||
@template.route('/<uuid:template_id>/version')
|
||||
@template.route('/<uuid:template_id>/versions')
|
||||
def get_template_versions(service_id, template_id):
|
||||
data, errors = template_history_schema.dump(
|
||||
dao_get_template_versions(service_id, template_id),
|
||||
dao_get_template_versions(service_id=service_id, template_id=template_id),
|
||||
many=True
|
||||
)
|
||||
if errors:
|
||||
return json_resp(result='error', message=errors), 400
|
||||
return jsonify(result='error', message=errors), 400
|
||||
return jsonify(data=data)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user