add action 'unfollow' to page 'suivis'

This commit is contained in:
Lisa Durand 2023-01-13 15:09:24 +01:00
parent 2f666b487e
commit 06c6a4ab0c
11 changed files with 119 additions and 5 deletions

View file

@ -35,6 +35,15 @@ en:
text_success:
one: 1/1 is being followed
other: "%{progress_count}/%{count} files have been followed"
unfollow:
finish:
text_success:
one: 1/1 file has been unfollowed
other: "%{success_count}/%{count} files have been unfollowed"
in_progress:
text_success:
one: 1/1 is being unfollowed
other: "%{progress_count}/%{count} files have been unfollowed"
repasser_en_construction:
finish:
text_success:

View file

@ -35,6 +35,15 @@ fr:
text_success:
one: 1 dossier sera suivi
other: "%{progress_count}/%{count} dossiers ont été suivis"
unfollow:
finish:
text_success:
one: 1 dossier n'est plus suivi
other: "%{success_count}/%{count} dossiers ne sont plus suivis"
in_progress:
text_success:
one: 1 dossier ne sera plus suivi
other: "%{progress_count}/%{count} dossiers ne sont plus suivis"
repasser_en_construction:
finish:
text_success:

View file

@ -13,9 +13,9 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
def operations_for_dossier(dossier)
case dossier.state
when Dossier.states.fetch(:en_construction)
[BatchOperation.operations.fetch(:passer_en_instruction), BatchOperation.operations.fetch(:follow)]
[BatchOperation.operations.fetch(:passer_en_instruction), BatchOperation.operations.fetch(:follow), BatchOperation.operations.fetch(:unfollow)]
when Dossier.states.fetch(:en_instruction)
[BatchOperation.operations.fetch(:accepter), BatchOperation.operations.fetch(:repasser_en_construction)]
[BatchOperation.operations.fetch(:accepter), BatchOperation.operations.fetch(:repasser_en_construction), BatchOperation.operations.fetch(:follow), BatchOperation.operations.fetch(:unfollow)]
when Dossier.states.fetch(:accepte), Dossier.states.fetch(:refuse), Dossier.states.fetch(:sans_suite)
[BatchOperation.operations.fetch(:archiver)]
else
@ -62,6 +62,11 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
operation: BatchOperation.operations.fetch(:accepter)
},
{
label: t(".operations.unfollow"),
operation: BatchOperation.operations.fetch(:unfollow)
},
{
label: t(".operations.repasser_en_construction"),
operation: BatchOperation.operations.fetch(:repasser_en_construction)
@ -81,7 +86,8 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
archiver: 'fr-icon-folder-2-line',
follow: 'fr-icon-star-line',
passer_en_instruction: 'fr-icon-edit-line',
repasser_en_construction: 'fr-icon-draft-line'
repasser_en_construction: 'fr-icon-draft-line',
unfollow: 'fr-icon-star-fill'
}
end
end

View file

@ -4,4 +4,5 @@ fr:
passer_en_instruction: 'Change selected files to instructing'
accepter: 'Accept seleted files'
follow: 'Follow seleted files'
unfollow: 'Unfollow seleted files'
repasser_en_construction: 'Change selected files to in progress'

View file

@ -4,4 +4,5 @@ fr:
passer_en_instruction: 'Passer les dossiers en instruction'
accepter: 'Accepter les dossiers'
follow: 'Suivre les dossiers'
unfollow: 'Ne plus suivre les dossiers'
repasser_en_construction: 'Repasser les dossiers en construction'

View file

@ -21,7 +21,8 @@ class BatchOperation < ApplicationRecord
archiver: 'archiver',
follow: 'follow',
passer_en_instruction: 'passer_en_instruction',
repasser_en_construction: 'repasser_en_construction'
repasser_en_construction: 'repasser_en_construction',
unfollow: 'unfollow'
}
has_many :dossiers, dependent: :nullify
@ -64,6 +65,8 @@ class BatchOperation < ApplicationRecord
query.without_followers.en_cours
when BatchOperation.operations.fetch(:repasser_en_construction) then
query.state_en_instruction
when BatchOperation.operations.fetch(:unfollow) then
query.with_followers.en_cours
end
end
@ -84,6 +87,8 @@ class BatchOperation < ApplicationRecord
instructeur.follow(dossier)
when BatchOperation.operations.fetch(:repasser_en_construction)
dossier.repasser_en_construction!(instructeur: instructeur)
when BatchOperation.operations.fetch(:unfollow)
instructeur.unfollow(dossier)
end
end

View file

@ -275,6 +275,7 @@ class Dossier < ApplicationRecord
}
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :with_followers, -> { left_outer_joins(:follows).where.not(follows: { id: nil }) }
scope :with_champs, -> {
includes(champs_public: [
:type_de_champ,

View file

@ -219,6 +219,60 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
end
end
describe 'unfollow' do
let(:component) do
described_class.new(
batch: batch_operation,
procedure: procedure
)
end
let!(:dossier) { create(:dossier, :en_construction, :followed, procedure: procedure) }
let!(:dossier_2) { create(:dossier, :en_instruction, :followed, procedure: procedure) }
let!(:batch_operation) { create(:batch_operation, operation: :unfollow, 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 ne sont plus suivis") }
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 ne sont plus suivis") }
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 ne sont plus suivis") }
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(

View file

@ -22,7 +22,9 @@ RSpec.describe Dossiers::BatchOperationComponent, type: :component do
let(:statut) { 'suivis' }
it { is_expected.to have_button('Passer les dossiers en instruction', disabled: true) }
it { is_expected.to have_button('Accepter les dossiers', disabled: true) }
it { is_expected.to have_button('Repasser les dossiers en construction', disabled: true) }
it { is_expected.to have_link('Repasser les dossiers en construction', disabled: true) }
it { is_expected.to have_link('Ne plus suivre les dossiers', disabled: true) }
it { is_expected.to have_button('Autres actions multiples', disabled: true) }
end
context 'statut a-suivre' do

View file

@ -51,6 +51,17 @@ FactoryBot.define do
end
end
trait :unfollow do
operation { BatchOperation.operations.fetch(:unfollow) }
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, :followed, :en_instruction, procedure: procedure),
create(:dossier, :with_individual, :followed, :en_construction, procedure: procedure)
]
end
end
trait :repasser_en_construction do
operation { BatchOperation.operations.fetch(:repasser_en_construction) }
after(:build) do |batch_operation, evaluator|

View file

@ -60,6 +60,21 @@ describe BatchOperationProcessOneJob, type: :job do
end
end
context 'when operation is "unfollow"' do
let(:batch_operation) do
create(:batch_operation, :unfollow,
options.merge(instructeur: create(:instructeur)))
end
it 'removes a follower to the dossier' do
expect { subject.perform_now }
.to change { dossier_job.reload.follows.first.unfollowed_at }
.from(nil)
.to(anything)
end
end
context 'when operation is "repasser en construction"' do
let(:batch_operation) do
create(:batch_operation, :repasser_en_construction,