2024-04-29 00:17:15 +02:00
# frozen_string_literal: true
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
2023-03-01 18:30:10 +01:00
include TurboChampsConcern
2017-11-29 17:11:50 +01:00
2019-07-01 15:55:37 +02:00
include ActionController :: Streaming
include Zipline
2022-05-17 09:53:34 +02:00
before_action :redirect_on_dossier_not_found , only : :show
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
before_action :redirect_on_dossier_in_batch_operation , only : [ :archive , :unarchive , :follow , :unfollow , :passer_en_instruction , :repasser_en_construction , :repasser_en_instruction , :terminer , :restore , :destroy , :extend_conservation ]
2024-09-13 19:07:32 +02:00
before_action :set_gallery_attachments , only : [ :show , :pieces_jointes , :annotations_privees , :avis , :messagerie , :personnes_impliquees , :reaffectation ]
2017-12-05 16:07:05 +01:00
after_action :mark_demande_as_read , only : :show
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
2023-04-13 19:10:09 +02:00
after_action :mark_messagerie_as_read , only : [ :messagerie , :create_commentaire , :pending_correction ]
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 ]
2024-09-10 16:09:43 +02:00
after_action :mark_pieces_jointes_as_read , only : [ :pieces_jointes ]
2017-12-05 16:07:05 +01:00
2021-12-03 16:09:51 +01:00
def extend_conservation
2024-07-23 15:06:23 +02:00
dossier . extend_conservation ( 1 . month )
2021-12-03 16:09:51 +01:00
flash [ :notice ] = t ( 'views.instructeurs.dossiers.archived_dossier' )
redirect_back ( fallback_location : instructeur_dossier_path ( @dossier . procedure , @dossier ) )
end
2024-07-23 15:06:23 +02:00
def extend_conservation_and_restore
dossier . extend_conservation_and_restore ( 1 . month , current_instructeur )
2024-07-25 14:40:22 +02:00
flash [ :notice ] = t ( 'views.instructeurs.dossiers.archived_dossier' )
redirect_back ( fallback_location : instructeur_dossier_path ( @dossier . procedure , @dossier ) )
2024-07-23 15:06:23 +02:00
end
2020-04-30 15:49:43 +02:00
def geo_data
send_data dossier . to_feature_collection . to_json ,
type : 'application/json' ,
filename : " dossier- #{ dossier . id } -features.json "
end
2019-01-18 14:20:30 +01:00
def apercu_attestation
2024-05-29 23:00:34 +02:00
send_data dossier . attestation_template . send ( :build_pdf , dossier ) ,
filename : 'attestation.pdf' ,
type : 'application/pdf' ,
disposition : 'inline'
2019-01-18 14:20:30 +01:00
end
2020-04-30 11:25:22 +02:00
def bilans_bdf
2020-06-04 12:32:09 +02:00
extension = params [ :format ]
render extension . to_sym = > dossier . etablissement . entreprise_bilans_bdf_to_sheet ( extension )
2020-04-30 11:25:22 +02:00
end
2017-07-06 16:33:36 +02:00
def show
2022-03-11 00:17:36 +01:00
@demande_seen_at = current_instructeur . follows . find_by ( dossier : dossier_with_champs ) & . demande_seen_at
2022-12-01 12:15:29 +01:00
@is_dossier_in_batch_operation = dossier . batch_operation . present?
2019-12-15 22:09:23 +01:00
respond_to do | format |
format . pdf do
2024-03-08 17:14:21 +01:00
@acls = PiecesJustificativesService . new ( user_profile : current_instructeur , export_template : nil ) . acl_for_dossier_export ( dossier . procedure )
2021-02-17 19:02:31 +01:00
render ( template : 'dossiers/show' , formats : [ :pdf ] )
2019-12-15 22:09:23 +01:00
end
format . all
end
2017-07-06 16:33:36 +02:00
end
2024-10-01 15:17:09 +02:00
def dossier_labels
2024-10-29 14:52:14 +01:00
labels = params [ :label_id ] & . map ( & :to_i ) || [ ]
2024-10-01 15:17:09 +02:00
@dossier = dossier
2024-10-29 14:52:14 +01:00
labels . each { | params_label | DossierLabel . find_or_create_by ( dossier_id : @dossier . id , label_id : params_label ) }
2024-10-01 15:17:09 +02:00
2024-10-29 14:52:14 +01:00
all_labels = DossierLabel . where ( dossier_id : @dossier . id ) . pluck ( :label_id )
2024-10-01 15:17:09 +02:00
2024-10-29 14:52:14 +01:00
( all_labels - labels ) . each { DossierLabel . find_by ( dossier_id : @dossier . id , label_id : _1 ) . destroy }
2024-10-01 15:17:09 +02:00
render :change_state
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
2024-04-16 11:12:32 +02:00
@experts_emails = Expert . autocomplete_mails ( @dossier . procedure )
2017-09-26 14:38:16 +02:00
end
2023-03-10 18:39:26 +01:00
def avis_new
@avis_seen_at = current_instructeur . follows . find_by ( dossier : dossier ) & . avis_seen_at
@avis = Avis . new
2024-04-16 11:12:32 +02:00
@experts_emails = Expert . autocomplete_mails ( @dossier . procedure )
2023-03-10 18:39:26 +01:00
end
2017-12-01 15:03:19 +01:00
def personnes_impliquees
2023-08-24 10:32:12 +02:00
# sort following_instructeurs (last follower on top) for the API of Agence de l'Eau Loire-Bretagne
@following_instructeurs_emails = dossier . followers_instructeurs . joins ( :follows ) . merge ( Follow . order ( id : :desc ) ) . map ( & :email )
2019-08-06 11:02:54 +02:00
previous_followers = dossier . previous_followers_instructeurs - dossier . followers_instructeurs
2019-10-15 18:32:18 +02:00
@previous_following_instructeurs_emails = previous_followers . map ( & :email )
2021-02-25 09:53:09 +01:00
@avis_emails = dossier . experts . map ( & :email )
2017-12-01 15:03:19 +01:00
@invites_emails = dossier . invites . map ( & :email )
2019-10-24 15:07:52 +02:00
@potential_recipients = dossier . groupe_instructeur . instructeurs . reject { | g | g == current_instructeur }
2023-07-13 16:47:55 +02:00
@manual_assignments = dossier . dossier_assignments . manual . includes ( :groupe_instructeur , :previous_groupe_instructeur )
2018-01-30 19:11:07 +01:00
end
2018-09-10 17:52:49 +02:00
def send_to_instructeurs
2024-05-15 23:16:55 +02:00
recipients = params [ 'recipients' ] . presence || [ ]
2023-01-17 16:33:48 +01:00
# instructeurs are scoped by groupe_instructeur to avoid enumeration
2024-05-15 23:16:55 +02:00
recipients = dossier . groupe_instructeur . instructeurs . where ( id : recipients )
2018-09-10 17:52:49 +02:00
2023-01-17 16:33:48 +01:00
if recipients . present?
recipients . each do | recipient |
recipient . follow ( dossier )
InstructeurMailer . send_dossier ( current_instructeur , dossier , recipient ) . deliver_later
end
flash . notice = " Dossier envoyé "
else
flash . alert = " Instructeur inconnu ou non présent sur la procédure "
2018-09-10 17:52:49 +02:00
end
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'
2022-03-11 13:55:36 +01:00
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
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 } "
2022-03-11 13:55:36 +01:00
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
2017-07-11 15:45:20 +02:00
end
2017-07-11 15:56:23 +02:00
def archive
2020-09-09 15:04:58 +02:00
dossier . archiver! ( current_instructeur )
2022-03-11 13:55:36 +01:00
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
2017-07-11 15:56:23 +02:00
end
def unarchive
2022-11-30 12:39:47 +01:00
dossier . desarchiver!
2022-03-11 13:55:36 +01:00
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
2017-07-11 15:56:23 +02:00
end
2017-11-30 17:11:46 +01:00
def passer_en_instruction
2019-12-19 13:25:32 +01:00
begin
2021-11-26 12:19:40 +01:00
dossier . passer_en_instruction! ( instructeur : current_instructeur )
2019-07-08 17:58:45 +02:00
flash . notice = 'Dossier passé en instruction.'
2019-12-19 13:25:32 +01:00
rescue AASM :: InvalidTransition = > e
flash . alert = aasm_error_message ( e , target_state : :en_instruction )
2019-07-08 17:58:45 +02:00
end
2017-11-30 17:11:46 +01:00
2022-05-06 11:59:28 +02:00
@dossier = dossier
2023-02-24 15:48:29 +01:00
respond_to do | format |
format . turbo_stream do
render :change_state
end
format . html do
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
end
end
2017-11-30 17:11:46 +01:00
end
2017-11-30 17:18:06 +01:00
def repasser_en_construction
2019-12-19 13:25:32 +01:00
begin
2022-12-04 12:34:34 +01:00
dossier . repasser_en_construction! ( instructeur : current_instructeur )
2019-07-11 11:47:37 +02:00
flash . notice = 'Dossier repassé en construction.'
2019-12-19 13:25:32 +01:00
rescue AASM :: InvalidTransition = > e
flash . alert = aasm_error_message ( e , target_state : :en_construction )
2019-07-11 11:47:37 +02:00
end
2017-11-30 17:18:06 +01:00
2022-05-06 11:59:28 +02:00
@dossier = dossier
2023-02-24 15:48:29 +01:00
respond_to do | format |
format . turbo_stream do
render :change_state
end
format . html do
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
end
end
2017-11-30 17:18:06 +01:00
end
2019-07-01 16:16:40 +02:00
def repasser_en_instruction
2019-12-19 13:25:32 +01:00
begin
2019-10-02 11:29:30 +02:00
flash . notice = " Le dossier #{ dossier . id } a été repassé en instruction. "
2021-11-26 12:19:40 +01:00
dossier . repasser_en_instruction! ( instructeur : current_instructeur )
2019-12-19 13:25:32 +01:00
rescue AASM :: InvalidTransition = > e
flash . alert = aasm_error_message ( e , target_state : :en_instruction )
2019-07-11 11:52:24 +02:00
end
2019-07-01 16:16:40 +02:00
2022-05-06 11:59:28 +02:00
@dossier = dossier
2023-02-24 15:48:29 +01:00
respond_to do | format |
format . turbo_stream do
render :change_state
end
format . html do
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
end
end
2019-07-01 16:16:40 +02:00
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
2021-11-26 12:19:40 +01:00
h = { instructeur : current_instructeur , motivation : motivation , justificatif : justificatif }
2019-12-19 13:25:32 +01:00
begin
2019-07-11 11:37:59 +02:00
case params [ :process_action ]
when " refuser "
2019-12-19 13:25:32 +01:00
target_state = :refuse
2021-11-26 12:19:40 +01:00
dossier . refuser! ( h )
2019-07-11 11:37:59 +02:00
flash . notice = " Dossier considéré comme refusé. "
when " classer_sans_suite "
2019-12-19 13:25:32 +01:00
target_state = :sans_suite
2021-11-26 12:19:40 +01:00
dossier . classer_sans_suite! ( h )
2019-07-11 11:37:59 +02:00
flash . notice = " Dossier considéré comme sans suite. "
when " accepter "
2019-12-19 13:25:32 +01:00
target_state = :accepte
2021-11-26 12:19:40 +01:00
dossier . accepter! ( h )
2019-07-11 11:37:59 +02:00
flash . notice = " Dossier traité avec succès. "
end
2019-12-19 13:25:32 +01:00
rescue AASM :: InvalidTransition = > e
flash . alert = aasm_error_message ( e , target_state : target_state )
2017-12-01 12:57:01 +01:00
end
2022-05-06 11:59:28 +02:00
@dossier = dossier
render :change_state
2017-12-01 12:57:01 +01:00
end
2023-04-13 19:10:09 +02:00
def pending_correction
2023-03-14 17:23:17 +01:00
message , piece_jointe = params . require ( :dossier ) . permit ( :motivation , :justificatif_motivation ) . values
if message . empty?
2023-04-13 19:10:09 +02:00
flash . alert = " Vous devez préciser quelle correction est attendue. "
2023-03-14 17:23:17 +01:00
elsif ! dossier . may_flag_as_pending_correction?
flash . alert = dossier . termine? ? " Impossible de demander de corriger un dossier terminé. " : " Le dossier est déjà en attente de correction. "
else
2023-03-14 18:48:19 +01:00
commentaire = CommentaireService . build ( current_instructeur , dossier , { body : message , piece_jointe : } )
2023-03-14 17:23:17 +01:00
2023-06-02 12:43:08 +02:00
if commentaire . valid?
2023-07-12 12:00:52 +02:00
dossier . flag_as_pending_correction! ( commentaire , params [ :reason ] . presence )
2023-06-02 12:43:08 +02:00
dossier . update! ( last_commentaire_updated_at : Time . zone . now )
current_instructeur . follow ( dossier )
flash . notice = " Dossier marqué comme en attente de correction. "
else
flash . alert = commentaire . errors . full_messages . map { " Commentaire : #{ _1 } " }
end
2023-03-14 17:23:17 +01:00
end
respond_to do | format |
format . turbo_stream do
@dossier = dossier
render :change_state
end
format . html do
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
end
end
end
2017-07-19 14:04:49 +02:00
def create_commentaire
2021-11-30 18:56:12 +01:00
@commentaire = CommentaireService . create ( current_instructeur , dossier , commentaire_params )
2017-10-30 17:21:05 +01:00
2021-11-30 18:56:12 +01:00
if @commentaire . errors . empty?
2020-07-22 16:34:33 +02:00
@commentaire . dossier . update! ( last_commentaire_updated_at : Time . zone . now )
2021-04-07 19:09:43 +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
2024-02-13 08:09:58 +01:00
@commentaire . piece_jointe . purge . reload
2017-10-30 17:21:05 +01:00
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
2021-02-25 09:53:09 +01:00
@avis = create_avis_from_params ( dossier , current_instructeur )
2018-10-31 14:56:01 +01:00
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
2024-05-13 16:53:33 +02:00
dossier_with_champs . update_champs_attributes ( champs_private_attributes_params , :private , updated_by : current_user . email )
2024-03-28 12:42:29 +01:00
if dossier . champs . any? ( & :changed_for_autosave? )
2020-07-22 17:11:33 +02:00
dossier . last_champ_private_updated_at = Time . zone . now
end
2023-10-26 16:02:23 +02:00
dossier . save ( context : :champs_private_value )
2024-04-25 18:48:14 +02:00
dossier . index_search_terms_later
2022-05-07 17:49:27 +02:00
respond_to do | format |
2023-03-01 18:30:10 +01:00
format . turbo_stream do
2024-03-27 11:39:15 +01:00
@to_show , @to_hide , @to_update = champs_to_turbo_update ( champs_private_attributes_params , dossier . champs . filter ( & :private? ) )
2023-03-01 18:30:10 +01:00
end
2022-05-07 17:49:27 +02:00
end
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
2023-05-30 11:39:53 +02:00
def annotation
@dossier = dossier_with_champs ( pj_template : false )
2024-03-28 12:42:29 +01:00
type_de_champ = @dossier . find_type_de_champ_by_stable_id ( params [ :stable_id ] , :private )
annotation = @dossier . project_champ ( type_de_champ , params [ :row_id ] )
2023-05-30 11:39:53 +02:00
respond_to do | format |
format . turbo_stream do
@to_show , @to_hide = [ ]
@to_update = [ annotation ]
render :update_annotations
end
end
end
2019-07-01 15:55:37 +02:00
def telecharger_pjs
2024-02-07 17:33:34 +01:00
files = ActiveStorage :: DownloadableFile . create_list_from_dossiers ( dossiers : Dossier . where ( id : dossier . id ) , user_profile : current_instructeur )
2022-09-05 11:20:30 +02:00
cleaned_files = ActiveStorage :: DownloadableFile . cleanup_list_from_dossier ( files )
2019-07-01 15:55:37 +02:00
2022-09-05 11:20:30 +02:00
zipline ( cleaned_files , " dossier- #{ dossier . id } .zip " )
2019-07-01 15:55:37 +02:00
end
2022-03-11 13:57:09 +01:00
def destroy
2020-11-17 13:25:35 +01:00
if dossier . termine?
2022-03-09 10:27:43 +01:00
dossier . hide_and_keep_track! ( current_instructeur , :instructeur_request )
2021-12-06 11:00:29 +01:00
flash . notice = t ( 'instructeurs.dossiers.deleted_by_instructeur' )
2020-11-17 13:25:35 +01:00
else
2021-12-06 11:00:29 +01:00
flash . alert = t ( 'instructeurs.dossiers.impossible_deletion' )
2022-03-11 13:57:09 +01:00
end
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
end
def restore
dossier = current_instructeur . dossiers . find ( params [ :dossier_id ] )
dossier . restore ( current_instructeur )
flash . notice = t ( 'instructeurs.dossiers.restore' )
if dossier . termine?
redirect_to instructeur_procedure_path ( procedure , statut : :traites )
else
redirect_back ( fallback_location : instructeur_procedure_path ( procedure ) )
2020-11-17 13:25:35 +01:00
end
end
2023-05-17 14:49:20 +02:00
def reaffectation
@dossier = current_instructeur . dossiers . find ( params [ :dossier_id ] )
@groupe_instructeur = @dossier . groupe_instructeur
@groupes_instructeurs = Kaminari . paginate_array ( @groupe_instructeur . other_groupe_instructeurs )
. page ( params [ :page ] )
. per ( ITEMS_PER_PAGE )
end
def reaffecter
2023-05-17 14:02:44 +02:00
dossier = current_instructeur . dossiers . find ( params [ :dossier_id ] )
new_group = dossier
. procedure
. groupe_instructeurs . find ( params [ :groupe_instructeur_id ] )
2023-07-05 17:48:18 +02:00
dossier . assign_to_groupe_instructeur ( new_group , DossierAssignment . modes . fetch ( :manual ) , current_instructeur )
2023-05-17 14:02:44 +02:00
flash . notice = t ( 'instructeurs.dossiers.reaffectation' , dossier_id : dossier . id , label : new_group . label )
redirect_to instructeur_procedure_path ( procedure )
end
2024-04-08 10:23:07 +02:00
def pieces_jointes
2024-09-16 09:14:54 +02:00
@dossier = dossier
2024-09-11 22:01:09 +02:00
@pieces_jointes_seen_at = current_instructeur . follows . find_by ( dossier : dossier ) & . pieces_jointes_seen_at
2024-04-08 10:23:07 +02:00
end
2017-06-29 15:31:29 +02:00
private
2022-05-07 17:49:27 +02:00
def dossier_scope
if action_name == 'update_annotations'
Dossier
. where ( id : current_instructeur . dossiers . visible_by_administration )
. or ( Dossier . where ( id : current_user . dossiers . for_procedure_preview ) )
2024-07-25 14:40:22 +02:00
elsif action_name == 'extend_conservation_and_restore'
2024-06-11 15:54:54 +02:00
Dossier
. where ( id : current_instructeur . dossiers . visible_by_administration )
2024-06-12 16:32:42 +02:00
. or ( Dossier . where ( id : current_instructeur . dossiers . hidden_by_expired ) )
2022-05-07 17:49:27 +02:00
else
current_instructeur . dossiers . visible_by_administration
end
end
2017-06-29 15:31:29 +02:00
def dossier
2023-03-15 18:25:12 +01:00
@dossier || = DossierPreloader . load_one ( dossier_scope . find ( params [ :dossier_id ] ) ) . tap do
set_sentry_dossier ( _1 )
end
2022-03-11 00:17:36 +01:00
end
def dossier_with_champs
2023-01-10 13:55:48 +01:00
@dossier || = DossierPreloader . load_one ( dossier_scope . find ( params [ :dossier_id ] ) )
2017-06-29 15:31:29 +02:00
end
2017-07-19 14:04:49 +02:00
def commentaire_params
2024-02-13 08:09:58 +01: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
2024-03-27 11:39:15 +01:00
champ_attributes = [
:id ,
:value ,
:value_other ,
:external_id ,
2024-05-06 21:44:41 +02:00
:code ,
2024-03-27 11:39:15 +01:00
:primary_value ,
:secondary_value ,
:numero_allocataire ,
:code_postal ,
:identifiant ,
:numero_fiscal ,
:reference_avis ,
:ine ,
:piece_justificative_file ,
:code_departement ,
:accreditation_number ,
:accreditation_birthdate ,
:feature ,
value : [ ]
]
# Strong attributes do not support records (indexed hash); they only support hashes with
# static keys. We create a static hash based on the available keys.
public_ids = params . dig ( :dossier , :champs_private_attributes ) & . keys || [ ]
champs_private_attributes = public_ids . map { [ _1 , champ_attributes ] } . to_h
params . require ( :dossier ) . permit ( champs_private_attributes : )
end
def champs_private_attributes_params
champs_private_params . fetch ( :champs_private_attributes )
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
2022-03-18 11:28:18 +01: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
2022-03-18 11:28:18 +01: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
2022-03-18 11:28:18 +01: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
2022-03-18 11:28:18 +01:00
current_instructeur . mark_tab_as_seen ( dossier , :annotations_privees )
2017-12-07 14:37:34 +01:00
end
2019-12-19 13:25:32 +01:00
2024-09-10 16:09:43 +02:00
def mark_pieces_jointes_as_read
current_instructeur . mark_tab_as_seen ( dossier , :pieces_jointes )
end
2019-12-19 13:25:32 +01:00
def aasm_error_message ( exception , target_state : )
if exception . originating_state == target_state
" Le dossier est déjà #{ dossier_display_state ( target_state , lower : true ) } . "
2023-01-18 18:31:37 +01:00
elsif exception . failures . include? ( :can_terminer? ) && dossier . any_etablissement_as_degraded_mode?
2022-09-21 15:05:54 +02:00
" Les données relatives au SIRET de ce dossier n’ ont pas pu encore être vérifiées : il n’ est pas possible de le passer #{ dossier_display_state ( target_state , lower : true ) } . "
2019-12-19 13:25:32 +01:00
else
" Le dossier est en ce moment #{ dossier_display_state ( exception . originating_state , lower : true ) } : il n’ est pas possible de le passer #{ dossier_display_state ( target_state , lower : true ) } . "
end
end
2022-05-17 09:53:34 +02:00
def redirect_on_dossier_not_found
2022-05-07 17:49:27 +02:00
if ! dossier_scope . exists? ( id : params [ :dossier_id ] )
2022-05-17 09:53:34 +02:00
redirect_to instructeur_procedure_path ( procedure )
end
end
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
def redirect_on_dossier_in_batch_operation
dossier_in_batch = begin
dossier
rescue ActiveRecord :: RecordNotFound
current_instructeur . dossiers . find ( params [ :dossier_id ] )
end
if dossier_in_batch . batch_operation . present?
2022-12-01 12:15:29 +01:00
flash . alert = " Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse. "
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
redirect_back ( fallback_location : instructeur_dossier_path ( procedure , dossier_in_batch ) )
end
end
2024-09-13 19:07:32 +02:00
def set_gallery_attachments
2024-09-16 08:42:41 +02:00
gallery_attachments_ids = Rails . cache . fetch ( [ dossier , " gallery_attachments " ] , expires_in : 10 . minutes ) do
champs_attachments_ids = dossier
. champs
. where ( type : [ Champs :: PieceJustificativeChamp . name , Champs :: TitreIdentiteChamp . name ] )
. flat_map ( & :piece_justificative_file )
. map ( & :id )
commentaires_attachments_ids = dossier
. commentaires
. includes ( piece_jointe_attachments : :blob )
. map ( & :piece_jointe )
2024-10-09 17:41:46 +02:00
. flat_map ( & :attachments )
2024-09-16 08:42:41 +02:00
. map ( & :id )
2024-10-09 17:41:46 +02:00
avis_attachments_ids = dossier
. avis . flat_map { [ _1 . introduction_file , _1 . piece_justificative_file ] }
. flat_map ( & :attachments )
. compact
. map ( & :id )
2024-10-10 11:17:02 +02:00
justificatif_motivation_id = dossier
. justificatif_motivation
& . attachment
& . id
champs_attachments_ids + commentaires_attachments_ids + avis_attachments_ids + [ justificatif_motivation_id ]
2024-09-16 08:42:41 +02:00
end
@gallery_attachments = ActiveStorage :: Attachment . where ( id : gallery_attachments_ids )
2024-09-13 19:07:32 +02:00
end
2017-06-29 15:31:29 +02:00
end
end