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

@ -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