feat: batch action for supprimer
This commit is contained in:
parent
e868d62ffd
commit
5ec95d781c
9 changed files with 111 additions and 2 deletions
|
@ -35,6 +35,15 @@ en:
|
||||||
text_success:
|
text_success:
|
||||||
one: "1 is being refused"
|
one: "1 is being refused"
|
||||||
other: "%{success_count}/%{count} files have been 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:
|
classer_sans_suite:
|
||||||
finish:
|
finish:
|
||||||
text_success:
|
text_success:
|
||||||
|
|
|
@ -35,6 +35,15 @@ fr:
|
||||||
text_success:
|
text_success:
|
||||||
one: "1 dossier est en cours de refus"
|
one: "1 dossier est en cours de refus"
|
||||||
other: "%{success_count}/%{count} dossiers ont été refusés"
|
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:
|
classer_sans_suite:
|
||||||
finish:
|
finish:
|
||||||
text_success:
|
text_success:
|
||||||
|
|
|
@ -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(:archiver), BatchOperation.operations.fetch(:supprimer)]
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end.append(BatchOperation.operations.fetch(:follow), BatchOperation.operations.fetch(:unfollow))
|
end.append(BatchOperation.operations.fetch(:follow), BatchOperation.operations.fetch(:unfollow))
|
||||||
|
@ -44,6 +44,10 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
||||||
{
|
{
|
||||||
label: t(".operations.archiver"),
|
label: t(".operations.archiver"),
|
||||||
operation: BatchOperation.operations.fetch(:archiver)
|
operation: BatchOperation.operations.fetch(:archiver)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t(".operations.supprimer"),
|
||||||
|
operation: BatchOperation.operations.fetch(:supprimer)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -113,6 +117,7 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
||||||
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',
|
||||||
|
supprimer: 'fr-icon-delete-line',
|
||||||
unfollow: 'fr-icon-star-fill'
|
unfollow: 'fr-icon-star-fill'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,7 @@ fr:
|
||||||
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'
|
||||||
|
supprimer: Delete seleted files
|
||||||
accepter_description: Users will be notified that their file has been accepted
|
accepter_description: Users will be notified that their file has been accepted
|
||||||
refuser: 'Refuse seleted files'
|
refuser: 'Refuse seleted files'
|
||||||
refuser_description: Users will be notified that their file has been refused
|
refuser_description: Users will be notified that their file has been refused
|
||||||
|
|
|
@ -4,6 +4,7 @@ fr:
|
||||||
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'
|
||||||
|
supprimer: 'Supprimer les dossiers'
|
||||||
accepter_description: Les usagers seront informés que leur dossier a été accepté
|
accepter_description: Les usagers seront informés que leur dossier a été accepté
|
||||||
refuser: 'Refuser les dossiers'
|
refuser: 'Refuser les dossiers'
|
||||||
refuser_description: Les usagers seront informés que leur dossier a été refusé
|
refuser_description: Les usagers seront informés que leur dossier a été refusé
|
||||||
|
|
|
@ -7,7 +7,8 @@ class BatchOperation < ApplicationRecord
|
||||||
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',
|
||||||
unfollow: 'unfollow'
|
unfollow: 'unfollow',
|
||||||
|
supprimer: 'supprimer'
|
||||||
}
|
}
|
||||||
|
|
||||||
has_many :dossiers, dependent: :nullify
|
has_many :dossiers, dependent: :nullify
|
||||||
|
@ -56,6 +57,8 @@ class BatchOperation < ApplicationRecord
|
||||||
query.state_en_instruction
|
query.state_en_instruction
|
||||||
when BatchOperation.operations.fetch(:unfollow) then
|
when BatchOperation.operations.fetch(:unfollow) then
|
||||||
query.with_followers.en_cours
|
query.with_followers.en_cours
|
||||||
|
when BatchOperation.operations.fetch(:supprimer) then
|
||||||
|
query.state_termine
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,6 +85,8 @@ class BatchOperation < ApplicationRecord
|
||||||
dossier.repasser_en_construction!(instructeur: instructeur)
|
dossier.repasser_en_construction!(instructeur: instructeur)
|
||||||
when BatchOperation.operations.fetch(:unfollow)
|
when BatchOperation.operations.fetch(:unfollow)
|
||||||
instructeur.unfollow(dossier)
|
instructeur.unfollow(dossier)
|
||||||
|
when BatchOperation.operations.fetch(:supprimer)
|
||||||
|
dossier.hide_and_keep_track!(instructeur, :instructeur_request)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -399,4 +399,58 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -94,5 +94,16 @@ FactoryBot.define do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -196,6 +196,20 @@ describe BatchOperationProcessOneJob, type: :job do
|
||||||
end
|
end
|
||||||
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
|
context 'when the dossier is out of sync (ie: someone applied a transition somewhere we do not know)' do
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
||||||
|
|
Loading…
Reference in a new issue