Merge pull request #2335 from tchak/do-not-notify-draft-dossier-delete

Only notify on dossier supression if dossier is en_construction
This commit is contained in:
Paul Chavard 2018-08-02 17:24:55 +02:00 committed by GitHub
commit 8d829dc246
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View file

@ -291,9 +291,11 @@ class Dossier < ApplicationRecord
deleted_dossier = DeletedDossier.create!(dossier_id: id, procedure: procedure, state: state, deleted_at: now)
update(hidden_at: now)
administration_emails = followers_gestionnaires.present? ? followers_gestionnaires.pluck(:email) : [procedure.administrateur.email]
administration_emails.each do |email|
DossierMailer.notify_deletion_to_administration(deleted_dossier, email).deliver_later
if en_construction?
administration_emails = followers_gestionnaires.present? ? followers_gestionnaires.pluck(:email) : [procedure.administrateur.email]
administration_emails.each do |email|
DossierMailer.notify_deletion_to_administration(deleted_dossier, email).deliver_later
end
end
DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later
end

View file

@ -498,7 +498,7 @@ describe NewUser::DossiersController, type: :controller do
end
context 'when dossier is owned by signed in user' do
let(:dossier) { create(:dossier, user: user, autorisation_donnees: true) }
let(:dossier) { create(:dossier, :en_construction, user: user, autorisation_donnees: true) }
it do
expect(DossierMailer).to receive(:notify_deletion_to_administration).with(kind_of(DeletedDossier), dossier.procedure.administrateur.email).and_return(double(deliver_later: nil))

View file

@ -859,7 +859,7 @@ describe Dossier do
end
context 'where gestionnaires are following the dossier' do
let(:dossier) { create(:dossier, :followed) }
let(:dossier) { create(:dossier, :en_construction, :followed) }
let!(:non_following_gestionnaire) do
non_following_gestionnaire = create(:gestionnaire)
non_following_gestionnaire.procedures << dossier.procedure
@ -873,11 +873,19 @@ describe Dossier do
end
context 'when there are no following gestionnaires' do
let(:dossier) { create(:dossier, :en_construction) }
it 'notifies the procedure administrateur' do
expect(DossierMailer).to have_received(:notify_deletion_to_administration).once
expect(DossierMailer).to have_received(:notify_deletion_to_administration).with(deleted_dossier, dossier.procedure.administrateur.email)
end
end
context 'when dossier is brouillon' do
let(:dossier) { create(:dossier) }
it 'do not notifies the procedure administrateur' do
expect(DossierMailer).not_to have_received(:notify_deletion_to_administration)
end
end
end
describe 'webhook' do