feat(instructeurs/dossier#create_avis): only followed dossier receive notifications, so when an instructeur ask for an avis, he follows the dossier

Update app/controllers/concerns/create_avis_concern.rb

Co-authored-by: Paul Chavard <paul.chavard@beta.gouv.fr>

Update spec/controllers/instructeurs/dossiers_controller_spec.rb

Co-authored-by: Paul Chavard <paul.chavard@beta.gouv.fr>
This commit is contained in:
Martin 2022-04-06 15:05:03 +02:00 committed by mfo
parent a9769ae277
commit 9bac5c65ba
2 changed files with 4 additions and 1 deletions

View file

@ -17,6 +17,9 @@ module CreateAvisConcern
allowed_dossiers += dossier.linked_dossiers_for(instructeur_or_expert)
end
if (instructeur_or_expert.is_a?(Instructeur)) && !instructeur_or_expert.follows.exists?(dossier: dossier)
instructeur_or_expert.follow(dossier)
end
create_results = Avis.create(
expert_emails.flat_map do |email|
user = User.create_or_promote_to_expert(email, SecureRandom.hex)