Delete button, notify user and admin then delete dossier
This commit is contained in:
parent
55a3d59e38
commit
eb1fbb7dbc
8 changed files with 69 additions and 22 deletions
|
@ -99,10 +99,12 @@ module NewUser
|
|||
end
|
||||
|
||||
def ask_deletion
|
||||
@dossier = current_user.dossiers.find(params[:id])
|
||||
DossierMailer.ask_deletion(@dossier).deliver_later
|
||||
flash.notice = 'Une demande de suppression de votre dossier a été envoyée, elle sera traitée dans les plus brefs délais.'
|
||||
redirect_to users_dossier_recapitulatif_path(@dossier)
|
||||
dossier = current_user.dossiers.includes(:user, procedure: :administrateur).find(params[:id])
|
||||
deleted_dossier = dossier.delete_and_keep_track
|
||||
DossierMailer.notify_deletion_to_user(deleted_dossier, dossier.user.email).deliver_later
|
||||
DossierMailer.notify_deletion_to_administration(deleted_dossier, dossier.procedure.administrateur.email).deliver_later
|
||||
flash.notice = 'Votre dossier a bien été supprimé.'
|
||||
redirect_to users_dossiers_path
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
class DossierMailer < ApplicationMailer
|
||||
layout 'mailers/layout'
|
||||
|
||||
def ask_deletion(dossier)
|
||||
@dossier = dossier
|
||||
mail(to: "contact@demarches-simplifiees.fr", subject: "Demande de suppression de dossier")
|
||||
def notify_deletion_to_user(deleted_dossier, to_email)
|
||||
@deleted_dossier = deleted_dossier
|
||||
mail(to: to_email, subject: "Votre dossier n° #{@deleted_dossier.dossier_id} a bien été supprimé")
|
||||
end
|
||||
|
||||
def notify_deletion_to_administration(deleted_dossier, to_email)
|
||||
@deleted_dossier = deleted_dossier
|
||||
mail(to: to_email, subject: "Le dossier n° #{@deleted_dossier.dossier_id} a été supprimé à la demande de l'usager")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -272,6 +272,13 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def delete_and_keep_track
|
||||
now = Time.now
|
||||
deleted_dossier = DeletedDossier.create!(dossier_id: id, procedure: procedure, state: state, deleted_at: now)
|
||||
update(hidden_at: now)
|
||||
deleted_dossier
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_state_dates
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
- content_for(:title, 'Demande de suppression de dossier')
|
||||
|
||||
%h1 Bonjour
|
||||
|
||||
%p
|
||||
Une demande de suppression a été effectuée pour le dossier #{@dossier.id}
|
||||
(état : #{@dossier.state})
|
||||
par l'utilisateur #{@dossier.user.email}.
|
||||
%p
|
||||
Merci de le notifier quand cela est fait.
|
|
@ -0,0 +1,11 @@
|
|||
- content_for(:title, "Suppression du dossier n° #{@deleted_dossier.dossier_id}")
|
||||
|
||||
%h1 Bonjour,
|
||||
|
||||
%p
|
||||
À la demande de l'usager le dossier n° #{@deleted_dossier.dossier_id} a été supprimé.
|
||||
%br
|
||||
Bonne journée,
|
||||
%br
|
||||
%br
|
||||
L'équipe demarches-simplifiees.fr
|
12
app/views/dossier_mailer/notify_deletion_to_user.html.haml
Normal file
12
app/views/dossier_mailer/notify_deletion_to_user.html.haml
Normal file
|
@ -0,0 +1,12 @@
|
|||
- content_for(:title, "Suppression du dossier n° #{@deleted_dossier.dossier_id}")
|
||||
|
||||
%h1 Bonjour,
|
||||
|
||||
%p
|
||||
Votre dossier n° #{@deleted_dossier.dossier_id} a bien été supprimé.
|
||||
Une trace anonyme de ce traitement sera conservée pour l’administration.
|
||||
%br
|
||||
Bonne journée,
|
||||
%br
|
||||
%br
|
||||
L'équipe demarches-simplifiees.fr
|
|
@ -394,11 +394,20 @@ describe NewUser::DossiersController, type: :controller do
|
|||
let(:dossier) { create(:dossier, user: user, autorisation_donnees: true) }
|
||||
|
||||
it do
|
||||
expect(DossierMailer).to receive(:ask_deletion).and_return(double(deliver_later: nil))
|
||||
expect(DossierMailer).to receive(:notify_deletion_to_administration).with(kind_of(DeletedDossier), dossier.procedure.administrateur.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
|
||||
|
||||
it { is_expected.to redirect_to(users_dossier_recapitulatif_path(dossier)) }
|
||||
it do
|
||||
procedure = dossier.procedure
|
||||
dossier_id = dossier.id
|
||||
subject
|
||||
expect(Dossier.find_by(id: dossier_id)).to eq(nil)
|
||||
expect(procedure.deleted_dossiers.count).to eq(1)
|
||||
expect(procedure.deleted_dossiers.first.dossier_id).to eq(dossier_id)
|
||||
end
|
||||
it { is_expected.to redirect_to(users_dossiers_path) }
|
||||
end
|
||||
|
||||
context 'when dossier is not owned by signed in user' do
|
||||
|
@ -406,10 +415,17 @@ describe NewUser::DossiersController, type: :controller do
|
|||
let(:dossier) { create(:dossier, user: user2, autorisation_donnees: true) }
|
||||
|
||||
it do
|
||||
expect(DossierMailer).not_to receive(:ask_deletion)
|
||||
expect(DossierMailer).not_to receive(:notify_deletion_to_administration)
|
||||
expect(DossierMailer).not_to receive(:notify_deletion_to_user)
|
||||
subject
|
||||
end
|
||||
|
||||
it do
|
||||
subject
|
||||
expect(Dossier.find_by(id: dossier.id)).not_to eq(nil)
|
||||
expect(dossier.procedure.deleted_dossiers.count).to eq(0)
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
# Preview all emails at http://localhost:3000/rails/mailers/dossier_mailer
|
||||
class DossierMailerPreview < ActionMailer::Preview
|
||||
def ask_deletion
|
||||
DossierMailer.ask_deletion(Dossier.last)
|
||||
def notify_deletion_to_user
|
||||
DossierMailer.notify_deletion_to_user(DeletedDossier.last, "user@ds.fr")
|
||||
end
|
||||
|
||||
def notify_deletion_to_administration
|
||||
DossierMailer.notify_deletion_to_administration(DeletedDossier.last, "admin@ds.fr")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue