refactor(attestation_template): cleanup relationships

This commit is contained in:
Paul Chavard 2022-02-11 08:45:16 +01:00
parent 88e80e9e32
commit e269077c40
10 changed files with 36 additions and 33 deletions

View file

@ -84,7 +84,7 @@ class Procedure < ApplicationRecord
has_many :experts, through: :experts_procedures
has_one :module_api_carto, dependent: :destroy
has_one :attestation_template, dependent: :destroy
has_one :legacy_attestation_template, class_name: 'AttestationTemplate', dependent: :destroy
has_many :attestation_templates, through: :revisions, source: :attestation_template
belongs_to :parent_procedure, class_name: 'Procedure', optional: true
@ -434,7 +434,6 @@ class Procedure < ApplicationRecord
populate_champ_stable_ids
include_list = {
attestation_template: [],
draft_revision: {
revision_types_de_champ: {
type_de_champ: :types_de_champ
@ -580,7 +579,7 @@ class Procedure < ApplicationRecord
touch(:whitelisted_at)
end
def active_attestation_template
def attestation_template
published_attestation_template || draft_attestation_template
end
@ -588,9 +587,9 @@ class Procedure < ApplicationRecord
# As an optimization, dont check the predefined templates (they are presumed correct)
if closed_mail.present?
tag_present = closed_mail.body.to_s.include?("--lien attestation--")
if active_attestation_template&.activated? && !tag_present
if attestation_template&.activated? && !tag_present
:missing_tag
elsif !active_attestation_template&.activated? && tag_present
elsif !attestation_template&.activated? && tag_present
:extraneous_tag
end
end