feat: batch action for desarchiver

This commit is contained in:
seb-by-ouidou 2023-11-29 21:36:55 +00:00 committed by mfo
parent c0c2e35881
commit 5c80f6c3f0
9 changed files with 117 additions and 2 deletions

View file

@ -8,6 +8,15 @@ en:
text_success:
one: "1 is being archived"
other: "%{success_count}/%{count} files have been archived"
desarchiver:
finish:
text_success:
one: "%{success_count}/1 file has been unarchived"
other: "%{success_count}/%{count} files have been unarchived"
in_progress:
text_success:
one: "1 is being unarchived"
other: "%{success_count}/%{count} files have been unarchived"
passer_en_instruction:
finish:
text_success:

View file

@ -8,6 +8,15 @@ fr:
text_success:
one: "1 dossier est en cours d'archivage"
other: "%{success_count}/%{count} dossiers ont été archivés"
desarchiver:
finish:
text_success:
one: "%{success_count}/1 dossier a été désarchivé"
other: "%{success_count}/%{count} dossiers ont été désarchivés"
in_progress:
text_success:
one: "1 dossier est en cours d'désarchivage"
other: "%{success_count}/%{count} dossiers ont été désarchivés"
passer_en_instruction:
finish:
text_success:

View file

@ -7,7 +7,7 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
end
def render?
['a-suivre', 'traites', 'suivis', 'supprimes_recemment'].include?(@statut)
['a-suivre', 'traites', 'suivis', 'archives', 'supprimes_recemment'].include?(@statut)
end
def operations_for_dossier(dossier)
@ -17,7 +17,7 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
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(:supprimer), BatchOperation.operations.fetch(:restaurer)]
[BatchOperation.operations.fetch(:archiver), BatchOperation.operations.fetch(:desarchiver), BatchOperation.operations.fetch(:supprimer), BatchOperation.operations.fetch(:restaurer)]
else
[]
end.append(BatchOperation.operations.fetch(:follow), BatchOperation.operations.fetch(:unfollow))
@ -37,6 +37,16 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
}
]
}
when 'archives' then
{
options:
[
{
label: t(".operations.desarchiver"),
operation: BatchOperation.operations.fetch(:desarchiver)
}
]
}
when 'traites' then
{
options:
@ -124,6 +134,7 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
{
accepter: 'fr-icon-success-line',
archiver: 'fr-icon-folder-2-line',
desarchiver: 'fr-icon-upload-2-line',
follow: 'fr-icon-star-line',
passer_en_instruction: 'fr-icon-edit-line',
repasser_en_construction: 'fr-icon-draft-line',

View file

@ -1,6 +1,7 @@
fr:
operations:
archiver: 'Archive selected files'
desarchiver: 'Unarchive selected files'
passer_en_instruction: 'Change selected files to instructing'
instruction: Instructing files
accepter: 'Accept seleted files'

View file

@ -1,6 +1,7 @@
fr:
operations:
archiver: 'Archiver les dossiers'
desarchiver: 'Désarchiver les dossiers'
passer_en_instruction: 'Passer les dossiers en instruction'
instruction: Instruire les dossiers
accepter: 'Accepter les dossiers'

View file

@ -4,6 +4,7 @@ class BatchOperation < ApplicationRecord
refuser: 'refuser',
classer_sans_suite: 'classer_sans_suite',
archiver: 'archiver',
desarchiver: 'desarchiver',
follow: 'follow',
passer_en_instruction: 'passer_en_instruction',
repasser_en_construction: 'repasser_en_construction',
@ -43,6 +44,8 @@ class BatchOperation < ApplicationRecord
case operation
when BatchOperation.operations.fetch(:archiver) then
query.visible_by_administration.not_archived.state_termine
when BatchOperation.operations.fetch(:desarchiver) then
query.visible_by_administration.archived.state_termine
when BatchOperation.operations.fetch(:passer_en_instruction) then
query.visible_by_administration.state_en_construction
when BatchOperation.operations.fetch(:accepter) then
@ -73,6 +76,8 @@ class BatchOperation < ApplicationRecord
case operation
when BatchOperation.operations.fetch(:archiver)
dossier.archiver!(instructeur)
when BatchOperation.operations.fetch(:desarchiver)
dossier.desarchiver!
when BatchOperation.operations.fetch(:passer_en_instruction)
dossier.passer_en_instruction(instructeur: instructeur)
when BatchOperation.operations.fetch(:accepter)

View file

@ -58,6 +58,60 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
end
end
describe 'desarchiver' 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: :desarchiver, 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é désarchivés") }
it { is_expected.to have_text("Cette opération a été lancée par #{instructeur.email}, il y a moins d'une minute") }
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("Laction de masse est terminée") }
it { is_expected.to have_text("2 dossiers ont été désarchivé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("Laction de masse est terminée") }
it { is_expected.to have_text("1/2 dossiers ont été désarchivé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
describe 'passer_en_instruction' do
let(:component) do
described_class.new(

View file

@ -18,6 +18,18 @@ FactoryBot.define do
end
end
trait :desarchiver do
operation { BatchOperation.operations.fetch(:desarchiver) }
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, archived: true),
create(:dossier, :with_individual, :refuse, procedure: procedure, archived: true),
create(:dossier, :with_individual, :sans_suite, procedure: procedure, archived: true)
]
end
end
trait :passer_en_instruction do
operation { BatchOperation.operations.fetch(:passer_en_instruction) }
after(:build) do |batch_operation, evaluator|

View file

@ -32,6 +32,19 @@ describe BatchOperationProcessOneJob, type: :job do
end
end
context 'when operation is "desarchiver"' do
let(:batch_operation) do
create(:batch_operation, :desarchiver,
options.merge(instructeur: create(:instructeur)))
end
it 'archives the dossier in the batch' do
expect { subject.perform_now }
.to change { dossier_job.reload.archived? }
.from(true)
.to(false)
end
end
context 'when operation is "passer_en_instruction"' do
let(:batch_operation) do
create(:batch_operation, :passer_en_instruction,