Merge pull request #2102 from betagouv/dossier_deletion_done_right
Dossier deletion done right
This commit is contained in:
commit
150cc4a636
8 changed files with 72 additions and 30 deletions
|
@ -101,11 +101,15 @@ module NewUser
|
||||||
|
|
||||||
def ask_deletion
|
def ask_deletion
|
||||||
dossier = current_user.dossiers.includes(:user, procedure: :administrateur).find(params[:id])
|
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
|
if !dossier.instruction_commencee?
|
||||||
DossierMailer.notify_deletion_to_administration(deleted_dossier, dossier.procedure.administrateur.email).deliver_later
|
dossier.delete_and_keep_track
|
||||||
flash.notice = 'Votre dossier a bien été supprimé.'
|
flash.notice = 'Votre dossier a bien été supprimé.'
|
||||||
redirect_to users_dossiers_path
|
redirect_to users_dossiers_path
|
||||||
|
else
|
||||||
|
flash.notice = "L'instruction de votre dossier a commencé, il n'est plus possible de supprimer votre dossier. Si vous souhaitez annuler l'instruction contactez votre administration par la messagerie de votre dossier."
|
||||||
|
redirect_to users_dossier_path(dossier)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -14,14 +14,4 @@ module DossierHelper
|
||||||
"highlighted"
|
"highlighted"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_dossier_confirm(dossier)
|
|
||||||
message = ["Vous vous apprêtez à supprimer votre dossier ainsi que les informations qu’il contient."]
|
|
||||||
if dossier.en_construction_ou_instruction?
|
|
||||||
message << "Nous vous rappelons que toute suppression entraine l’annulation de la démarche en cours."
|
|
||||||
end
|
|
||||||
message << "Confirmer la suppression ?"
|
|
||||||
|
|
||||||
message.join(" ")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,4 +14,11 @@ class DossierMailer < ApplicationMailer
|
||||||
|
|
||||||
mail(to: to_email, subject: subject)
|
mail(to: to_email, subject: subject)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notify_unhide_to_user(dossier)
|
||||||
|
@dossier = dossier
|
||||||
|
subject = "Votre dossier n° #{@dossier.id} n'a pas pu être supprimé"
|
||||||
|
|
||||||
|
mail(to: dossier.user.email, subject: subject)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,6 +44,7 @@ class Dossier < ApplicationRecord
|
||||||
scope :state_en_construction, -> { where(state: 'en_construction') }
|
scope :state_en_construction, -> { where(state: 'en_construction') }
|
||||||
scope :state_en_instruction, -> { where(state: 'en_instruction') }
|
scope :state_en_instruction, -> { where(state: 'en_instruction') }
|
||||||
scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) }
|
scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) }
|
||||||
|
scope :state_instruction_commencee, -> { where(state: INSTRUCTION_COMMENCEE) }
|
||||||
scope :state_termine, -> { where(state: TERMINE) }
|
scope :state_termine, -> { where(state: TERMINE) }
|
||||||
|
|
||||||
scope :archived, -> { where(archived: true) }
|
scope :archived, -> { where(archived: true) }
|
||||||
|
@ -126,6 +127,10 @@ class Dossier < ApplicationRecord
|
||||||
TERMINE.include?(state)
|
TERMINE.include?(state)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def instruction_commencee?
|
||||||
|
INSTRUCTION_COMMENCEE.include?(state)
|
||||||
|
end
|
||||||
|
|
||||||
def cerfa_available?
|
def cerfa_available?
|
||||||
procedure.cerfa_flag? && cerfa.size != 0
|
procedure.cerfa_flag? && cerfa.size != 0
|
||||||
end
|
end
|
||||||
|
@ -276,7 +281,8 @@ class Dossier < ApplicationRecord
|
||||||
now = Time.now
|
now = Time.now
|
||||||
deleted_dossier = DeletedDossier.create!(dossier_id: id, procedure: procedure, state: state, deleted_at: now)
|
deleted_dossier = DeletedDossier.create!(dossier_id: id, procedure: procedure, state: state, deleted_at: now)
|
||||||
update(hidden_at: now)
|
update(hidden_at: now)
|
||||||
deleted_dossier
|
DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later
|
||||||
|
DossierMailer.notify_deletion_to_administration(deleted_dossier, procedure.administrateur.email).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
13
app/views/dossier_mailer/notify_unhide_to_user.html.haml
Normal file
13
app/views/dossier_mailer/notify_unhide_to_user.html.haml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
- content_for(:title, "Votre dossier n° #{@dossier.id} n'a pas pu être supprimé")
|
||||||
|
|
||||||
|
%h1 Bonjour,
|
||||||
|
|
||||||
|
%p
|
||||||
|
L'instruction de votre dossier n° #{@dossier.id} ayant commencé, il n'a pas pu être supprimé.
|
||||||
|
Le dossier a été rétabli dans votre tableau de bord.
|
||||||
|
|
||||||
|
%p
|
||||||
|
Bonne journée,
|
||||||
|
|
||||||
|
%p
|
||||||
|
L'équipe demarches-simplifiees.fr
|
|
@ -14,9 +14,9 @@
|
||||||
.dossier-state= @facade.dossier.display_state
|
.dossier-state= @facade.dossier.display_state
|
||||||
.split-hr-left
|
.split-hr-left
|
||||||
|
|
||||||
- if current_user.owns?(@facade.dossier)
|
- if current_user.owns?(@facade.dossier) && !@facade.dossier.instruction_commencee?
|
||||||
.text-center.mt-1
|
.text-center.mt-1
|
||||||
= link_to ask_deletion_dossier_path(@facade.dossier), method: :post, class: "btn btn-danger", data: { confirm: delete_dossier_confirm(@facade.dossier) } do
|
= link_to ask_deletion_dossier_path(@facade.dossier), method: :post, class: "btn btn-danger", data: { confirm: "Vous vous apprêtez à supprimer votre dossier ainsi que les informations qu’il contient. Nous vous rappelons que toute suppression entraine l’annulation de la démarche en cours. Confirmer la suppression ?" } do
|
||||||
Supprimer définitivement
|
Supprimer définitivement
|
||||||
%br
|
%br
|
||||||
ce dossier
|
ce dossier
|
||||||
|
|
11
lib/tasks/2018_06_13_unhide_dossiers.rake
Normal file
11
lib/tasks/2018_06_13_unhide_dossiers.rake
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
namespace :'2018_06_13_unhide_dossiers' do
|
||||||
|
task run: :environment do
|
||||||
|
Dossier.unscoped.where.not(hidden_at: nil).state_instruction_commencee.each do |d|
|
||||||
|
if !d.procedure.nil? # ensure the procedure was not deleted by administrateur for testing
|
||||||
|
d.update(hidden_at: nil)
|
||||||
|
DeletedDossier.find_by(dossier_id: d.id)&.destroy
|
||||||
|
DossierMailer.notify_unhide_to_user(d).deliver_later
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -412,6 +412,20 @@ describe NewUser::DossiersController, type: :controller do
|
||||||
|
|
||||||
subject { post :ask_deletion, params: { id: dossier.id } }
|
subject { post :ask_deletion, params: { id: dossier.id } }
|
||||||
|
|
||||||
|
shared_examples_for "the dossier can not be deleted" do
|
||||||
|
it do
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
context 'when dossier is owned by signed in user' do
|
context 'when dossier is owned by signed in user' do
|
||||||
let(:dossier) { create(:dossier, user: user, autorisation_donnees: true) }
|
let(:dossier) { create(:dossier, user: user, autorisation_donnees: true) }
|
||||||
|
|
||||||
|
@ -429,25 +443,22 @@ describe NewUser::DossiersController, type: :controller do
|
||||||
expect(procedure.deleted_dossiers.count).to eq(1)
|
expect(procedure.deleted_dossiers.count).to eq(1)
|
||||||
expect(procedure.deleted_dossiers.first.dossier_id).to eq(dossier_id)
|
expect(procedure.deleted_dossiers.first.dossier_id).to eq(dossier_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to redirect_to(users_dossiers_path) }
|
it { is_expected.to redirect_to(users_dossiers_path) }
|
||||||
|
|
||||||
|
context "and the instruction has started" do
|
||||||
|
let(:dossier) { create(:dossier, :en_instruction, user: user, autorisation_donnees: true) }
|
||||||
|
|
||||||
|
it_behaves_like "the dossier can not be deleted"
|
||||||
|
it { is_expected.to redirect_to(users_dossier_path(dossier)) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when dossier is not owned by signed in user' do
|
context 'when dossier is not owned by signed in user' do
|
||||||
let(:user2) { create(:user) }
|
let(:user2) { create(:user) }
|
||||||
let(:dossier) { create(:dossier, user: user2, autorisation_donnees: true) }
|
let(:dossier) { create(:dossier, user: user2, autorisation_donnees: true) }
|
||||||
|
|
||||||
it do
|
it_behaves_like "the dossier can not be deleted"
|
||||||
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) }
|
it { is_expected.to redirect_to(root_path) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue