2019-08-06 11:02:54 +02:00
|
|
|
|
module Instructeurs
|
|
|
|
|
class ProceduresController < InstructeurController
|
2017-07-03 14:05:55 +02:00
|
|
|
|
before_action :ensure_ownership!, except: [:index]
|
2022-07-21 15:27:21 +02:00
|
|
|
|
before_action :ensure_not_super_admin!, only: [:download_export]
|
2017-07-03 14:05:55 +02:00
|
|
|
|
|
2017-10-05 13:28:24 +02:00
|
|
|
|
ITEMS_PER_PAGE = 25
|
2017-09-27 15:16:07 +02:00
|
|
|
|
|
2017-07-03 14:05:55 +02:00
|
|
|
|
def index
|
2019-09-16 14:04:18 +02:00
|
|
|
|
@procedures = current_instructeur
|
2019-09-17 15:07:58 +02:00
|
|
|
|
.procedures
|
2020-04-22 15:16:21 +02:00
|
|
|
|
.kept
|
2019-09-17 11:11:08 +02:00
|
|
|
|
.with_attached_logo
|
|
|
|
|
.includes(:defaut_groupe_instructeur)
|
2019-12-18 13:28:29 +01:00
|
|
|
|
.order(closed_at: :desc, unpublished_at: :desc, published_at: :desc, created_at: :desc)
|
2017-07-03 14:05:55 +02:00
|
|
|
|
|
2022-04-04 15:49:16 +02:00
|
|
|
|
dossiers = current_instructeur.dossiers
|
|
|
|
|
.joins(groupe_instructeur: :procedure)
|
|
|
|
|
.where(procedures: { hidden_at: nil })
|
2022-03-09 10:27:43 +01:00
|
|
|
|
dossiers_visibles = dossiers.visible_by_administration
|
|
|
|
|
@dossiers_count_per_procedure = dossiers_visibles.all_state.group('groupe_instructeurs.procedure_id').reorder(nil).count
|
|
|
|
|
@dossiers_a_suivre_count_per_procedure = dossiers_visibles.without_followers.en_cours.group('groupe_instructeurs.procedure_id').reorder(nil).count
|
|
|
|
|
@dossiers_archived_count_per_procedure = dossiers_visibles.archived.group('groupe_instructeurs.procedure_id').count
|
|
|
|
|
@dossiers_termines_count_per_procedure = dossiers_visibles.termine.group('groupe_instructeurs.procedure_id').reorder(nil).count
|
|
|
|
|
@dossiers_expirant_count_per_procedure = dossiers_visibles.termine_or_en_construction_close_to_expiration.group('groupe_instructeurs.procedure_id').count
|
2022-01-27 17:01:09 +01:00
|
|
|
|
@dossiers_supprimes_recemment_count_per_procedure = dossiers.hidden_by_administration.group('groupe_instructeurs.procedure_id').reorder(nil).count
|
2017-07-03 14:05:55 +02:00
|
|
|
|
|
2022-03-09 10:27:43 +01:00
|
|
|
|
groupe_ids = current_instructeur.groupe_instructeurs.pluck(:id)
|
2019-09-12 17:26:59 +02:00
|
|
|
|
@followed_dossiers_count_per_procedure = current_instructeur
|
2017-07-17 11:22:12 +02:00
|
|
|
|
.followed_dossiers
|
2019-09-12 17:26:59 +02:00
|
|
|
|
.joins(:groupe_instructeur)
|
2017-07-17 11:22:12 +02:00
|
|
|
|
.en_cours
|
2019-09-12 17:26:59 +02:00
|
|
|
|
.where(groupe_instructeur_id: groupe_ids)
|
2022-03-09 10:27:43 +01:00
|
|
|
|
.visible_by_administration
|
2019-09-12 17:26:59 +02:00
|
|
|
|
.group('groupe_instructeurs.procedure_id')
|
2017-07-17 11:22:12 +02:00
|
|
|
|
.reorder(nil)
|
|
|
|
|
.count
|
2020-06-25 15:19:54 +02:00
|
|
|
|
|
2020-09-10 12:10:38 +02:00
|
|
|
|
@all_dossiers_counts = {
|
2022-04-13 15:44:22 +02:00
|
|
|
|
t('.to_follow') => @dossiers_a_suivre_count_per_procedure.sum { |_, v| v },
|
|
|
|
|
t('.followed') => @followed_dossiers_count_per_procedure.sum { |_, v| v },
|
|
|
|
|
t('.processed') => @dossiers_termines_count_per_procedure.sum { |_, v| v },
|
|
|
|
|
t('.all') => @dossiers_count_per_procedure.sum { |_, v| v },
|
|
|
|
|
t('.dossiers_close_to_expiration') => @dossiers_expirant_count_per_procedure.sum { |_, v| v },
|
|
|
|
|
t('.archived') => @dossiers_archived_count_per_procedure.sum { |_, v| v },
|
|
|
|
|
t('.dossiers_supprimes_recemment') => @dossiers_supprimes_recemment_count_per_procedure.sum { |_, v| v }
|
2020-09-10 12:10:38 +02:00
|
|
|
|
}
|
2020-09-10 21:03:50 +02:00
|
|
|
|
|
|
|
|
|
@procedure_ids_en_cours_with_notifications = current_instructeur.procedure_ids_with_notifications(:en_cours)
|
|
|
|
|
@procedure_ids_termines_with_notifications = current_instructeur.procedure_ids_with_notifications(:termine)
|
2017-07-03 14:05:55 +02:00
|
|
|
|
end
|
2017-06-29 15:30:42 +02:00
|
|
|
|
|
2017-07-11 16:09:03 +02:00
|
|
|
|
def show
|
|
|
|
|
@procedure = procedure
|
2018-10-03 14:46:12 +02:00
|
|
|
|
# Technically, procedure_presentation already sets the attribute.
|
|
|
|
|
# Setting it here to make clear that it is used by the view
|
|
|
|
|
@procedure_presentation = procedure_presentation
|
2017-10-02 17:03:38 +02:00
|
|
|
|
|
2020-10-30 11:33:45 +01:00
|
|
|
|
@current_filters = current_filters
|
2022-06-14 07:46:12 +02:00
|
|
|
|
@displayable_fields_for_select, @displayable_fields_selected = procedure_presentation.displayable_fields_for_select
|
|
|
|
|
@filterable_fields_for_select = procedure_presentation.filterable_fields_options
|
2022-03-31 18:28:12 +02:00
|
|
|
|
@counts = current_instructeur
|
2021-04-09 09:32:10 +02:00
|
|
|
|
.dossiers_count_summary(groupe_instructeur_ids)
|
2022-03-31 18:28:12 +02:00
|
|
|
|
.symbolize_keys
|
2022-07-28 15:12:24 +02:00
|
|
|
|
@can_download_dossiers = (@counts[:tous] + @counts[:archives]) > 0 && !instructeur_as_manager?
|
2021-04-09 09:32:10 +02:00
|
|
|
|
|
2022-03-09 10:27:43 +01:00
|
|
|
|
dossiers = Dossier.where(groupe_instructeur_id: groupe_instructeur_ids)
|
2022-04-06 17:08:22 +02:00
|
|
|
|
dossiers_count = @counts[statut.underscore.to_sym]
|
2017-07-11 16:09:03 +02:00
|
|
|
|
|
2022-03-31 16:33:14 +02:00
|
|
|
|
@followed_dossiers_id = current_instructeur
|
2017-07-11 16:09:03 +02:00
|
|
|
|
.followed_dossiers
|
|
|
|
|
.en_cours
|
2022-03-31 16:33:14 +02:00
|
|
|
|
.merge(dossiers.visible_by_administration)
|
|
|
|
|
.pluck(:id)
|
2017-07-11 15:40:09 +02:00
|
|
|
|
|
2021-04-07 18:03:03 +02:00
|
|
|
|
notifications = current_instructeur.notifications_for_groupe_instructeurs(groupe_instructeur_ids)
|
|
|
|
|
@has_en_cours_notifications = notifications[:en_cours].present?
|
|
|
|
|
@has_termine_notifications = notifications[:termines].present?
|
|
|
|
|
@not_archived_notifications_dossier_ids = notifications[:en_cours] + notifications[:termines]
|
2020-09-14 13:52:28 +02:00
|
|
|
|
|
2022-04-06 17:08:22 +02:00
|
|
|
|
filtered_sorted_ids = procedure_presentation.filtered_sorted_ids(dossiers, statut, count: dossiers_count)
|
2017-09-28 11:04:18 +02:00
|
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
|
page = params[:page].presence || 1
|
2017-09-27 15:16:07 +02:00
|
|
|
|
|
2022-04-06 17:08:22 +02:00
|
|
|
|
@dossiers_count = filtered_sorted_ids.size
|
2021-04-25 21:29:31 +02:00
|
|
|
|
@filtered_sorted_paginated_ids = Kaminari
|
2017-09-28 11:04:18 +02:00
|
|
|
|
.paginate_array(filtered_sorted_ids)
|
2017-09-27 15:16:07 +02:00
|
|
|
|
.page(page)
|
|
|
|
|
.per(ITEMS_PER_PAGE)
|
|
|
|
|
|
2021-04-25 21:29:31 +02:00
|
|
|
|
@projected_dossiers = DossierProjectionService.project(@filtered_sorted_paginated_ids, procedure_presentation.displayed_fields)
|
2019-12-11 17:42:44 +01:00
|
|
|
|
|
|
|
|
|
assign_exports
|
2017-07-11 16:09:03 +02:00
|
|
|
|
end
|
|
|
|
|
|
2020-03-20 17:59:16 +01:00
|
|
|
|
def deleted_dossiers
|
|
|
|
|
@procedure = procedure
|
2020-03-24 13:53:15 +01:00
|
|
|
|
@deleted_dossiers = @procedure
|
2020-03-31 14:33:30 +02:00
|
|
|
|
.deleted_dossiers
|
2020-03-24 13:53:15 +01:00
|
|
|
|
.order(:dossier_id)
|
|
|
|
|
.page params[:page]
|
2021-09-23 15:03:20 +02:00
|
|
|
|
|
2022-03-11 13:57:53 +01:00
|
|
|
|
@a_suivre_count, @suivis_count, @traites_count, @tous_count, @archives_count, @supprimes_recemment_count, @expirant_count = current_instructeur
|
2021-09-23 15:03:20 +02:00
|
|
|
|
.dossiers_count_summary(groupe_instructeur_ids)
|
2022-03-11 13:57:53 +01:00
|
|
|
|
.fetch_values('a_suivre', 'suivis', 'traites', 'tous', 'archives', 'supprimes_recemment', 'expirant')
|
2022-07-28 15:12:24 +02:00
|
|
|
|
@can_download_dossiers = (@tous_count + @archives_count) > 0 && !instructeur_as_manager?
|
2021-09-23 15:03:20 +02:00
|
|
|
|
|
|
|
|
|
notifications = current_instructeur.notifications_for_groupe_instructeurs(groupe_instructeur_ids)
|
|
|
|
|
@has_en_cours_notifications = notifications[:en_cours].present?
|
|
|
|
|
@has_termine_notifications = notifications[:termines].present?
|
|
|
|
|
|
|
|
|
|
@statut = 'supprime'
|
2022-03-11 13:57:53 +01:00
|
|
|
|
|
|
|
|
|
assign_exports
|
2020-03-20 17:59:16 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-10-02 17:03:38 +02:00
|
|
|
|
def update_displayed_fields
|
2021-03-03 17:31:05 +01:00
|
|
|
|
values = params['values'].presence || [].to_json
|
|
|
|
|
procedure_presentation.update_displayed_fields(JSON.parse(values))
|
2017-09-27 15:16:07 +02:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
2017-09-27 15:16:07 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_sort
|
2022-09-26 17:14:20 +02:00
|
|
|
|
procedure_presentation.update_sort(params[:table], params[:column], params[:order])
|
2017-09-27 15:16:07 +02:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
2017-10-02 17:03:38 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-09-28 11:04:18 +02:00
|
|
|
|
def add_filter
|
2022-09-12 16:30:29 +02:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
|
|
|
|
procedure_presentation.add_filter(statut, params[:field], params[:value])
|
|
|
|
|
|
|
|
|
|
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
|
|
|
|
end
|
|
|
|
|
format.turbo_stream do
|
|
|
|
|
@statut = statut
|
|
|
|
|
@procedure = procedure
|
|
|
|
|
@procedure_presentation = procedure_presentation
|
|
|
|
|
@field = params[:field]
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-09-28 11:04:18 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def remove_filter
|
2020-10-30 14:34:00 +01:00
|
|
|
|
procedure_presentation.remove_filter(statut, params[:field], params[:value])
|
2017-09-28 11:04:18 +02:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
2017-09-28 11:04:18 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-10-03 15:35:31 +02:00
|
|
|
|
def download_export
|
2019-12-11 17:43:24 +01:00
|
|
|
|
groupe_instructeurs = current_instructeur
|
|
|
|
|
.groupe_instructeurs
|
|
|
|
|
.where(procedure: procedure)
|
2019-09-30 11:57:21 +02:00
|
|
|
|
|
2022-03-09 10:27:43 +01:00
|
|
|
|
@can_download_dossiers = current_instructeur
|
|
|
|
|
.dossiers
|
|
|
|
|
.visible_by_administration
|
2022-07-28 15:12:24 +02:00
|
|
|
|
.exists?(groupe_instructeur_id: groupe_instructeur_ids) && !instructeur_as_manager?
|
2021-04-22 08:38:34 +02:00
|
|
|
|
|
2022-04-05 15:57:19 +02:00
|
|
|
|
export = Export.find_or_create_export(export_format, groupe_instructeurs, **export_options)
|
2019-12-11 17:43:24 +01:00
|
|
|
|
|
2022-07-07 18:15:48 +02:00
|
|
|
|
if export.available? && export.old? && force_export?
|
2021-04-08 12:47:29 +02:00
|
|
|
|
export.destroy
|
2022-04-05 15:57:19 +02:00
|
|
|
|
export = Export.find_or_create_export(export_format, groupe_instructeurs, **export_options)
|
2021-04-08 12:47:29 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-07-07 18:15:48 +02:00
|
|
|
|
if export.available?
|
2020-01-29 12:16:38 +01:00
|
|
|
|
respond_to do |format|
|
2022-05-11 16:11:34 +02:00
|
|
|
|
format.turbo_stream do
|
2020-01-29 12:16:38 +01:00
|
|
|
|
@procedure = procedure
|
2022-04-05 15:57:19 +02:00
|
|
|
|
@statut = export_options[:statut]
|
|
|
|
|
@dossiers_count = export.count
|
2020-01-29 12:16:38 +01:00
|
|
|
|
assign_exports
|
2020-04-02 15:54:31 +02:00
|
|
|
|
flash.notice = "L’export au format \"#{export_format}\" est prêt. Vous pouvez le <a href=\"#{export.file.service_url}\">télécharger</a>"
|
2020-01-29 12:16:38 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
format.html do
|
|
|
|
|
redirect_to export.file.service_url
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-12-11 17:43:24 +01:00
|
|
|
|
else
|
2019-10-16 11:40:19 +02:00
|
|
|
|
respond_to do |format|
|
2019-12-11 17:43:24 +01:00
|
|
|
|
notice_message = "Nous générons cet export. Veuillez revenir dans quelques minutes pour le télécharger."
|
2020-01-29 12:16:38 +01:00
|
|
|
|
|
2022-05-11 16:11:34 +02:00
|
|
|
|
format.turbo_stream do
|
2019-10-16 11:40:19 +02:00
|
|
|
|
@procedure = procedure
|
2022-04-05 15:57:19 +02:00
|
|
|
|
@statut = export_options[:statut]
|
|
|
|
|
@dossiers_count = export.count
|
2019-12-11 17:43:24 +01:00
|
|
|
|
assign_exports
|
2020-01-29 12:16:38 +01:00
|
|
|
|
if !params[:no_progress_notification]
|
|
|
|
|
flash.notice = notice_message
|
|
|
|
|
end
|
2019-12-11 17:43:24 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
format.html do
|
|
|
|
|
redirect_to instructeur_procedure_url(procedure), notice: notice_message
|
2019-10-16 11:40:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-10-02 15:51:37 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-13 17:37:07 +01:00
|
|
|
|
def email_notifications
|
|
|
|
|
@procedure = procedure
|
2021-12-21 18:25:14 +01:00
|
|
|
|
@assign_to = assign_tos.first
|
2019-03-13 17:37:07 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_email_notifications
|
2021-12-21 18:25:14 +01:00
|
|
|
|
assign_tos.each do |assign_to|
|
|
|
|
|
assign_to.update!(assign_to_params)
|
|
|
|
|
end
|
2019-03-13 17:37:07 +01:00
|
|
|
|
flash.notice = 'Vos notifications sont enregistrées.'
|
2019-08-06 11:02:54 +02:00
|
|
|
|
redirect_to instructeur_procedure_path(procedure)
|
2019-03-13 17:37:07 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-07-30 14:37:00 +02:00
|
|
|
|
def stats
|
|
|
|
|
@procedure = procedure
|
2019-09-17 15:52:38 +02:00
|
|
|
|
@usual_traitement_time = @procedure.stats_usual_traitement_time
|
|
|
|
|
@dossiers_funnel = @procedure.stats_dossiers_funnel
|
|
|
|
|
@termines_states = @procedure.stats_termines_states
|
2021-06-02 12:45:47 +02:00
|
|
|
|
@termines_by_week = @procedure.stats_termines_by_week
|
2021-06-15 17:40:52 +02:00
|
|
|
|
@usual_traitement_time_by_month = @procedure.stats_usual_traitement_time_by_month_in_days
|
2019-07-30 14:37:00 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-07-19 18:45:49 +02:00
|
|
|
|
def email_usagers
|
|
|
|
|
@procedure = procedure
|
|
|
|
|
@commentaire = Commentaire.new
|
|
|
|
|
@email_usagers_dossiers = email_usagers_dossiers
|
|
|
|
|
@dossiers_count = @email_usagers_dossiers.count
|
|
|
|
|
@groupe_instructeurs = email_usagers_groupe_instructeurs_label
|
2021-08-02 10:38:44 +02:00
|
|
|
|
@bulk_messages = BulkMessage.includes(:groupe_instructeurs).where(groupe_instructeurs: { id: current_instructeur.groupe_instructeur_ids, procedure: procedure })
|
2021-07-19 18:45:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_multiple_commentaire
|
|
|
|
|
@procedure = procedure
|
|
|
|
|
errors = []
|
|
|
|
|
|
|
|
|
|
email_usagers_dossiers.each do |dossier|
|
2021-11-30 18:56:12 +01:00
|
|
|
|
commentaire = CommentaireService.create(current_instructeur, dossier, commentaire_params)
|
|
|
|
|
if commentaire.errors.empty?
|
2021-07-19 18:45:49 +02:00
|
|
|
|
commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now)
|
|
|
|
|
else
|
|
|
|
|
errors << dossier.id
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
valid_dossiers_count = email_usagers_dossiers.count - errors.count
|
|
|
|
|
create_bulk_message_mail(valid_dossiers_count, Dossier.states.fetch(:brouillon))
|
|
|
|
|
|
|
|
|
|
if errors.empty?
|
|
|
|
|
flash[:notice] = "Tous les messages ont été envoyés avec succès"
|
|
|
|
|
else
|
|
|
|
|
flash[:alert] = "Envoi terminé. Cependant #{errors.count} messages n'ont pas été envoyés"
|
|
|
|
|
end
|
|
|
|
|
redirect_to instructeur_procedure_path(@procedure)
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-11 13:57:09 +01:00
|
|
|
|
private
|
|
|
|
|
|
2021-07-19 18:45:49 +02:00
|
|
|
|
def create_bulk_message_mail(dossier_count, dossier_state)
|
|
|
|
|
BulkMessage.create(
|
|
|
|
|
dossier_count: dossier_count,
|
|
|
|
|
dossier_state: dossier_state,
|
|
|
|
|
body: commentaire_params[:body],
|
|
|
|
|
sent_at: Time.zone.now,
|
|
|
|
|
instructeur_id: current_instructeur.id,
|
|
|
|
|
piece_jointe: commentaire_params[:piece_jointe],
|
|
|
|
|
groupe_instructeurs: email_usagers_groupe_instructeurs
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2020-02-11 15:51:15 +01:00
|
|
|
|
def assign_to_params
|
2020-04-09 11:43:23 +02:00
|
|
|
|
params.require(:assign_to)
|
2022-08-30 21:41:04 +02:00
|
|
|
|
.permit(:instant_expert_avis_email_notifications_enabled, :instant_email_dossier_notifications_enabled, :instant_email_message_notifications_enabled, :daily_email_notifications_enabled, :weekly_email_notifications_enabled)
|
2020-02-11 15:51:15 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-12-11 17:42:44 +01:00
|
|
|
|
def assign_exports
|
2022-04-05 15:57:19 +02:00
|
|
|
|
@exports = Export.find_for_groupe_instructeurs(groupe_instructeur_ids, procedure_presentation)
|
2019-12-11 17:42:44 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-04-08 15:35:20 +02:00
|
|
|
|
def assign_tos
|
|
|
|
|
@assign_tos ||= current_instructeur
|
|
|
|
|
.assign_to
|
|
|
|
|
.joins(:groupe_instructeur)
|
|
|
|
|
.where(groupe_instructeur: { procedure_id: procedure_id })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def groupe_instructeur_ids
|
|
|
|
|
@groupe_instructeur_ids ||= assign_tos
|
|
|
|
|
.map(&:groupe_instructeur_id)
|
|
|
|
|
end
|
|
|
|
|
|
2017-09-28 19:07:18 +02:00
|
|
|
|
def statut
|
2018-03-06 13:44:29 +01:00
|
|
|
|
@statut ||= (params[:statut].presence || 'a-suivre')
|
2017-09-28 19:07:18 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-04-05 15:57:19 +02:00
|
|
|
|
def export_format
|
|
|
|
|
@export_format ||= params[:export_format]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def force_export?
|
|
|
|
|
@force_export ||= params[:force_export].present?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def export_options
|
|
|
|
|
@export_options ||= {
|
|
|
|
|
time_span_type: params[:time_span_type],
|
|
|
|
|
statut: params[:statut],
|
|
|
|
|
procedure_presentation: params[:statut].present? ? procedure_presentation : nil
|
|
|
|
|
}.compact
|
|
|
|
|
end
|
|
|
|
|
|
2021-04-08 14:35:43 +02:00
|
|
|
|
def procedure_id
|
|
|
|
|
params[:procedure_id]
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-29 15:30:42 +02:00
|
|
|
|
def procedure
|
2021-04-21 22:02:40 +02:00
|
|
|
|
Procedure
|
|
|
|
|
.with_attached_logo
|
|
|
|
|
.find(procedure_id)
|
2017-06-29 15:30:42 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def ensure_ownership!
|
2019-10-09 18:28:03 +02:00
|
|
|
|
if !current_instructeur.procedures.include?(procedure)
|
2020-01-29 12:16:38 +01:00
|
|
|
|
flash[:alert] = "Vous n’avez pas accès à cette démarche"
|
2017-06-29 15:30:42 +02:00
|
|
|
|
redirect_to root_path
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-09-07 16:04:53 +02:00
|
|
|
|
|
|
|
|
|
def redirect_to_avis_if_needed
|
2019-09-17 15:07:58 +02:00
|
|
|
|
if current_instructeur.procedures.count == 0 && current_instructeur.avis.count > 0
|
2020-04-16 17:52:58 +02:00
|
|
|
|
redirect_to instructeur_all_avis_path
|
2017-09-07 16:04:53 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-10-02 17:03:38 +02:00
|
|
|
|
|
|
|
|
|
def procedure_presentation
|
2018-10-23 10:55:59 +02:00
|
|
|
|
@procedure_presentation ||= get_procedure_presentation
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_procedure_presentation
|
2021-04-08 14:35:43 +02:00
|
|
|
|
procedure_presentation, errors = current_instructeur.procedure_presentation_and_errors_for_procedure_id(procedure_id)
|
2018-10-23 11:39:54 +02:00
|
|
|
|
if errors.present?
|
|
|
|
|
flash[:alert] = "Votre affichage a dû être réinitialisé en raison du problème suivant : " + errors.full_messages.join(', ')
|
|
|
|
|
end
|
|
|
|
|
procedure_presentation
|
2017-10-02 17:03:38 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-09-28 11:04:18 +02:00
|
|
|
|
def current_filters
|
|
|
|
|
@current_filters ||= procedure_presentation.filters[statut]
|
|
|
|
|
end
|
2021-07-19 18:45:49 +02:00
|
|
|
|
|
|
|
|
|
def email_usagers_dossiers
|
|
|
|
|
procedure.dossiers.state_brouillon.where(groupe_instructeur: current_instructeur.groupe_instructeur_ids).includes(:groupe_instructeur)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def email_usagers_groupe_instructeurs_label
|
|
|
|
|
email_usagers_dossiers.map(&:groupe_instructeur).uniq.map(&:label)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def email_usagers_groupe_instructeurs
|
|
|
|
|
email_usagers_dossiers.map(&:groupe_instructeur).uniq
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def commentaire_params
|
|
|
|
|
params.require(:commentaire).permit(:body, :piece_jointe)
|
|
|
|
|
end
|
2017-06-29 15:30:42 +02:00
|
|
|
|
end
|
|
|
|
|
end
|