-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Issue
- Updating a template on the
/org_admin/templates/:template_id/editpath /"Template details"tab
- The existing entry in the
templatestable is simply saved in place.
- Updating a template on a
/org_admin/templates/:template_id/phases/:phase_id/editpath /"#{phase.title}"tab
- No direct db update occurs. Rather a new version of the template is created, along with new corresponding versions of the phases, sections, questions, etc.
Resulting Outcomes
This inconsistent behaviour can result in unexpected outcomes. For example, funder templates are customisable and the following code determines whether a funder template vs org customisation of it should populate the templates dropdown on the create /plans/new page.
# Determines whether or not a customized template should be upgraded
def upgrade_customization?
return false unless customization_of?
funder_template = Template.published(customization_of).select(:created_at).first
return false unless funder_template.present?
funder_template.created_at > created_at
endLet funder_template be a customisable funder template, and org_customisation be an org's customisation of funder_template.
Also, let org_customization.created_at > funder_template.created_at.
In this scenario, org_customization.upgrade_customization? would return false.
Next, lets say we update funder_template. What will org_customization.upgrade_customization? return now? The answer to that is dependant on what exactly we updated for funder_template.
If something is updated within the "Template details" tab (e.g. title or description), then no new version is created, and because funder_template.created_at is unchanged, org_customization_template.upgrade_customization? still returns false.
However, if a field is changed in one of the "#{phase.title}" tabs, then a new version of funder_template is created. upgrade_customization? will use this new funder_template for comparison (along with it's more recent created_at value), against org_customization and org_customization_template.upgrade_customization? will now return true.