feat: batch action for restaurer
This commit is contained in:
parent
5ec95d781c
commit
c0c2e35881
9 changed files with 126 additions and 12 deletions
|
@ -44,6 +44,15 @@ en:
|
|||
text_success:
|
||||
one: "1 is being deleted"
|
||||
other: "%{success_count}/%{count} files have been deleted"
|
||||
restaurer:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 file has been restored"
|
||||
other: "%{success_count}/%{count} files have been restored"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 is being restored"
|
||||
other: "%{success_count}/%{count} files have been restored"
|
||||
classer_sans_suite:
|
||||
finish:
|
||||
text_success:
|
||||
|
|
|
@ -44,6 +44,15 @@ fr:
|
|||
text_success:
|
||||
one: "1 dossier est en cours de suppression"
|
||||
other: "%{success_count}/%{count} dossiers ont été supprimés"
|
||||
restaurer:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 dossier a été restauré"
|
||||
other: "%{success_count}/%{count} dossiers ont été restaurés"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 dossier est en cours de restauration"
|
||||
other: "%{success_count}/%{count} dossiers ont été restaurés"
|
||||
classer_sans_suite:
|
||||
finish:
|
||||
text_success:
|
||||
|
|
|
@ -7,7 +7,7 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def render?
|
||||
['a-suivre', 'traites', 'suivis'].include?(@statut)
|
||||
['a-suivre', 'traites', 'suivis', '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(:archiver), BatchOperation.operations.fetch(:supprimer), BatchOperation.operations.fetch(:restaurer)]
|
||||
else
|
||||
[]
|
||||
end.append(BatchOperation.operations.fetch(:follow), BatchOperation.operations.fetch(:unfollow))
|
||||
|
@ -51,6 +51,16 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
}
|
||||
]
|
||||
}
|
||||
when 'supprimes_recemment' then
|
||||
{
|
||||
options:
|
||||
[
|
||||
{
|
||||
label: t(".operations.restaurer"),
|
||||
operation: BatchOperation.operations.fetch(:restaurer)
|
||||
}
|
||||
]
|
||||
}
|
||||
when 'suivis' then
|
||||
{
|
||||
options:
|
||||
|
@ -118,6 +128,7 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
passer_en_instruction: 'fr-icon-edit-line',
|
||||
repasser_en_construction: 'fr-icon-draft-line',
|
||||
supprimer: 'fr-icon-delete-line',
|
||||
restaurer: 'fr-icon-refresh-line',
|
||||
unfollow: 'fr-icon-star-fill'
|
||||
}
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ fr:
|
|||
instruction: Instructing files
|
||||
accepter: 'Accept seleted files'
|
||||
supprimer: Delete seleted files
|
||||
restaurer: Restore 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
|
||||
|
|
|
@ -5,6 +5,7 @@ fr:
|
|||
instruction: Instruire les dossiers
|
||||
accepter: 'Accepter les dossiers'
|
||||
supprimer: 'Supprimer les dossiers'
|
||||
restaurer: 'Restaurer 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é
|
||||
|
|
|
@ -7,6 +7,7 @@ class BatchOperation < ApplicationRecord
|
|||
follow: 'follow',
|
||||
passer_en_instruction: 'passer_en_instruction',
|
||||
repasser_en_construction: 'repasser_en_construction',
|
||||
restaurer: 'restaurer',
|
||||
unfollow: 'unfollow',
|
||||
supprimer: 'supprimer'
|
||||
}
|
||||
|
@ -38,27 +39,28 @@ class BatchOperation < ApplicationRecord
|
|||
def dossiers_safe_scope(dossier_ids = self.dossier_ids)
|
||||
query = instructeur
|
||||
.dossiers
|
||||
.visible_by_administration
|
||||
.where(id: dossier_ids)
|
||||
case operation
|
||||
when BatchOperation.operations.fetch(:archiver) then
|
||||
query.not_archived.state_termine
|
||||
query.visible_by_administration.not_archived.state_termine
|
||||
when BatchOperation.operations.fetch(:passer_en_instruction) then
|
||||
query.state_en_construction
|
||||
query.visible_by_administration.state_en_construction
|
||||
when BatchOperation.operations.fetch(:accepter) then
|
||||
query.state_en_instruction
|
||||
query.visible_by_administration.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:refuser) then
|
||||
query.state_en_instruction
|
||||
query.visible_by_administration.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:classer_sans_suite) then
|
||||
query.state_en_instruction
|
||||
query.visible_by_administration.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:follow) then
|
||||
query.without_followers.en_cours
|
||||
query.visible_by_administration.without_followers.en_cours
|
||||
when BatchOperation.operations.fetch(:repasser_en_construction) then
|
||||
query.state_en_instruction
|
||||
query.visible_by_administration.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:unfollow) then
|
||||
query.with_followers.en_cours
|
||||
query.visible_by_administration.with_followers.en_cours
|
||||
when BatchOperation.operations.fetch(:supprimer) then
|
||||
query.state_termine
|
||||
query.visible_by_administration.state_termine
|
||||
when BatchOperation.operations.fetch(:restaurer) then
|
||||
query.hidden_by_administration
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -87,6 +89,8 @@ class BatchOperation < ApplicationRecord
|
|||
instructeur.unfollow(dossier)
|
||||
when BatchOperation.operations.fetch(:supprimer)
|
||||
dossier.hide_and_keep_track!(instructeur, :instructeur_request)
|
||||
when BatchOperation.operations.fetch(:restaurer)
|
||||
dossier.restore(instructeur)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -346,6 +346,60 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'restaurer' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
batch: batch_operation,
|
||||
procedure: procedure
|
||||
)
|
||||
end
|
||||
let!(:dossier) { create(:dossier, :accepte, procedure: procedure, hidden_by_administration_at: Time.zone.now) }
|
||||
let!(:dossier_2) { create(:dossier, :accepte, procedure: procedure, hidden_by_administration_at: Time.zone.now) }
|
||||
let!(:batch_operation) { create(:batch_operation, operation: :restaurer, 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é restauré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é restauré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é restauré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 'repasser en construction' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
|
|
|
@ -84,6 +84,17 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :restaurer do
|
||||
operation { BatchOperation.operations.fetch(:restaurer) }
|
||||
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, hidden_by_administration_at: Time.zone.now),
|
||||
create(:dossier, :with_individual, :refuse, procedure: procedure, hidden_by_administration_at: Time.zone.now)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
trait :repasser_en_construction do
|
||||
operation { BatchOperation.operations.fetch(:repasser_en_construction) }
|
||||
after(:build) do |batch_operation, evaluator|
|
||||
|
|
|
@ -175,6 +175,20 @@ describe BatchOperationProcessOneJob, type: :job do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when operation is "restaurer"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :restaurer,
|
||||
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(true)
|
||||
.to(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when operation is "classer_sans_suite"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :classer_sans_suite,
|
||||
|
|
Loading…
Add table
Reference in a new issue