tag 'groupe instructeur' uniquement si la procedure est routee

This commit is contained in:
clemkeirua 2020-02-19 15:47:22 +01:00 committed by GitHub Action
parent 059d80ea34
commit 48d2093577
2 changed files with 19 additions and 23 deletions

View file

@ -11,13 +11,6 @@ module TagsSubstitutionConcern
target: :motivation, target: :motivation,
available_for_states: Dossier::TERMINE available_for_states: Dossier::TERMINE
}, },
{
libelle: 'groupe instructeur',
description: 'Le groupe instructeur en charge du dossier',
lambda: -> (d) { d.groupe_instructeur.label },
available?: -> (d) { d.procedure.routee? },
available_for_states: Dossier::SOUMIS
},
{ {
libelle: 'date de dépôt', libelle: 'date de dépôt',
description: 'Date du passage en construction du dossier par lusager', description: 'Date du passage en construction du dossier par lusager',
@ -137,6 +130,15 @@ module TagsSubstitutionConcern
} }
] ]
ROUTAGE_TAGS = [
{
libelle: 'groupe instructeur',
description: 'Le groupe instructeur en charge du dossier',
lambda: -> (d) { d.groupe_instructeur.label },
available_for_states: Dossier::SOUMIS
}
]
def tags def tags
if procedure.for_individual? if procedure.for_individual?
identity_tags = INDIVIDUAL_TAGS identity_tags = INDIVIDUAL_TAGS
@ -144,7 +146,12 @@ module TagsSubstitutionConcern
identity_tags = ENTREPRISE_TAGS identity_tags = ENTREPRISE_TAGS
end end
filter_tags(identity_tags + dossier_tags + champ_public_tags + champ_private_tags) routage_tags = []
if procedure.routee?
routage_tags = ROUTAGE_TAGS
end
filter_tags(identity_tags + dossier_tags + champ_public_tags + champ_private_tags + routage_tags)
end end
private private
@ -214,6 +221,7 @@ module TagsSubstitutionConcern
[champ_public_tags, dossier.champs], [champ_public_tags, dossier.champs],
[champ_private_tags, dossier.champs_private], [champ_private_tags, dossier.champs_private],
[dossier_tags, dossier], [dossier_tags, dossier],
[ROUTAGE_TAGS, dossier],
[INDIVIDUAL_TAGS, dossier.individual], [INDIVIDUAL_TAGS, dossier.individual],
[ENTREPRISE_TAGS, dossier.etablissement&.entreprise] [ENTREPRISE_TAGS, dossier.etablissement&.entreprise]
] ]
@ -226,19 +234,7 @@ module TagsSubstitutionConcern
def replace_tags_with_values_from_data(text, tags, data) def replace_tags_with_values_from_data(text, tags, data)
if data.present? if data.present?
tags.reduce(text) do |acc, tag| tags.reduce(text) do |acc, tag|
# A tag is available by default.
# If it has an :available? lambda, then we check its result to determine if the tag is available
if tag.key?(:available?)
tag_available = instance_exec(data, &tag[:available?])
else
tag_available = true
end
if tag_available
replace_tag(acc, tag, data) replace_tag(acc, tag, data)
else
text
end
end end
else else
text text

View file

@ -83,13 +83,13 @@ describe TagsSubstitutionConcern, type: :model do
dossier.reload dossier.reload
end end
it { expect(procedure.groupe_instructeurs.size).to eq(2) }
it { expect(procedure.routee?).to eq(true) } it { expect(procedure.routee?).to eq(true) }
it { is_expected.to eq(label) } it { is_expected.to eq(label) }
end end
context 'and the dossier has no groupe instructeur' do context 'and the dossier has no groupe instructeur' do
it { is_expected.to eq(template) } it { expect(procedure.routee?).to eq(false) }
it { is_expected.to eq('défaut') }
end end
end end