Allow dossier deletion if instruction has not started
This commit is contained in:
parent
e588195001
commit
e05fb2d0ae
5 changed files with 40 additions and 29 deletions
|
@ -101,11 +101,17 @@ module NewUser
|
|||
|
||||
def ask_deletion
|
||||
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
|
||||
|
||||
if !dossier.instruction_commencee?
|
||||
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
|
||||
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
|
||||
|
||||
private
|
||||
|
|
|
@ -14,14 +14,4 @@ module DossierHelper
|
|||
"highlighted"
|
||||
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
|
||||
|
|
|
@ -126,6 +126,10 @@ class Dossier < ApplicationRecord
|
|||
TERMINE.include?(state)
|
||||
end
|
||||
|
||||
def instruction_commencee?
|
||||
INSTRUCTION_COMMENCEE.include?(state)
|
||||
end
|
||||
|
||||
def cerfa_available?
|
||||
procedure.cerfa_flag? && cerfa.size != 0
|
||||
end
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
.dossier-state= @facade.dossier.display_state
|
||||
.split-hr-left
|
||||
|
||||
- if current_user.owns?(@facade.dossier)
|
||||
- if current_user.owns?(@facade.dossier) && !@facade.dossier.instruction_commencee?
|
||||
.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
|
||||
%br
|
||||
ce dossier
|
||||
|
|
|
@ -412,6 +412,20 @@ describe NewUser::DossiersController, type: :controller do
|
|||
|
||||
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
|
||||
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.first.dossier_id).to eq(dossier_id)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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(: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_behaves_like "the dossier can not be deleted"
|
||||
it { is_expected.to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue