display batch operation alert to instructeur groups not only instructeur

This commit is contained in:
Lisa Durand 2022-12-02 09:58:35 +01:00 committed by mfo
parent c52443f221
commit 6859882a58
3 changed files with 22 additions and 21 deletions

View file

@ -91,17 +91,9 @@ module Instructeurs
assign_exports assign_exports
# Set procedure_batchs to display alerts in view @batch_operations = BatchOperation.joins(:groupe_instructeurs)
# TO DO // récupérer les batchs du groupe d'instructeurs au lieu de l'instructeur .where(groupe_instructeurs: current_instructeur.groupe_instructeurs.where(procedure_id: @procedure.id))
return if current_instructeur.batch_operations.blank? .distinct
# extraire un dossier de chaque batch pour voir quel procedure est rattaché -> et les ajouter à un tableau
@procedure_batchs = []
current_instructeur.batch_operations.each do |batch|
random_batch_dossier_id = (batch.failed_dossier_ids + batch.success_dossier_ids + batch.dossiers.ids).sample
if Dossier.find(random_batch_dossier_id).procedure.id == @procedure.id
@procedure_batchs << batch
end
end
end end
def deleted_dossiers def deleted_dossiers

View file

@ -71,9 +71,9 @@
%div{ data: { controller: 'batch-operation' } } %div{ data: { controller: 'batch-operation' } }
- batch_operation_component = Dossiers::BatchOperationComponent.new(statut: @statut, procedure: @procedure) - batch_operation_component = Dossiers::BatchOperationComponent.new(statut: @statut, procedure: @procedure)
- if @procedure_batchs.present? - if @batch_operations.present?
- @procedure_batchs.each do |batch| - @batch_operations.each do |batch_operation|
= render Dossiers::BatchAlertComponent.new(batch: batch, procedure: @procedure) = render Dossiers::BatchAlertComponent.new(batch: batch_operation, procedure: @procedure)
.flex .flex
.flex-grow= render batch_operation_component .flex-grow= render batch_operation_component

View file

@ -342,22 +342,31 @@ describe Instructeurs::ProceduresController, type: :controller do
it { expect(assigns(:filtered_sorted_paginated_ids)).to match_array([termine_dossier, termine_dossier_on_gi_2].map(&:id)) } it { expect(assigns(:filtered_sorted_paginated_ids)).to match_array([termine_dossier, termine_dossier_on_gi_2].map(&:id)) }
end end
context 'with batch operations' do context 'with batch operations attached to the instructeur and his group' do
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [termine_dossier], instructeur: instructeur) } let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [termine_dossier], instructeur: instructeur, groupe_instructeurs: [gi_2]) }
let!(:termine_dossier_2) { create(:dossier, :accepte, procedure: procedure) } let!(:termine_dossier_2) { create(:dossier, :accepte, procedure: procedure) }
let!(:batch_operation_2) { create(:batch_operation, operation: :archiver, dossiers: [termine_dossier_2], instructeur: instructeur) } let!(:batch_operation_2) { create(:batch_operation, operation: :archiver, dossiers: [termine_dossier_2], instructeur: instructeur, groupe_instructeurs: [gi_2]) }
before { subject } before { subject }
it { expect(assigns(:procedure_batchs)).to match_array([batch_operation, batch_operation_2]) } it { expect(assigns(:batch_operations)).to match_array([batch_operation, batch_operation_2]) }
end end
context 'with a batch operation not attached to the instructeur' do context 'with a batch operation not attached to the instructeur and his group' do
let(:instructeur_2) { create(:instructeur) } let(:instructeur_2) { create(:instructeur) }
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [termine_dossier], instructeur: instructeur_2) } let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [termine_dossier], instructeur: instructeur_2, groupe_instructeurs: [gi_3]) }
before { subject } before { subject }
it { expect(assigns(:procedure_batchs)).to eq(nil) } it { expect(assigns(:batch_operations)).to eq([]) }
end
context 'with a batch operation not attached to the instructeur but to his group' do
let(:instructeur_2) { create(:instructeur) }
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [termine_dossier], instructeur: instructeur_2, groupe_instructeurs: [gi_2]) }
before { subject }
it { expect(assigns(:batch_operations)).to match_array([batch_operation]) }
end end
end end