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: text_success:
one: "1 is being archived" one: "1 is being archived"
other: "%{success_count}/%{count} files have been 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: passer_en_instruction:
finish: finish:
text_success: text_success:

View file

@ -8,6 +8,15 @@ fr:
text_success: text_success:
one: "1 dossier est en cours d'archivage" one: "1 dossier est en cours d'archivage"
other: "%{success_count}/%{count} dossiers ont été archivés" 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: passer_en_instruction:
finish: finish:
text_success: text_success:

View file

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

View file

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

View file

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

View file

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

View file

@ -58,6 +58,60 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
end end
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 describe 'passer_en_instruction' do
let(:component) do let(:component) do
described_class.new( described_class.new(

View file

@ -18,6 +18,18 @@ FactoryBot.define do
end end
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 trait :passer_en_instruction do
operation { BatchOperation.operations.fetch(:passer_en_instruction) } operation { BatchOperation.operations.fetch(:passer_en_instruction) }
after(:build) do |batch_operation, evaluator| after(:build) do |batch_operation, evaluator|

View file

@ -32,6 +32,19 @@ describe BatchOperationProcessOneJob, type: :job do
end end
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 context 'when operation is "passer_en_instruction"' do
let(:batch_operation) do let(:batch_operation) do
create(:batch_operation, :passer_en_instruction, create(:batch_operation, :passer_en_instruction,