EQT instructeur, je peux supprimer un dossier terminé

This commit is contained in:
kara Diaby 2020-11-17 13:25:35 +01:00 committed by simon lehericey
parent f7f832bed8
commit 00b5ad7a10
18 changed files with 255 additions and 97 deletions

View file

@ -214,6 +214,17 @@ module Instructeurs
zipline(files, "dossier-#{dossier.id}.zip")
end
def delete_dossier
if dossier.termine?
dossier.deleted_by_instructeur_and_keep_track!(current_instructeur)
flash.notice = 'Le dossier a bien été supprimé'
redirect_to instructeur_procedure_path(procedure)
else
flash.alert = "Suppression impossible : le dossier n'est pas terminé"
redirect_back(fallback_location: instructeur_procedures_url)
end
end
private
def dossier

View file

@ -14,19 +14,12 @@ module Users
before_action :forbid_closed_submission!, only: [:update_brouillon]
before_action :show_demarche_en_test_banner
before_action :store_user_location!, only: :new
before_action :statut, only: :index
def index
@user_dossiers = current_user.dossiers.includes(:procedure).order_by_updated_at.page(page)
@dossiers_invites = current_user.dossiers_invites.includes(:procedure).order_by_updated_at.page(page)
@current_tab = current_tab(@user_dossiers.count, @dossiers_invites.count)
@dossiers = case @current_tab
when 'mes-dossiers'
@user_dossiers
when 'dossiers-invites'
@dossiers_invites
end
@dossiers_supprimes = DeletedDossier.where(user_id: current_user.id).order_by_updated_at.page(page)
end
def show
@ -282,6 +275,10 @@ module Users
private
def statut
@statut = params[:statut].blank? ? 'mes-dossiers' : params[:statut]
end
def store_user_location!
store_location_for(:user, request.fullpath)
end
@ -307,16 +304,6 @@ module Users
[params[:page].to_i, 1].max
end
def current_tab(mes_dossiers_count, dossiers_invites_count)
if dossiers_invites_count == 0
'mes-dossiers'
elsif mes_dossiers_count == 0
'dossiers-invites'
else
params[:current_tab].presence || 'mes-dossiers'
end
end
# FIXME: require(:dossier) when all the champs are united
def champs_params
params.permit(dossier: {

View file

@ -75,6 +75,20 @@ class DossierMailer < ApplicationMailer
mail(to: to_email, subject: @subject)
end
def notify_instructeur_deletion_to_user(deleted_dossier, to_email)
@subject = default_i18n_subject(dossier_id: deleted_dossier.dossier_id)
@deleted_dossier = deleted_dossier
mail(to: to_email, subject: @subject)
end
def notify_instructeur(deleted_dossier, to_email)
@subject = default_i18n_subject(dossier_id: deleted_dossier.dossier_id)
@deleted_dossier = deleted_dossier
mail(to: to_email, subject: @subject)
end
def notify_deletion_to_administration(deleted_dossier, to_email)
@subject = default_i18n_subject(dossier_id: deleted_dossier.dossier_id)
@deleted_dossier = deleted_dossier

View file

@ -19,12 +19,15 @@ class DeletedDossier < ApplicationRecord
validates :dossier_id, uniqueness: true
scope :order_by_updated_at, -> (order = :desc) { order(created_at: order) }
enum reason: {
user_request: 'user_request',
manager_request: 'manager_request',
user_removed: 'user_removed',
procedure_removed: 'procedure_removed',
expired: 'expired'
expired: 'expired',
instructeur_request: 'instructeur_request'
}
def self.create_from_dossier(dossier, reason)

View file

@ -520,6 +520,16 @@ class Dossier < ApplicationRecord
end
end
def deleted_by_instructeur_and_keep_track!(author)
if keep_track_on_deletion?
deleted_dossier = DeletedDossier.create_from_dossier(self, :instructeur_request)
self.delete_operations_logs
log_dossier_operation(author, :supprime_par_instructeur, self)
DossierMailer.notify_instructeur_deletion_to_user(deleted_dossier, user.email).deliver_later
self.destroy
end
end
def discard_and_keep_track!(author, reason)
if keep_track_on_deletion? && en_construction?
deleted_dossier = DeletedDossier.create_from_dossier(self, reason)
@ -797,6 +807,10 @@ class Dossier < ApplicationRecord
private
def delete_operations_logs
DossierOperationLog.where(dossier: self).destroy_all
end
def geo_areas
champs.includes(:geo_areas).flat_map(&:geo_areas) + champs_private.includes(:geo_areas).flat_map(&:geo_areas)
end

View file

@ -28,7 +28,8 @@ class DossierOperationLog < ApplicationRecord
modifier_annotation: 'modifier_annotation',
demander_un_avis: 'demander_un_avis',
archiver: 'archiver',
desarchiver: 'desarchiver'
desarchiver: 'desarchiver',
supprime_par_instructeur: 'supprime_par_instructeur'
}
has_one_attached :serialized
@ -58,7 +59,7 @@ class DossierOperationLog < ApplicationRecord
operation: operation_log.operation,
dossier_id: operation_log.dossier_id,
author: self.serialize_author(params[:author]),
subject: self.serialize_subject(params[:subject]),
subject: self.serialize_subject(params[:subject], operation_log.operation),
automatic_operation: operation_log.automatic_operation?,
executed_at: operation_log.executed_at.iso8601
}.compact.to_json
@ -84,9 +85,15 @@ class DossierOperationLog < ApplicationRecord
end
end
def self.serialize_subject(subject)
def self.serialize_subject(subject, operation = nil)
if subject.nil?
nil
elsif operation == "supprime_par_instructeur"
{
date_de_depot: subject.en_construction_at,
date_de_mise_en_instruction: subject.en_instruction_at,
date_de_decision: subject.traitements.last.processed_at
}.as_json
else
case subject
when Dossier

