fix(attestation_template): handle attestation changes on procedures without revisions
This commit is contained in:
parent
76b1b85fa7
commit
08030bcdb7
4 changed files with 90 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue