diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb index 3be44c460..645bb559e 100644 --- a/app/mailers/dossier_mailer.rb +++ b/app/mailers/dossier_mailer.rb @@ -84,22 +84,11 @@ class DossierMailer < ApplicationMailer mail(to: to_email, subject: @subject) end - def notify_deletion_to_user(deleted_dossier, to_email) - I18n.with_locale(deleted_dossier.user_locale) do - @subject = default_i18n_subject(dossier_id: deleted_dossier.dossier_id) - @deleted_dossier = deleted_dossier + def notify_en_construction_deletion_to_administration(dossier, to_email) + @subject = default_i18n_subject(dossier_id: dossier.id) + @dossier = dossier - mail(to: to_email, subject: @subject) - end - end - - def notify_instructeur_deletion_to_user(deleted_dossier, to_email) - I18n.with_locale(deleted_dossier.user_locale) do - @subject = default_i18n_subject(libelle_demarche: deleted_dossier.procedure.libelle) - @deleted_dossier = deleted_dossier - - mail(to: to_email, subject: @subject) - end + mail(to: to_email, subject: @subject) end def notify_deletion_to_administration(deleted_dossier, to_email) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index d27fd4a1a..6e1a5adfc 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -774,7 +774,6 @@ class Dossier < ApplicationRecord update(hidden_by_user_at: Time.zone.now, dossier_transfer_id: nil) end - user_email = user_deleted? ? nil : user_email_for(:notification) deleted_dossier = nil transaction do @@ -797,14 +796,6 @@ class Dossier < ApplicationRecord DossierMailer.notify_deletion_to_administration(deleted_dossier, email).deliver_later end end - - if user_email.present? - if reason == :user_request - DossierMailer.notify_deletion_to_user(deleted_dossier, user_email).deliver_later - else - DossierMailer.notify_instructeur_deletion_to_user(deleted_dossier, user_email).deliver_later - end - end end end diff --git a/app/views/dossier_mailer/notify_deletion_to_user.html.haml b/app/views/dossier_mailer/notify_en_construction_deletion_to_administration.html.haml similarity index 57% rename from app/views/dossier_mailer/notify_deletion_to_user.html.haml rename to app/views/dossier_mailer/notify_en_construction_deletion_to_administration.html.haml index 55da5cfe9..330b22b1f 100644 --- a/app/views/dossier_mailer/notify_deletion_to_user.html.haml +++ b/app/views/dossier_mailer/notify_en_construction_deletion_to_administration.html.haml @@ -3,6 +3,6 @@ %p= t(:hello, scope: [:views, :shared, :greetings]) %p - = t('.body', dossier_id: @deleted_dossier.dossier_id, procedure: @deleted_dossier.procedure.libelle) + = t('.body', dossier_id: @dossier.id, procedure: @dossier.procedure.libelle) = render partial: "layouts/mailers/signature" diff --git a/app/views/dossier_mailer/notify_instructeur_deletion_to_user.html.haml b/app/views/dossier_mailer/notify_instructeur_deletion_to_user.html.haml deleted file mode 100644 index f1959341f..000000000 --- a/app/views/dossier_mailer/notify_instructeur_deletion_to_user.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -- content_for(:title, "#{@subject}") - -%p= t(:hello, scope: [:views, :shared, :greetings]) - -%p - = t('.body_html', dossier_id: @deleted_dossier.dossier_id, libelle_demarche: @deleted_dossier.procedure.libelle, deleted_dossiers_link: dossiers_url(statut: 'dossiers-supprimes')) - -= render partial: "layouts/mailers/signature" diff --git a/config/locales/views/dossier_mailer/notify_deletion_to_user/fr.yml b/config/locales/views/dossier_mailer/notify_deletion_to_user/fr.yml deleted file mode 100644 index ea104b332..000000000 --- a/config/locales/views/dossier_mailer/notify_deletion_to_user/fr.yml +++ /dev/null @@ -1,11 +0,0 @@ -fr: - dossier_mailer: - notify_deletion_to_user: - subject: Votre dossier nº %{dossier_id} a bien été supprimé - body: Votre dossier n° %{dossier_id} (%{procedure}) a bien été supprimé. Une trace de ce traitement sera conservée pour l’administration. - notify_instructeur_deletion_to_user: - subject: Votre dossier sur la démarche « %{libelle_demarche} » est supprimé - body_html: | - Afin de limiter la conservation de vos données personnelles, votre dossier n° %{dossier_id} concernant la démarche « %{libelle_demarche} » est supprimé.

- Cette suppression ne modifie pas le statut final (accepté, refusé ou sans suite) de votre dossier.

- Une trace de ce dossier est visible dans votre interface : %{deleted_dossiers_link}. diff --git a/config/locales/views/dossier_mailer/notify_en_construction_deletion_to_administration/fr.yml b/config/locales/views/dossier_mailer/notify_en_construction_deletion_to_administration/fr.yml new file mode 100644 index 000000000..1410878ec --- /dev/null +++ b/config/locales/views/dossier_mailer/notify_en_construction_deletion_to_administration/fr.yml @@ -0,0 +1,5 @@ +fr: + dossier_mailer: + notify_en_construction_deletion_to_administration: + subject: Le dossier nº %{dossier_id} a été supprimé à la demande de l’usager + body: À la demande de l’usager, le dossier n° %{dossier_id} (%{procedure}) a été supprimé. diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index e4c6463a7..336afd076 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -766,7 +766,6 @@ describe Instructeurs::DossiersController, type: :controller do before do dossier.accepter!(instructeur: instructeur, motivation: "le dossier est correct") dossier.update!(hidden_by_user_at: Time.zone.now.beginning_of_day.utc) - allow(DossierMailer).to receive(:notify_instructeur_deletion_to_user).and_return(double(deliver_later: nil)) subject end @@ -775,10 +774,6 @@ describe Instructeurs::DossiersController, type: :controller do expect(DossierOperationLog.where(dossier_id: dossier.id).last.operation).to eq('supprimer') end - it 'send an email to the user' do - expect(DossierMailer).to have_received(:notify_instructeur_deletion_to_user).with(DeletedDossier.where(dossier_id: dossier.id).first, dossier.user.email) - end - it 'add a record into deleted_dossiers table' do expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(1) expect(DeletedDossier.where(dossier_id: dossier.id).first.revision_id).to eq(dossier.revision_id) @@ -794,7 +789,6 @@ describe Instructeurs::DossiersController, type: :controller do context 'when the instructeur want to delete a dossier with a decision and not hidden by user' do before do dossier.accepter!(instructeur: instructeur, motivation: "le dossier est correct") - allow(DossierMailer).to receive(:notify_instructeur_deletion_to_user).and_return(double(deliver_later: nil)) subject end @@ -803,10 +797,6 @@ describe Instructeurs::DossiersController, type: :controller do expect(DossierOperationLog.where(dossier_id: dossier.id).last.operation).not_to eq('supprimer') end - it 'does not send an email to the user' do - expect(DossierMailer).not_to have_received(:notify_instructeur_deletion_to_user).with(DeletedDossier.where(dossier_id: dossier.id).first, dossier.user.email) - end - it 'add a record into deleted_dossiers table' do expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(0) end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 5d278d665..855e64790 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -1008,7 +1008,6 @@ describe Users::DossiersController, type: :controller do shared_examples_for "the dossier can not be deleted" do it "doesn’t notify the deletion" do expect(DossierMailer).not_to receive(:notify_deletion_to_administration) - expect(DossierMailer).not_to receive(:notify_deletion_to_user) subject end @@ -1024,7 +1023,6 @@ describe Users::DossiersController, type: :controller do it "notifies the user and the admin of the deletion" do expect(DossierMailer).to receive(:notify_deletion_to_administration).with(kind_of(DeletedDossier), dossier.procedure.administrateurs.first.email).and_return(double(deliver_later: nil)) - expect(DossierMailer).to receive(:notify_deletion_to_user).with(kind_of(DeletedDossier), dossier.user.email).and_return(double(deliver_later: nil)) subject end diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index 87e4bcdca..31d3ab633 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -60,16 +60,11 @@ RSpec.describe DossierMailer, type: :mailer do it { expect(subject.perform_deliveries).to be_falsy } end - describe '.notify_deletion_to_user' do - let(:deleted_dossier) { build(:deleted_dossier) } + def notify_deletion_to_administration(deleted_dossier, to_email) + @subject = default_i18n_subject(dossier_id: deleted_dossier.dossier_id) + @deleted_dossier = deleted_dossier - subject { described_class.notify_deletion_to_user(deleted_dossier, to_email) } - - it { expect(subject.subject).to eq("Votre dossier nº #{deleted_dossier.dossier_id} a bien été supprimé") } - it { expect(subject.body).to include("Votre dossier") } - it { expect(subject.body).to include(deleted_dossier.dossier_id) } - it { expect(subject.body).to include("a bien été supprimé") } - it { expect(subject.body).to include(deleted_dossier.procedure.libelle) } + mail(to: to_email, subject: @subject) end describe '.notify_deletion_to_administration' do diff --git a/spec/mailers/previews/dossier_mailer_preview.rb b/spec/mailers/previews/dossier_mailer_preview.rb index c85c0e6e0..739989da3 100644 --- a/spec/mailers/previews/dossier_mailer_preview.rb +++ b/spec/mailers/previews/dossier_mailer_preview.rb @@ -45,10 +45,6 @@ class DossierMailerPreview < ActionMailer::Preview DossierMailer.notify_brouillon_deletion(dossier_hashes, usager_email) end - def notify_deletion_to_user - DossierMailer.notify_deletion_to_user(deleted_dossier, usager_email) - end - def notify_instructeur_deletion_to_user DossierMailer.notify_instructeur_deletion_to_user(deleted_dossier, usager_email) end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 1ca7ecb43..62bee0e85 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -799,7 +799,6 @@ describe Dossier do let(:reason) { :user_request } before do - allow(DossierMailer).to receive(:notify_deletion_to_user).and_return(double(deliver_later: nil)) allow(DossierMailer).to receive(:notify_deletion_to_administration).and_return(double(deliver_later: nil)) end @@ -835,10 +834,6 @@ describe Dossier do expect(deleted_dossier.deleted_at).to be_present end - it 'notifies the user' do - expect(DossierMailer).to have_received(:notify_deletion_to_user).with(deleted_dossier, dossier.user.email) - end - it 'records the operation in the log' do expect(last_operation.operation).to eq("supprimer") expect(last_operation.automatic_operation?).to be_falsey