View file

@ -0,0 +1,9 @@
- content_for(:title, "#{@subject}")
%p
Bonjour,
%p
= t('.body', dossier_id: @deleted_dossier.dossier_id, procedure: @deleted_dossier.procedure.libelle)
= render partial: "layouts/mailers/signature"

View file

@ -105,3 +105,11 @@
.dropdown-description
%h4 Repasser en instruction
Lusager sera notifié que son dossier est réexaminé.
- if dossier.termine?
%li
= link_to supprimer_dossier_instructeur_dossier_path(dossier.procedure, dossier), method: :patch, data: { confirm: "Voulez vous vraiment supprimer le dossier #{dossier.id} ? Cette action est irréversible. \nNous vous suggérons de télécharger le dossier au format PDF au préalable." } do
%span.icon.refuse
.dropdown-description
%h4 Supprimer le dossier
Lusager sera notifié que son dossier sera supprimé.

View file

@ -0,0 +1,67 @@
- if dossiers.present?
%table.table.dossiers-table.hoverable
%thead
%tr
%th.number-col Nº dossier
%th Démarche
- if dossiers.present?
%th Demandeur
%th.status-col Statut
%th.updated-at-col Mis à jour
%th.sr-only Actions
%tbody
- dossiers.each do |dossier|
-# check if the dossier is deleted or not
- if dossier.try(:deleted_at).nil?
%tr{ data: { 'dossier-id': dossier.id } }
%td.number-col
= link_to(url_for_dossier(dossier), class: 'cell-link', tabindex: -1) do
%span.icon.folder
= dossier.id
%td
= link_to(url_for_dossier(dossier), class: 'cell-link') do
= procedure_libelle(dossier.procedure)
- if dossiers.present?
%td.cell-link
= demandeur_dossier(dossier)
%td.status-col
= status_badge(dossier.state)
%td.updated-at-col.cell-link
= try_format_date(dossier.updated_at)
%td.action-col
= render partial: 'dossier_actions', locals: { dossier: dossier }
- else
%tr{ data: { 'dossier-id': dossier.dossier_id } }
%td.number-col
= dossier.dossier_id
%td
= dossier.procedure_id
- if dossiers.present?
%td.cell-link
= dossier.reason
%td
= status_badge(dossier.state)
%td
= dossier.updated_at.strftime('%d/%m/%Y')
= paginate(dossiers)
- if current_user.feedbacks.empty? || current_user.feedbacks.last.created_at < 1.month.ago
#user-satisfaction
%h3 Que pensez-vous de la facilité d'utilisation de ce service ?
.icons
= link_to feedback_path(rating: Feedback.ratings.fetch(:unhappy)), data: { remote: true, method: :post } do
%span.icon.frown
= link_to feedback_path(rating: Feedback.ratings.fetch(:neutral)), data: { remote: true, method: :post } do
%span.icon.meh
= link_to feedback_path(rating: Feedback.ratings.fetch(:happy)), data: { remote: true, method: :post } do
%span.icon.smile
- else
.blank-tab
%h2.empty-text Aucun dossier.
%p.empty-text-details
Pour remplir une démarche, contactez votre administration en lui demandant le lien de la démarche.
%br
Celui ci doit ressembler à #{APPLICATION_BASE_URL}/commencer/xxx.

