[#1203] Do not include champs privés in accusé de réception
This commit is contained in:
parent
a21dee680d
commit
8f41ab89cf
2 changed files with 62 additions and 9 deletions
|
@ -116,7 +116,7 @@ module TagsSubstitutionConcern
|
|||
identity_tags = ENTREPRISE_TAGS + ETABLISSEMENT_TAGS
|
||||
end
|
||||
|
||||
filter_tags(identity_tags + dossier_tags) + procedure_type_de_champ_public_private_tags
|
||||
filter_tags(identity_tags + dossier_tags + champ_public_tags + champ_private_tags)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -156,9 +156,22 @@ module TagsSubstitutionConcern
|
|||
tags.select { |tag| tag[:available_for_states].include?(self.class::DOSSIER_STATE) }
|
||||
end
|
||||
|
||||
def procedure_type_de_champ_public_private_tags
|
||||
(procedure.types_de_champ + procedure.types_de_champ_private)
|
||||
.map { |tdc| { libelle: tdc.libelle, description: tdc.description } }
|
||||
def champ_public_tags
|
||||
types_de_champ_tags(procedure.types_de_champ, Dossier::SOUMIS)
|
||||
end
|
||||
|
||||
def champ_private_tags
|
||||
types_de_champ_tags(procedure.types_de_champ_private, Dossier::INSTRUCTION_COMMENCEE)
|
||||
end
|
||||
|
||||
def types_de_champ_tags(types_de_champ, available_for_states)
|
||||
types_de_champ.map { |tdc|
|
||||
{
|
||||
libelle: tdc.libelle,
|
||||
description: tdc.description,
|
||||
available_for_states: available_for_states
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def replace_tags(text, dossier)
|
||||
|
@ -166,8 +179,8 @@ module TagsSubstitutionConcern
|
|||
return ''
|
||||
end
|
||||
|
||||
text = replace_type_de_champ_tags(text, procedure.types_de_champ, dossier.champs)
|
||||
text = replace_type_de_champ_tags(text, procedure.types_de_champ_private, dossier.champs_private)
|
||||
text = replace_type_de_champ_tags(text, filter_tags(champ_public_tags), dossier.champs)
|
||||
text = replace_type_de_champ_tags(text, filter_tags(champ_private_tags), dossier.champs_private)
|
||||
|
||||
tags_and_datas = [
|
||||
[dossier_tags, dossier],
|
||||
|
|
|
@ -131,10 +131,10 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
context 'when the procedure has a type de champ prive named libelleA' do
|
||||
let(:types_de_champ_private) { [create(:type_de_champ_private, libelle: 'libelleA')] }
|
||||
|
||||
context 'and the are used in the template' do
|
||||
context 'and it is used in the template' do
|
||||
let(:template) { '--libelleA--' }
|
||||
|
||||
context 'and its value in the dossier are not nil' do
|
||||
context 'and its value in the dossier is not nil' do
|
||||
before { dossier.champs_private.first.update_attributes(value: 'libelle1') }
|
||||
|
||||
it { is_expected.to eq('libelle1') }
|
||||
|
@ -142,6 +142,28 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the dossier is en construction' do
|
||||
let(:state) { 'en_construction' }
|
||||
let(:template) { '--libelleA--' }
|
||||
|
||||
context 'champs privés are not valid tags' do
|
||||
# The dossier just transitionned from brouillon to en construction,
|
||||
# so champs private are not valid tags yet
|
||||
|
||||
let(:types_de_champ_private) { [create(:type_de_champ_private, libelle: 'libelleA')] }
|
||||
|
||||
it { is_expected.to eq('--libelleA--') }
|
||||
end
|
||||
|
||||
context 'champs publics are valid tags' do
|
||||
let(:types_de_champ) { [create(:type_de_champ_public, libelle: 'libelleA')] }
|
||||
|
||||
before { dossier.champs.first.update_attributes(value: 'libelle1') }
|
||||
|
||||
it { is_expected.to eq('libelle1') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the procedure has 2 types de champ date and datetime' do
|
||||
let(:types_de_champ) do
|
||||
[
|
||||
|
@ -249,16 +271,34 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
describe 'tags' do
|
||||
subject { template_concern.tags }
|
||||
|
||||
let(:types_de_champ) { [create(:type_de_champ_public, libelle: 'public')] }
|
||||
let(:types_de_champ_private) { [create(:type_de_champ_private, libelle: 'privé')] }
|
||||
|
||||
context 'when generating a document for a dossier terminé' do
|
||||
it { is_expected.to include(include({ libelle: 'motivation' })) }
|
||||
it { is_expected.to include(include({ libelle: 'date de décision' })) }
|
||||
it { is_expected.to include(include({ libelle: 'public' })) }
|
||||
it { is_expected.to include(include({ libelle: 'privé' })) }
|
||||
end
|
||||
|
||||
context 'when generating a document for a dossier that is not terminé' do
|
||||
context 'when generating a document for a dossier en instruction' do
|
||||
let(:state) { 'en_instruction' }
|
||||
|
||||
it { is_expected.not_to include(include({ libelle: 'motivation' })) }
|
||||
it { is_expected.not_to include(include({ libelle: 'date de décision' })) }
|
||||
|
||||
it { is_expected.to include(include({ libelle: 'public' })) }
|
||||
it { is_expected.to include(include({ libelle: 'privé' })) }
|
||||
end
|
||||
|
||||
context 'when generating a document for a dossier en construction' do
|
||||
let(:state) { 'en_construction' }
|
||||
|
||||
it { is_expected.not_to include(include({ libelle: 'motivation' })) }
|
||||
it { is_expected.not_to include(include({ libelle: 'date de décision' })) }
|
||||
it { is_expected.not_to include(include({ libelle: 'privé' })) }
|
||||
|
||||
it { is_expected.to include(include({ libelle: 'public' })) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue