commit
bf3c05d729
14 changed files with 110 additions and 28 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
|
||||
|
|
|
@ -14,4 +14,12 @@ 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 ?"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
3
app/models/deleted_dossier.rb
Normal file
3
app/models/deleted_dossier.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class DeletedDossier < ApplicationRecord
|
||||
belongs_to :procedure
|
||||
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
|
||||
|
|
|
@ -3,6 +3,7 @@ class Procedure < ApplicationRecord
|
|||
has_many :types_de_champ, -> { public_only }, dependent: :destroy
|
||||
has_many :types_de_champ_private, -> { private_only }, class_name: 'TypeDeChamp', dependent: :destroy
|
||||
has_many :dossiers
|
||||
has_many :deleted_dossiers, dependent: :destroy
|
||||
|
||||
has_one :module_api_carto, dependent: :destroy
|
||||
has_one :attestation_template, dependent: :destroy
|
||||
|
|
|
@ -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
|
|
@ -14,8 +14,9 @@
|
|||
.dossier-state= @facade.dossier.display_state
|
||||
.split-hr-left
|
||||
|
||||
- if @facade.dossier.user == current_user
|
||||
.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
|
||||
= link_to ask_deletion_dossier_path(@facade.dossier), method: :post, class: "btn btn-danger", data: { confirm: delete_dossier_confirm(@facade.dossier) } do
|
||||
Supprimer définitivement
|
||||
%br
|
||||
du dossier
|
||||
ce dossier
|
||||
|
|
12
db/migrate/20180530095508_create_deleted_dossiers.rb
Normal file
12
db/migrate/20180530095508_create_deleted_dossiers.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class CreateDeletedDossiers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :deleted_dossiers do |t|
|
||||
t.references :procedure
|
||||
t.bigint :dossier_id
|
||||
t.datetime :deleted_at
|
||||
t.string :state
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
12
db/schema.rb
12
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_05_22_142109) do
|
||||
ActiveRecord::Schema.define(version: 2018_05_30_095508) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -220,6 +220,16 @@ ActiveRecord::Schema.define(version: 2018_05_22_142109) do
|
|||
t.index ["priority", "run_at"], name: "delayed_jobs_priority"
|
||||
end
|
||||
|
||||
create_table "deleted_dossiers", force: :cascade do |t|
|
||||
t.bigint "procedure_id"
|
||||
t.bigint "dossier_id"
|
||||
t.datetime "deleted_at"
|
||||
t.string "state"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["procedure_id"], name: "index_deleted_dossiers_on_procedure_id"
|
||||
end
|
||||
|
||||
create_table "dossiers", id: :serial, force: :cascade do |t|
|
||||
t.boolean "autorisation_donnees"
|
||||
t.integer "procedure_id"
|
||||
|
|
|
@ -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