View file

@ -10,68 +10,33 @@
.container
- if @search_terms.present?
%h1.page-title Résultat de la recherche pour « #{@search_terms} »
- elsif @dossiers_invites.count == 0
%h1.page-title Mes dossiers
= render partial: "dossiers_list", locals: { dossiers: @dossiers }
- else
%h1.page-title Dossiers
%ul.tabs
= tab_item('mes dossiers',
dossiers_path(current_tab: 'mes-dossiers'),
active: @current_tab == 'mes-dossiers')
dossiers_path(statut: 'mes-dossiers'),
active: @statut == 'mes-dossiers',
badge: number_with_html_delimiter(@user_dossiers.count))
= tab_item('dossiers invités',
dossiers_path(current_tab: 'dossiers-invites'),
active: @current_tab == 'dossiers-invites')
dossiers_path(statut: 'dossiers-invites'),
active: @statut == 'dossiers-invites',
badge: number_with_html_delimiter(@dossiers_invites.count))
= tab_item('dossiers supprimés',
dossiers_path(statut: 'dossiers-supprimes'),
active: @statut == 'dossiers-supprimes',
badge: number_with_html_delimiter(@dossiers_supprimes.count))
.container
- if @dossiers.present?
%table.table.dossiers-table.hoverable
%thead
%tr
%th.number-col Nº dossier
%th Démarche
- if @dossiers.count > 1
%th Demandeur
%th.status-col Statut
%th.updated-at-col Mis à jour
%th.sr-only Actions
%tbody
- @dossiers.each do |dossier|
%tr{ data: { 'dossier-id': dossier.id } }
%td.number-col
= link_to(url_for_dossier(dossier), class: 'cell-link', tabindex: -1) do
%span.icon.folder
= dossier.id
%td
= link_to(url_for_dossier(dossier), class: 'cell-link') do
= procedure_libelle(dossier.procedure)
- if @dossiers.count > 1
%td.cell-link
= demandeur_dossier(dossier)
%td.status-col
= status_badge(dossier.state)
%td.updated-at-col.cell-link
= try_format_date(dossier.updated_at)
%td.action-col
= render partial: 'dossier_actions', locals: { dossier: dossier }
= paginate(@dossiers)
- if @statut === "mes-dossiers"
= render partial: "dossiers_list", locals: { dossiers: @user_dossiers }
- if current_user.feedbacks.empty? || current_user.feedbacks.last.created_at < 1.month.ago
#user-satisfaction
%h3 Que pensez-vous de la facilité d'utilisation de ce service ?
.icons
= link_to feedback_path(rating: Feedback.ratings.fetch(:unhappy)), data: { remote: true, method: :post } do
%span.icon.frown
= link_to feedback_path(rating: Feedback.ratings.fetch(:neutral)), data: { remote: true, method: :post } do
%span.icon.meh
= link_to feedback_path(rating: Feedback.ratings.fetch(:happy)), data: { remote: true, method: :post } do
%span.icon.smile
- if @statut === "dossiers-invites"
= render partial: "dossiers_list", locals: { dossiers: @dossiers_invites }
- else
.blank-tab
%h2.empty-text Aucun dossier.
%p.empty-text-details
Pour remplir une démarche, contactez votre administration en lui demandant le lien de la démarche.
%br
Celui ci doit ressembler à #{APPLICATION_BASE_URL}/commencer/xxx.
- if @statut === "dossiers-supprimes"
= render partial: "dossiers_list", locals: { dossiers: @dossiers_supprimes }