Skip to content

Commit

Permalink
feat: batch action for supprimer
Browse files Browse the repository at this point in the history
  • Loading branch information
seb-by-ouidou authored and seb-by-ouidou committed Nov 29, 2023
1 parent a330118 commit cdf10f9
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion app/components/dossiers/batch_operation_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
}
]
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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é
Expand Down
7 changes: 6 additions & 1 deletion app/models/batch_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
54 changes: 54 additions & 0 deletions spec/components/dossiers/batch_alert_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions spec/factories/batch_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions spec/jobs/batch_operation_process_one_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]) }
Expand Down

0 comments on commit cdf10f9

Please sign in to comment.