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:
Rebecca Law
2018-01-10 12:40:14 +00:00
parent cc839562da
commit e59d6d470e
4 changed files with 122 additions and 32 deletions

View File

@@ -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