2019-08-06 11:02:54 +02:00
|
|
|
|
module Instructeurs
|
2017-06-29 15:31:29 +02:00
|
|
|
|
class DossiersController < ProceduresController
|
2017-12-01 12:57:01 +01:00
|
|
|
|
include ActionView::Helpers::NumberHelper
|
2017-11-29 17:11:50 +01:00
|
|
|
|
include ActionView::Helpers::TextHelper
|
2018-10-31 14:56:01 +01:00
|
|
|
|
include CreateAvisConcern
|
2019-07-11 11:37:59 +02:00
|
|
|
|
include DossierHelper
|
2017-11-29 17:11:50 +01:00
|
|
|
|
|
2019-07-01 15:55:37 +02:00
|
|
|
|
include ActionController::Streaming
|
|
|
|
|
include Zipline
|
|
|
|
|
|
2017-12-05 16:07:05 +01:00
|
|
|
|
after_action :mark_demande_as_read, only: :show
|
2017-12-05 17:20:10 +01:00
|
|
|
|
after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire]
|
2017-12-07 11:15:51 +01:00
|
|
|
|
after_action :mark_avis_as_read, only: [:avis, :create_avis]
|
2017-12-07 14:37:34 +01:00
|
|
|
|
after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations]
|
2017-12-05 16:07:05 +01:00
|
|
|
|
|
2017-06-29 15:31:29 +02:00
|
|
|
|
def attestation
|
2019-08-27 17:43:33 +02:00
|
|
|
|
if dossier.attestation.pdf_active_storage.attached?
|
|
|
|
|
redirect_to url_for(dossier.attestation.pdf_active_storage)
|
|
|
|
|
else
|
|
|
|
|
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
|
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-01-18 14:20:30 +01:00
|
|
|
|
def apercu_attestation
|
2019-08-28 16:33:51 +02:00
|
|
|
|
@title = dossier.procedure.attestation_template.title_for_dossier(dossier)
|
|
|
|
|
@body = dossier.procedure.attestation_template.body_for_dossier(dossier)
|
2019-08-27 17:44:02 +02:00
|
|
|
|
@footer = dossier.procedure.attestation_template.footer
|
|
|
|
|
@created_at = Time.zone.now
|
|
|
|
|
@logo = dossier.procedure.attestation_template&.proxy_logo
|
|
|
|
|
@signature = dossier.procedure.attestation_template&.proxy_signature
|
|
|
|
|
|
|
|
|
|
render 'admin/attestation_templates/show', formats: [:pdf]
|
2019-01-18 14:20:30 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
def show
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@demande_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.demande_seen_at
|
2017-07-06 16:33:36 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-19 11:08:53 +02:00
|
|
|
|
def messagerie
|
2017-10-30 17:21:05 +01:00
|
|
|
|
@commentaire = Commentaire.new
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@messagerie_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.messagerie_seen_at
|
2017-07-19 11:08:53 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-09-27 12:08:47 +02:00
|
|
|
|
def annotations_privees
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@annotations_privees_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.annotations_privees_seen_at
|
2017-07-19 16:53:31 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-09-26 14:38:16 +02:00
|
|
|
|
def avis
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@avis_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.avis_seen_at
|
2018-02-27 16:58:22 +01:00
|
|
|
|
@avis = Avis.new
|
2017-09-26 14:38:16 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-01 15:03:19 +01:00
|
|
|
|
def personnes_impliquees
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@following_instructeurs_emails = dossier.followers_instructeurs.pluck(:email)
|
|
|
|
|
previous_followers = dossier.previous_followers_instructeurs - dossier.followers_instructeurs
|
2019-06-07 16:45:43 +02:00
|
|
|
|
@previous_following_instructeurs_emails = previous_followers.pluck(:email)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@avis_emails = dossier.avis.includes(:instructeur).map(&:email_to_display)
|
2017-12-01 15:03:19 +01:00
|
|
|
|
@invites_emails = dossier.invites.map(&:email)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@potential_recipients = procedure.instructeurs.reject { |g| g == current_instructeur }
|
2018-01-30 19:11:07 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-09-10 17:52:49 +02:00
|
|
|
|
def send_to_instructeurs
|
2019-08-06 11:02:54 +02:00
|
|
|
|
recipients = Instructeur.find(params[:recipients])
|
2018-09-10 17:52:49 +02:00
|
|
|
|
|
|
|
|
|
recipients.each do |recipient|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
InstructeurMailer.send_dossier(current_instructeur, dossier, recipient).deliver_later
|
2018-09-10 17:52:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-01-30 19:11:07 +01:00
|
|
|
|
flash.notice = "Dossier envoyé"
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_to(personnes_impliquees_instructeur_dossier_path(procedure, dossier))
|
2017-12-01 15:03:19 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-11 15:45:20 +02:00
|
|
|
|
def follow
|
2019-08-06 11:02:54 +02:00
|
|
|
|
current_instructeur.follow(dossier)
|
2017-07-17 12:28:09 +02:00
|
|
|
|
flash.notice = 'Dossier suivi'
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_back(fallback_location: instructeur_procedures_url)
|
2017-07-11 15:45:20 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def unfollow
|
2019-08-06 11:02:54 +02:00
|
|
|
|
current_instructeur.unfollow(dossier)
|
2017-07-17 12:28:09 +02:00
|
|
|
|
flash.notice = "Vous ne suivez plus le dossier nº #{dossier.id}"
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_back(fallback_location: instructeur_procedures_url)
|
2017-07-11 15:45:20 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-11 15:56:23 +02:00
|
|
|
|
def archive
|
2018-03-02 16:27:03 +01:00
|
|
|
|
dossier.update(archived: true)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
current_instructeur.unfollow(dossier)
|
|
|
|
|
redirect_back(fallback_location: instructeur_procedures_url)
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def unarchive
|
2018-03-02 16:27:03 +01:00
|
|
|
|
dossier.update(archived: false)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_back(fallback_location: instructeur_procedures_url)
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:11:46 +01:00
|
|
|
|
def passer_en_instruction
|
2019-07-08 17:58:45 +02:00
|
|
|
|
if dossier.en_instruction?
|
|
|
|
|
flash.notice = 'Le dossier est déjà en instruction.'
|
|
|
|
|
else
|
2019-08-06 11:02:54 +02:00
|
|
|
|
dossier.passer_en_instruction!(current_instructeur)
|
2019-07-08 17:58:45 +02:00
|
|
|
|
flash.notice = 'Dossier passé en instruction.'
|
|
|
|
|
end
|
2017-11-30 17:11:46 +01:00
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
2017-11-30 17:11:46 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:18:06 +01:00
|
|
|
|
def repasser_en_construction
|
2019-07-11 11:47:37 +02:00
|
|
|
|
if dossier.en_construction?
|
|
|
|
|
flash.notice = 'Le dossier est déjà en construction.'
|
|
|
|
|
else
|
2019-08-06 11:02:54 +02:00
|
|
|
|
dossier.repasser_en_construction!(current_instructeur)
|
2019-07-11 11:47:37 +02:00
|
|
|
|
flash.notice = 'Dossier repassé en construction.'
|
|
|
|
|
end
|
2017-11-30 17:18:06 +01:00
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
2017-11-30 17:18:06 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-07-01 16:16:40 +02:00
|
|
|
|
def repasser_en_instruction
|
2019-07-11 11:52:24 +02:00
|
|
|
|
if dossier.en_instruction?
|
|
|
|
|
flash.notice = 'Le dossier est déjà en instruction.'
|
|
|
|
|
else
|
2019-07-30 10:12:57 +02:00
|
|
|
|
if dossier.accepte?
|
2019-07-30 08:42:22 +02:00
|
|
|
|
flash.notice = 'Il n’est pas possible de repasser un dossier accepté en instruction.'
|
2019-07-29 10:57:21 +02:00
|
|
|
|
else
|
|
|
|
|
flash.notice = "Le dossier #{dossier.id} a été repassé en instruction."
|
2019-08-06 11:02:54 +02:00
|
|
|
|
dossier.repasser_en_instruction!(current_instructeur)
|
2019-07-29 10:57:21 +02:00
|
|
|
|
end
|
2019-07-11 11:52:24 +02:00
|
|
|
|
end
|
2019-07-01 16:16:40 +02:00
|
|
|
|
|
|
|
|
|
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-01 12:57:01 +01:00
|
|
|
|
def terminer
|
2018-11-26 21:24:18 +01:00
|
|
|
|
motivation = params[:dossier] && params[:dossier][:motivation]
|
2019-02-18 17:52:15 +01:00
|
|
|
|
justificatif = params[:dossier] && params[:dossier][:justificatif_motivation]
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-07-11 11:37:59 +02:00
|
|
|
|
if dossier.termine?
|
|
|
|
|
flash.notice = "Le dossier est déjà #{dossier_display_state(dossier, lower: true)}"
|
|
|
|
|
else
|
|
|
|
|
case params[:process_action]
|
|
|
|
|
when "refuser"
|
2019-08-06 11:02:54 +02:00
|
|
|
|
dossier.refuser!(current_instructeur, motivation, justificatif)
|
2019-07-11 11:37:59 +02:00
|
|
|
|
flash.notice = "Dossier considéré comme refusé."
|
|
|
|
|
when "classer_sans_suite"
|
2019-08-06 11:02:54 +02:00
|
|
|
|
dossier.classer_sans_suite!(current_instructeur, motivation, justificatif)
|
2019-07-11 11:37:59 +02:00
|
|
|
|
flash.notice = "Dossier considéré comme sans suite."
|
|
|
|
|
when "accepter"
|
2019-08-06 11:02:54 +02:00
|
|
|
|
dossier.accepter!(current_instructeur, motivation, justificatif)
|
2019-07-11 11:37:59 +02:00
|
|
|
|
flash.notice = "Dossier traité avec succès."
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-19 14:04:49 +02:00
|
|
|
|
def create_commentaire
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@commentaire = CommentaireService.build(current_instructeur, dossier, commentaire_params)
|
2017-10-30 17:21:05 +01:00
|
|
|
|
|
|
|
|
|
if @commentaire.save
|
2019-08-06 11:02:54 +02:00
|
|
|
|
current_instructeur.follow(dossier)
|
2017-10-30 17:21:05 +01:00
|
|
|
|
flash.notice = "Message envoyé"
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_to messagerie_instructeur_dossier_path(procedure, dossier)
|
2017-10-30 17:21:05 +01:00
|
|
|
|
else
|
|
|
|
|
flash.alert = @commentaire.errors.full_messages
|
|
|
|
|
render :messagerie
|
|
|
|
|
end
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-28 14:16:13 +02:00
|
|
|
|
def create_avis
|
2018-10-31 14:56:01 +01:00
|
|
|
|
@avis = create_avis_from_params(dossier)
|
|
|
|
|
|
|
|
|
|
if @avis.nil?
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_to avis_instructeur_dossier_path(procedure, dossier)
|
2018-02-27 16:58:22 +01:00
|
|
|
|
else
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@avis_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.avis_seen_at
|
2018-02-27 16:58:22 +01:00
|
|
|
|
render :avis
|
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
def update_annotations
|
2019-08-06 11:02:54 +02:00
|
|
|
|
dossier = current_instructeur.dossiers.includes(champs_private: :type_de_champ).find(params[:dossier_id])
|
2018-03-02 16:27:03 +01:00
|
|
|
|
dossier.update(champs_private_params)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
dossier.modifier_annotations!(current_instructeur)
|
|
|
|
|
redirect_to annotations_privees_instructeur_dossier_path(procedure, dossier)
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-10-05 23:27:02 +02:00
|
|
|
|
def print
|
|
|
|
|
@dossier = dossier
|
|
|
|
|
render layout: "print"
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-01 15:55:37 +02:00
|
|
|
|
def telecharger_pjs
|
|
|
|
|
return head(:forbidden) if !Flipflop.download_as_zip_enabled? || !dossier.attachments_downloadable?
|
|
|
|
|
|
|
|
|
|
files = ActiveStorage::DownloadableFile.create_list_from_dossier(dossier)
|
|
|
|
|
|
|
|
|
|
zipline(files, "dossier-#{dossier.id}.zip")
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-29 15:31:29 +02:00
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def dossier
|
2019-08-06 11:02:54 +02:00
|
|
|
|
@dossier ||= current_instructeur.dossiers.find(params[:dossier_id])
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|
2017-07-19 14:04:49 +02:00
|
|
|
|
|
|
|
|
|
def commentaire_params
|
2019-06-25 17:12:44 +02:00
|
|
|
|
params.require(:commentaire).permit(:body, :piece_jointe)
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
def champs_private_params
|
2018-04-03 17:53:14 +02:00
|
|
|
|
params.require(:dossier).permit(champs_private_attributes: [
|
2019-03-25 11:08:41 +01:00
|
|
|
|
:id, :primary_value, :secondary_value, :piece_justificative_file, :value, value: [],
|
|
|
|
|
champs_attributes: [:id, :_destroy, :value, :primary_value, :secondary_value, :piece_justificative_file, value: []]
|
2018-04-03 17:53:14 +02:00
|
|
|
|
])
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2017-12-05 16:07:05 +01:00
|
|
|
|
def mark_demande_as_read
|
2019-08-06 11:02:54 +02:00
|
|
|
|
current_instructeur.mark_tab_as_seen(dossier, :demande)
|
2017-12-05 16:07:05 +01:00
|
|
|
|
end
|
2017-12-05 17:20:10 +01:00
|
|
|
|
|
|
|
|
|
def mark_messagerie_as_read
|
2019-08-06 11:02:54 +02:00
|
|
|
|
current_instructeur.mark_tab_as_seen(dossier, :messagerie)
|
2017-12-05 17:20:10 +01:00
|
|
|
|
end
|
2017-12-07 11:15:51 +01:00
|
|
|
|
|
|
|
|
|
def mark_avis_as_read
|
2019-08-06 11:02:54 +02:00
|
|
|
|
current_instructeur.mark_tab_as_seen(dossier, :avis)
|
2017-12-07 11:15:51 +01:00
|
|
|
|
end
|
2017-12-07 14:37:34 +01:00
|
|
|
|
|
|
|
|
|
def mark_annotations_privees_as_read
|
2019-08-06 11:02:54 +02:00
|
|
|
|
current_instructeur.mark_tab_as_seen(dossier, :annotations_privees)
|
2017-12-07 14:37:34 +01:00
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|
|
|
|
|
end
|