fix(attestation_template): handle attestation changes on procedures without revisions

This commit is contained in:
Paul Chavard 2022-02-11 08:43:29 +01:00
parent 76b1b85fa7
commit 08030bcdb7
4 changed files with 90 additions and 9 deletions

View file

@ -103,17 +103,19 @@ class AttestationTemplate < ApplicationRecord
}
end
def revise!
if revisions.size > 1
def find_or_revise!
if revisions.size > 1 && procedure.feature_enabled?(:procedure_revisions)
# If attestation template belongs to more then one revision
# and procedure has revisions enabled revise attestation template.
attestation_template = dup
attestation_template.save!
revisions
.last
.procedure
.draft_revision
.update!(attestation_template: attestation_template)
procedure.draft_revision.update!(attestation_template: attestation_template)
attestation_template
else
# If procedure has only one revision or revisions are not supported
# apply updates directly to the attestation template.
# If it is a published procedure with revisions disabled,
# draft and published attestation template will be the same.
self
end
end