mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 22:42:28 -05:00
Fix the problem with updating the reply_to or service_letter_contact_id for templates.
The history was not being updated properly, we think this is because the declaritive attribute is not being set propery by the property. When reply_to: None it will update the service_letter_contact_id, but not the service_letter_contact, we think when the history_meta is build the history class and checking if the value is updated it depends which attribute it is checking first. In order to fix this issue, there is a new dao method to update the reply_to on the Template and insert a new Template history.
This commit is contained in:
@@ -33,6 +33,36 @@ def dao_update_template(template):
|
||||
db.session.add(template)
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_update_template_reply_to(template_id, reply_to):
|
||||
Template.query.filter_by(id=template_id).update(
|
||||
{"service_letter_contact_id": reply_to,
|
||||
"updated_at": datetime.utcnow(),
|
||||
"version": Template.version + 1,
|
||||
}
|
||||
)
|
||||
template = Template.query.filter_by(id=template_id).one()
|
||||
|
||||
history = TemplateHistory(**
|
||||
{
|
||||
"id": template.id,
|
||||
"name": template.name,
|
||||
"template_type": template.template_type,
|
||||
"created_at": template.created_at,
|
||||
"updated_at": template.updated_at,
|
||||
"content": template.content,
|
||||
"service_id": template.service_id,
|
||||
"subject": template.subject,
|
||||
"created_by_id": template.created_by_id,
|
||||
"version": template.version,
|
||||
"archived": template.archived,
|
||||
"process_type": template.process_type,
|
||||
"service_letter_contact_id": template.service_letter_contact_id
|
||||
})
|
||||
db.session.add(history)
|
||||
return history
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_redact_template(template, user_id):
|
||||
template.template_redacted.redact_personalisation = True
|
||||
|
||||
@@ -11,7 +11,8 @@ from app.dao.templates_dao import (
|
||||
dao_redact_template,
|
||||
dao_get_template_by_id_and_service_id,
|
||||
dao_get_all_templates_for_service,
|
||||
dao_get_template_versions
|
||||
dao_get_template_versions,
|
||||
dao_update_template_reply_to
|
||||
)
|
||||
from notifications_utils.template import SMSMessageTemplate
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
@@ -81,6 +82,11 @@ def update_template(service_id, template_id):
|
||||
if data.get('redact_personalisation') is True:
|
||||
return redact_template(fetched_template, data)
|
||||
|
||||
if "reply_to" in data:
|
||||
check_reply_to(service_id, data.get("reply_to"), fetched_template.template_type)
|
||||
updated = dao_update_template_reply_to(template_id=template_id, reply_to=data.get("reply_to"))
|
||||
return jsonify(data=template_schema.dump(updated).data), 200
|
||||
|
||||
current_data = dict(template_schema.dump(fetched_template).data.items())
|
||||
updated_template = dict(template_schema.dump(fetched_template).data.items())
|
||||
updated_template.update(data)
|
||||
@@ -89,8 +95,6 @@ def update_template(service_id, template_id):
|
||||
if _template_has_not_changed(current_data, updated_template):
|
||||
return jsonify(data=updated_template), 200
|
||||
|
||||
check_reply_to(service_id, updated_template.get('reply_to', None), fetched_template.template_type)
|
||||
|
||||
over_limit = _content_count_greater_than_limit(updated_template['content'], fetched_template.template_type)
|
||||
if over_limit:
|
||||
char_count_limit = current_app.config.get('SMS_CHAR_COUNT_LIMIT')
|
||||
@@ -160,7 +164,7 @@ def get_template_versions(service_id, template_id):
|
||||
def _template_has_not_changed(current_data, updated_template):
|
||||
return all(
|
||||
current_data[key] == updated_template[key]
|
||||
for key in ('name', 'content', 'subject', 'archived', 'process_type', 'reply_to')
|
||||
for key in ('name', 'content', 'subject', 'archived', 'process_type')
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user