From 50d20af4066c9e827c08accf219032a50ab0123c Mon Sep 17 00:00:00 2001 From: seb-by-ouidou Date: Thu, 16 Nov 2023 09:30:16 +0000 Subject: [PATCH] feat: batch action for supprimer --- .../batch_alert_component.en.yml | 9 ++++ .../batch_alert_component.fr.yml | 9 ++++ .../dossiers/batch_operation_component.rb | 7 ++- .../batch_operation_component.en.yml | 1 + .../batch_operation_component.fr.yml | 1 + app/models/batch_operation.rb | 7 ++- .../dossiers/batch_alert_component_spec.rb | 54 +++++++++++++++++++ spec/factories/batch_operation.rb | 11 ++++ .../batch_operation_process_one_job_spec.rb | 14 +++++ 9 files changed, 111 insertions(+), 2 deletions(-) diff --git a/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml b/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml index 764c2f611e9..e8d3ac03548 100644 --- a/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml +++ b/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml @@ -35,6 +35,15 @@ en: text_success: one: "1 is being refused" other: "%{success_count}/%{count} files have been refused" + supprimer: + finish: + text_success: + one: "%{success_count}/1 file has been deleted" + other: "%{success_count}/%{count} files have been deleted" + in_progress: + text_success: + one: "1 is being deleted" + other: "%{success_count}/%{count} files have been deleted" classer_sans_suite: finish: text_success: diff --git a/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml b/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml index ed386a22721..58b9ef308a6 100644 --- a/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml +++ b/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml @@ -35,6 +35,15 @@ fr: text_success: one: "1 dossier est en cours de refus" other: "%{success_count}/%{count} dossiers ont été refusés" + supprimer: + finish: + text_success: + one: "%{success_count}/1 dossier a été supprimé" + other: "%{success_count}/%{count} dossiers ont été supprimés" + in_progress: + text_success: + one: "1 dossier est en cours de suppression" + other: "%{success_count}/%{count} dossiers ont été supprimés" classer_sans_suite: finish: text_success: diff --git a/app/components/dossiers/batch_operation_component.rb b/app/components/dossiers/batch_operation_component.rb index 3164f91f7fa..f9756e1d1b9 100644 --- a/app/components/dossiers/batch_operation_component.rb +++ b/app/components/dossiers/batch_operation_component.rb @@ -17,7 +17,7 @@ def operations_for_dossier(dossier) when Dossier.states.fetch(:en_instruction) [BatchOperation.operations.fetch(:accepter), BatchOperation.operations.fetch(:refuser), BatchOperation.operations.fetch(:classer_sans_suite), BatchOperation.operations.fetch(:repasser_en_construction)] when Dossier.states.fetch(:accepte), Dossier.states.fetch(:refuse), Dossier.states.fetch(:sans_suite) - [BatchOperation.operations.fetch(:archiver)] + [BatchOperation.operations.fetch(:archiver), BatchOperation.operations.fetch(:supprimer)] else [] end.append(BatchOperation.operations.fetch(:follow), BatchOperation.operations.fetch(:unfollow)) @@ -44,6 +44,10 @@ def available_operations { label: t(".operations.archiver"), operation: BatchOperation.operations.fetch(:archiver) + }, + { + label: t(".operations.supprimer"), + operation: BatchOperation.operations.fetch(:supprimer) } ] } @@ -110,6 +114,7 @@ def icons follow: 'fr-icon-star-line', passer_en_instruction: 'fr-icon-edit-line', repasser_en_construction: 'fr-icon-draft-line', + supprimer: 'fr-icon-delete-line', unfollow: 'fr-icon-star-fill' } end diff --git a/app/components/dossiers/batch_operation_component/batch_operation_component.en.yml b/app/components/dossiers/batch_operation_component/batch_operation_component.en.yml index fb10bc43058..f8646ebdbe9 100644 --- a/app/components/dossiers/batch_operation_component/batch_operation_component.en.yml +++ b/app/components/dossiers/batch_operation_component/batch_operation_component.en.yml @@ -4,6 +4,7 @@ fr: passer_en_instruction: 'Change selected files to instructing' instruction: Instructing files accepter: 'Accept seleted files' + supprimer: Delete seleted files accepter_description: Users will be notified that their file has been accepted refuser: 'Refuse seleted files' refuser_description: Users will be notified that their file has been refused diff --git a/app/components/dossiers/batch_operation_component/batch_operation_component.fr.yml b/app/components/dossiers/batch_operation_component/batch_operation_component.fr.yml index ef7980d3930..6c15180a084 100644 --- a/app/components/dossiers/batch_operation_component/batch_operation_component.fr.yml +++ b/app/components/dossiers/batch_operation_component/batch_operation_component.fr.yml @@ -4,6 +4,7 @@ fr: passer_en_instruction: 'Passer les dossiers en instruction' instruction: Instruire les dossiers accepter: 'Accepter les dossiers' + supprimer: 'Supprimer les dossiers' accepter_description: Les usagers seront informés que leur dossier a été accepté refuser: 'Refuser les dossiers' refuser_description: Les usagers seront informés que leur dossier a été refusé diff --git a/app/models/batch_operation.rb b/app/models/batch_operation.rb index c1da424c37b..437b24e850c 100644 --- a/app/models/batch_operation.rb +++ b/app/models/batch_operation.rb @@ -7,7 +7,8 @@ class BatchOperation < ApplicationRecord follow: 'follow', passer_en_instruction: 'passer_en_instruction', repasser_en_construction: 'repasser_en_construction', - unfollow: 'unfollow' + unfollow: 'unfollow', + supprimer: 'supprimer' } has_many :dossiers, dependent: :nullify @@ -56,6 +57,8 @@ def dossiers_safe_scope(dossier_ids = self.dossier_ids) query.state_en_instruction when BatchOperation.operations.fetch(:unfollow) then query.with_followers.en_cours + when BatchOperation.operations.fetch(:supprimer) then + query.state_termine end end @@ -82,6 +85,8 @@ def process_one(dossier) dossier.repasser_en_construction!(instructeur: instructeur) when BatchOperation.operations.fetch(:unfollow) instructeur.unfollow(dossier) + when BatchOperation.operations.fetch(:supprimer) + dossier.hide_and_keep_track!(instructeur, :instructeur_request) end end diff --git a/spec/components/dossiers/batch_alert_component_spec.rb b/spec/components/dossiers/batch_alert_component_spec.rb index d43c3bf405f..41fe867f00f 100644 --- a/spec/components/dossiers/batch_alert_component_spec.rb +++ b/spec/components/dossiers/batch_alert_component_spec.rb @@ -399,4 +399,58 @@ end end end + + describe 'supprimer' do + let(:component) do + described_class.new( + batch: batch_operation, + procedure: procedure + ) + end + let!(:dossier) { create(:dossier, :accepte, procedure: procedure) } + let!(:dossier_2) { create(:dossier, :accepte, procedure: procedure) } + let!(:batch_operation) { create(:batch_operation, operation: :supprimer, dossiers: [dossier, dossier_2], instructeur: instructeur) } + + context 'in_progress' do + before { + batch_operation.track_processed_dossier(true, dossier) + batch_operation.reload + } + + it { is_expected.to have_selector('.fr-alert--info') } + it { is_expected.to have_text("Une action de masse est en cours") } + it { is_expected.to have_text("1/2 dossiers ont été supprimés") } + end + + context 'finished and success' do + before { + batch_operation.track_processed_dossier(true, dossier) + batch_operation.track_processed_dossier(true, dossier_2) + batch_operation.reload + } + + it { is_expected.to have_selector('.fr-alert--success') } + it { is_expected.to have_text("L’action de masse est terminée") } + it { is_expected.to have_text("2 dossiers ont été supprimés") } + it { expect(batch_operation.seen_at).to eq(nil) } + end + + context 'finished and fail' do + before { + batch_operation.track_processed_dossier(false, dossier) + batch_operation.track_processed_dossier(true, dossier_2) + batch_operation.reload + } + + it { is_expected.to have_selector('.fr-alert--warning') } + it { is_expected.to have_text("L’action de masse est terminée") } + it { is_expected.to have_text("1/2 dossiers ont été supprimés") } + it { expect(batch_operation.seen_at).to eq(nil) } + + it 'on next render "seen_at" is set to avoid rendering alert' do + render_inline(component).to_html + expect(batch_operation.seen_at).not_to eq(nil) + end + end + end end diff --git a/spec/factories/batch_operation.rb b/spec/factories/batch_operation.rb index 9d91cfb0561..a5f8bb34bd0 100644 --- a/spec/factories/batch_operation.rb +++ b/spec/factories/batch_operation.rb @@ -94,5 +94,16 @@ ] end end + + trait :supprimer do + operation { BatchOperation.operations.fetch(:supprimer) } + after(:build) do |batch_operation, evaluator| + procedure = create(:simple_procedure, :published, instructeurs: [evaluator.invalid_instructeur.presence || batch_operation.instructeur], administrateurs: [create(:administrateur)]) + batch_operation.dossiers = [ + create(:dossier, :with_individual, :accepte, procedure: procedure), + create(:dossier, :with_individual, :refuse, procedure: procedure) + ] + end + end end end diff --git a/spec/jobs/batch_operation_process_one_job_spec.rb b/spec/jobs/batch_operation_process_one_job_spec.rb index e808ac59fc4..39f41afd34d 100644 --- a/spec/jobs/batch_operation_process_one_job_spec.rb +++ b/spec/jobs/batch_operation_process_one_job_spec.rb @@ -196,6 +196,20 @@ end end + context 'when operation is "supprimer"' do + let(:batch_operation) do + create(:batch_operation, :supprimer, + options.merge(instructeur: create(:instructeur))) + end + + it 'changed the dossier to en construction' do + expect { subject.perform_now } + .to change { dossier_job.reload.hidden_by_administration? } + .from(false) + .to(true) + end + end + context 'when the dossier is out of sync (ie: someone applied a transition somewhere we do not know)' do let(:instructeur) { create(:instructeur) } let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }