Merge pull request #10607 from mfo/US/fix-invisible-pj
Amélioration: ETQ usager, je souhaite que les PJs d'un champ qui n'est plus visible ne soient pas soumise a l'administration
This commit is contained in:
commit
b55ed262ed
4 changed files with 59 additions and 7 deletions
|
@ -20,6 +20,7 @@ module DossierStateConcern
|
|||
def after_commit_passer_en_construction
|
||||
NotificationMailer.send_en_construction_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
remove_piece_justificative_file_not_visible!
|
||||
end
|
||||
|
||||
def after_passer_en_instruction(h)
|
||||
|
|
|
@ -894,6 +894,7 @@ class Dossier < ApplicationRecord
|
|||
|
||||
resolve_pending_correction!
|
||||
process_sva_svr!
|
||||
remove_piece_justificative_file_not_visible!
|
||||
end
|
||||
|
||||
def process_declarative!
|
||||
|
@ -934,6 +935,10 @@ class Dossier < ApplicationRecord
|
|||
champs_public.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
|
||||
end
|
||||
|
||||
def remove_piece_justificative_file_not_visible!
|
||||
champs.filter { _1.piece_justificative_file.attached? && !_1.visible? && _1.piece_justificative_file.purge_later }
|
||||
end
|
||||
|
||||
def check_mandatory_and_visible_champs
|
||||
champs_for_revision(scope: :public)
|
||||
.filter { _1.child? ? _1.parent.visible? : true }
|
||||
|
|
|
@ -599,7 +599,10 @@ describe Users::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when dossier was already submitted' do
|
||||
before { post :submit_en_construction, params: payload }
|
||||
before do
|
||||
expect_any_instance_of(Dossier).to receive(:remove_piece_justificative_file_not_visible!)
|
||||
post :submit_en_construction, params: payload
|
||||
end
|
||||
|
||||
it 'redirects to the dossier' do
|
||||
subject
|
||||
|
|
|
@ -476,18 +476,22 @@ describe Dossier, type: :model do
|
|||
|
||||
context 'when dossier is en_construction' do
|
||||
context 'when the procedure.routing_enabled? is false' do
|
||||
before do
|
||||
subject do
|
||||
dossier.passer_en_construction!
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.state).to eq(Dossier.states.fetch(:en_construction)) }
|
||||
it { expect(dossier.en_construction_at).to eq(beginning_of_day) }
|
||||
it { expect(dossier.depose_at).to eq(beginning_of_day) }
|
||||
it { expect(dossier.traitement.state).to eq(Dossier.states.fetch(:en_construction)) }
|
||||
it { expect(dossier.traitement.processed_at).to eq(beginning_of_day) }
|
||||
it do
|
||||
subject
|
||||
expect(dossier.state).to eq(Dossier.states.fetch(:en_construction))
|
||||
expect(dossier.en_construction_at).to eq(beginning_of_day)
|
||||
expect(dossier.depose_at).to eq(beginning_of_day)
|
||||
expect(dossier.traitement.state).to eq(Dossier.states.fetch(:en_construction))
|
||||
expect(dossier.traitement.processed_at).to eq(beginning_of_day)
|
||||
end
|
||||
|
||||
it 'should keep first en_construction_at date' do
|
||||
subject
|
||||
Timecop.return
|
||||
dossier.passer_en_instruction!(instructeur: instructeur)
|
||||
dossier.repasser_en_construction!(instructeur: instructeur)
|
||||
|
@ -498,6 +502,45 @@ describe Dossier, type: :model do
|
|||
expect(dossier.depose_at).to eq(beginning_of_day)
|
||||
expect(dossier.en_construction_at).to be > beginning_of_day
|
||||
end
|
||||
|
||||
context 'when dossier have piece_justificative or titre_identite' do
|
||||
include Logic
|
||||
|
||||
let(:procedure) { create(:procedure, types_de_champ_public:) }
|
||||
let(:dossier) { create(:dossier, :brouillon, :with_populated_champs, procedure:) }
|
||||
|
||||
before { expect(champ).to receive(:visible?).and_return(visible) }
|
||||
|
||||
context 'when piece_justificative' do
|
||||
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
||||
let(:champ) { dossier.champs_for_revision(scope: :public).find(&:piece_justificative?) }
|
||||
|
||||
context 'when not visible' do
|
||||
let(:visible) { false }
|
||||
it { expect { subject }.to change { champ.reload.piece_justificative_file.attached? } }
|
||||
end
|
||||
|
||||
context 'when visible' do
|
||||
let(:visible) { true }
|
||||
it { expect { subject }.not_to change { champ.reload.piece_justificative_file.attached? } }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when titre identite' do
|
||||
let(:types_de_champ_public) { [{ type: :titre_identite }] }
|
||||
let(:champ) { dossier.champs_for_revision(scope: :public).find(&:piece_justificative?) }
|
||||
|
||||
context 'when not visible' do
|
||||
let(:visible) { false }
|
||||
it { expect { subject }.to change { champ.reload.piece_justificative_file.attached? } }
|
||||
end
|
||||
|
||||
context 'when visible' do
|
||||
let(:visible) { true }
|
||||
it { expect { subject }.not_to change { champ.reload.piece_justificative_file.attached? } }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the procedure.routing_enabled? is true' do
|
||||
|
|
Loading…
Reference in a new issue