diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index f707d1950..551c4cb83 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -49,7 +49,7 @@ module Instructeurs @previous_following_instructeurs_emails = previous_followers.pluck(:email) @avis_emails = dossier.avis.includes(:instructeur).map(&:email_to_display) @invites_emails = dossier.invites.map(&:email) - @potential_recipients = procedure.defaut_groupe_instructeur.instructeurs.reject { |g| g == current_instructeur } + @potential_recipients = dossier.groupe_instructeur.instructeurs.reject { |g| g == current_instructeur } end def send_to_instructeurs diff --git a/app/models/instructeur.rb b/app/models/instructeur.rb index 38d2834da..21d00068e 100644 --- a/app/models/instructeur.rb +++ b/app/models/instructeur.rb @@ -110,8 +110,10 @@ class Instructeur < ApplicationRecord end def notifications_for_procedure(procedure, scope) - procedure - .defaut_groupe_instructeur.dossiers + target_groupes = groupe_instructeurs.where(procedure: procedure) + + Dossier + .where(groupe_instructeur: target_groupes) .send(scope) # :en_cours or :termine or :not_archived (or any other Dossier scope) .merge(followed_dossiers) .with_notifications diff --git a/spec/features/routing/full_scenario_spec.rb b/spec/features/routing/full_scenario_spec.rb index 86da5f97c..02e338c1a 100644 --- a/spec/features/routing/full_scenario_spec.rb +++ b/spec/features/routing/full_scenario_spec.rb @@ -1,10 +1,11 @@ require 'spec_helper' feature 'The routing' do - let(:procedure) { create(:procedure, :with_service, :for_individual) } + let(:password) { 'a very complicated password' } + let(:procedure) { create(:procedure, :with_type_de_champ, :with_service, :for_individual) } let(:administrateur) { create(:administrateur, procedures: [procedure]) } - let(:scientifique_user) { create(:user) } - let(:litteraire_user) { create(:user) } + let(:scientifique_user) { create(:user, password: password) } + let(:litteraire_user) { create(:user, password: password) } before { Flipper.enable_actor(:routage, administrateur.user) } @@ -67,6 +68,9 @@ feature 'The routing' do click_on litteraire_user.email expect(page).to have_current_path(instructeur_dossier_path(procedure, litteraire_user.dossiers.first)) + # follow the dossier + click_on 'Suivre le dossier' + log_out # the scientifiques instructeurs only manage the scientifiques dossiers @@ -74,9 +78,50 @@ feature 'The routing' do click_on procedure.libelle expect(page).not_to have_text(litteraire_user.email) expect(page).to have_text(scientifique_user.email) + + # follow the dossier + click_on scientifique_user.email + click_on 'Suivre le dossier' + log_out - # TODO: notifications tests + # litteraire_user change its dossier + visit root_path + click_on 'Connexion' + sign_in_with litteraire_user.email, password + + click_on litteraire_user.dossiers.first.id + click_on 'Modifier mon dossier' + + fill_in 'dossier_champs_attributes_0_value', with: 'some value' + click_on 'Enregistrer les modifications du dossier' + log_out + + # the litteraires instructeurs should have a notification + visit root_path + click_on 'Connexion' + sign_in_with victor.user.email, password + + ## on the procedures list + visit instructeur_procedures_path + expect(page).to have_css("span.notifications") + + ## on the dossiers list + click_on procedure.libelle + expect(page).to have_css("span.notifications") + + ## on the dossier it self + click_on 'suivi' + click_on litteraire_user.email + expect(page).to have_css("span.notifications") + + log_out + + # the scientifiques instructeurs should not have a notification + login_as marie.user, scope: :user + visit instructeur_procedures_path + expect(page).not_to have_css("span.notifications") + log_out end def publish_procedure(procedure) @@ -113,7 +158,7 @@ feature 'The routing' do token_params = confirmation_email.body.match(/token=[^"]+/) visit "users/activate?#{token_params}" - fill_in :user_password, with: 'démarches-simplifiées-pwd' + fill_in :user_password, with: password click_button 'Définir le mot de passe' diff --git a/spec/models/instructeur_spec.rb b/spec/models/instructeur_spec.rb index a17c8b341..37917bf18 100644 --- a/spec/models/instructeur_spec.rb +++ b/spec/models/instructeur_spec.rb @@ -236,15 +236,16 @@ describe Instructeur, type: :model do end describe '#notifications_for_procedure' do - let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) } + let(:procedure) { create(:simple_procedure, :routee, :with_type_de_champ_private) } + let!(:dossier) { create(:dossier, :followed, groupe_instructeur: procedure.groupe_instructeurs.last, state: Dossier.states.fetch(:en_construction)) } let(:instructeur) { dossier.follows.first.instructeur } - let(:procedure) { dossier.procedure } - let!(:instructeur_2) { create(:instructeur, groupe_instructeurs: [procedure.defaut_groupe_instructeur]) } + let!(:instructeur_2) { create(:instructeur, groupe_instructeurs: [procedure.groupe_instructeurs.last]) } let!(:dossier_on_procedure_2) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) } let!(:instructeur_on_procedure_2) { dossier_on_procedure_2.follows.first.instructeur } before do + procedure.groupe_instructeurs.last.instructeurs << instructeur instructeur_2.followed_dossiers << dossier end