From aaf1bc0b99e2338f196e3efadb61ac5d48d19764 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 24 May 2018 15:55:47 +0200 Subject: [PATCH] [Fix #1931] User can ask support to delete dossier --- .../new_user/dossiers_controller.rb | 7 +++++ app/mailers/dossier_mailer.rb | 8 +++++ .../dossier_mailer/ask_deletion.html.haml | 12 ++++++++ ...ers_recapitulatifcontroller_show.html.haml | 6 ++++ config/routes.rb | 1 + .../new_user/dossiers_controller_spec.rb | 29 +++++++++++++++++++ 6 files changed, 63 insertions(+) create mode 100644 app/mailers/dossier_mailer.rb create mode 100644 app/views/dossier_mailer/ask_deletion.html.haml diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index b0a63fb8a..e05ce8a5f 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -98,6 +98,13 @@ module NewUser end 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) + end + private def page diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb new file mode 100644 index 000000000..68ef28d7c --- /dev/null +++ b/app/mailers/dossier_mailer.rb @@ -0,0 +1,8 @@ +class DossierMailer < ApplicationMailer + layout 'mailers/layout' + + def ask_deletion(dossier) + @dossier = dossier + mail(to: "contact@demarches-simplifiees.fr", subject: "Demande de suppression de dossier") + end +end diff --git a/app/views/dossier_mailer/ask_deletion.html.haml b/app/views/dossier_mailer/ask_deletion.html.haml new file mode 100644 index 000000000..a4d1cb5d8 --- /dev/null +++ b/app/views/dossier_mailer/ask_deletion.html.haml @@ -0,0 +1,12 @@ +- content_for(:title, 'Demande de suppression de dossier') + +%h1 Bonjour + +%p + Une demande de suppression a été effectuée pour le dossier + = @dossier.id + par l'utilisateur + = @dossier.user.email + \. +%p + Merci de le notifier quand cela est fait. diff --git a/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml b/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml index 1adb2c390..8f5502c44 100644 --- a/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml +++ b/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml @@ -13,3 +13,9 @@ .split-hr-left .dossier-state= @facade.dossier.display_state .split-hr-left + + .text-center.mt-1 + = link_to ask_deletion_dossier_path(@facade.dossier), method: :post, class:"btn btn-danger", data: { confirm: "Confirmez-vous la demande de suppression de ce dossier ?" } do + Demander la suppression + %br + du dossier diff --git a/config/routes.rb b/config/routes.rb index f4a174bb8..be4399b44 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -225,6 +225,7 @@ Rails.application.routes.draw do patch 'update_identite' get 'modifier' get 'merci' + post 'ask_deletion' end get 'attestation' end diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index af8dfd898..005d39287 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -384,4 +384,33 @@ describe NewUser::DossiersController, type: :controller do end end end + + describe '#ask_deletion' do + before { sign_in(user) } + + subject { post :ask_deletion, params: { id: dossier.id } } + + context 'when dossier is owned by signed in user' do + let(:dossier) { create(:dossier, user: user, autorisation_donnees: true) } + + it do + expect(DossierMailer).to receive(:ask_deletion).and_return(double(deliver_later: nil)) + subject + end + + it { is_expected.to redirect_to(users_dossier_recapitulatif_path(dossier)) } + end + + context 'when dossier is not owned by signed in user' do + let(:user2) { create(:user) } + let(:dossier) { create(:dossier, user: user2, autorisation_donnees: true) } + + it do + expect(DossierMailer).not_to receive(:ask_deletion) + subject + end + + it { is_expected.to redirect_to(root_path) } + end + end end