dossiers: allow users to delete "en construction" dossiers

This commit is contained in:
Pierre de La Morinerie 2019-02-06 18:11:55 +00:00
parent d251ebc2f4
commit a6704c4cd6
4 changed files with 7 additions and 3 deletions

View file

@ -188,7 +188,7 @@ module NewUser
def ask_deletion
dossier = current_user.dossiers.includes(:user, procedure: :administrateur).find(params[:id])
if !dossier.instruction_commencee?
if dossier.can_be_deleted_by_user?
dossier.delete_and_keep_track
flash.notice = 'Votre dossier a bien été supprimé.'
redirect_to dossiers_path

View file

@ -170,6 +170,10 @@ class Dossier < ApplicationRecord
brouillon? || en_construction?
end
def can_be_deleted_by_user?
brouillon? || en_construction?
end
def retention_end_date
if instruction_commencee?
en_instruction_at + procedure.duree_conservation_dossiers_dans_ds.months

View file

@ -51,7 +51,7 @@
= link_to(url_for_dossier(dossier), class: 'cell-link') do
= dossier.updated_at.strftime("%d/%m/%Y")
%td.action-col.delete-col
- if dossier.brouillon?
- if dossier.can_be_deleted_by_user?
= link_to(ask_deletion_dossier_path(dossier), method: :post, class: 'button danger', data: { disable: true, confirm: "En continuant, vous allez supprimer ce dossier ainsi que les informations quil contient. Toute suppression entraine lannulation de la démarche en cours.\n\nConfirmer la suppression ?" }) do
%span.icon.delete
Supprimer

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe 'user access to the list of his dossier' do
let(:user) { create(:user) }
let!(:last_updated_dossier) { create(:dossier, :with_entreprise, user: user, state: Dossier.states.fetch(:en_construction)) }
let!(:dossier1) { create(:dossier, :with_entreprise, user: user, state: Dossier.states.fetch(:en_construction)) }
let!(:dossier1) { create(:dossier, :with_entreprise, user: user, state: Dossier.states.fetch(:en_instruction)) }
let!(:dossier2) { create(:dossier, :with_entreprise) }
let!(:dossier_brouillon) { create(:dossier, :with_entreprise, user: user) }
let!(:dossier_archived) { create(:dossier, :with_entreprise, user: user, state: Dossier.states.fetch(:en_construction)) }