2017-12-28 19:44:11 +01:00
|
|
|
|
module Manager
|
|
|
|
|
class ProceduresController < Manager::ApplicationController
|
2019-10-31 16:30:39 +01:00
|
|
|
|
#
|
|
|
|
|
# Administrate overrides
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# Override this if you have certain roles that require a subset
|
|
|
|
|
# this will be used to set the records shown on the `index` action.
|
|
|
|
|
def scoped_resource
|
|
|
|
|
if unfiltered_list?
|
2020-03-26 09:08:52 +01:00
|
|
|
|
# Don't display discarded demarches in the unfiltered list…
|
2020-02-05 16:09:03 +01:00
|
|
|
|
Procedure.kept
|
2019-10-31 16:30:39 +01:00
|
|
|
|
else
|
|
|
|
|
# … but allow them to be searched and displayed.
|
2020-02-05 16:09:03 +01:00
|
|
|
|
Procedure.with_discarded
|
2019-10-31 16:30:39 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-10 16:46:12 +01:00
|
|
|
|
def whitelist
|
|
|
|
|
procedure.whitelist!
|
2018-09-05 14:48:42 +02:00
|
|
|
|
flash[:notice] = "Démarche whitelistée."
|
2018-01-10 16:46:12 +01:00
|
|
|
|
redirect_to manager_procedure_path(procedure)
|
|
|
|
|
end
|
2018-10-09 12:11:13 +02:00
|
|
|
|
|
2020-03-26 09:08:52 +01:00
|
|
|
|
def discard
|
2020-11-05 15:09:11 +01:00
|
|
|
|
procedure.discard_and_keep_track!(current_super_admin)
|
2020-03-26 09:08:52 +01:00
|
|
|
|
|
2020-11-05 15:09:11 +01:00
|
|
|
|
logger.info("La démarche #{procedure.id} est supprimée par #{current_super_admin.email}")
|
2020-03-26 09:08:52 +01:00
|
|
|
|
flash[:notice] = "La démarche #{procedure.id} a été supprimée."
|
|
|
|
|
|
|
|
|
|
redirect_to manager_procedure_path(procedure)
|
2018-11-20 17:38:04 +01:00
|
|
|
|
end
|
2019-02-27 14:42:21 +01:00
|
|
|
|
|
2020-03-26 17:35:50 +01:00
|
|
|
|
def restore
|
2020-11-05 15:09:11 +01:00
|
|
|
|
procedure.restore(current_super_admin)
|
2020-03-26 17:35:50 +01:00
|
|
|
|
|
|
|
|
|
flash[:notice] = "La démarche #{procedure.id} a été restauré."
|
|
|
|
|
|
|
|
|
|
redirect_to manager_procedure_path(procedure)
|
|
|
|
|
end
|
|
|
|
|
|
2020-05-18 11:07:51 +02:00
|
|
|
|
def export_mail_brouillons
|
2020-05-18 12:17:21 +02:00
|
|
|
|
dossiers = procedure.dossiers.state_brouillon.includes(:user)
|
2021-05-01 12:20:24 +02:00
|
|
|
|
emails = dossiers.map { |dossier| dossier.user_email_for(:display) }.sort.uniq
|
2020-05-18 11:07:51 +02:00
|
|
|
|
date = Time.zone.now.strftime('%d-%m-%Y')
|
|
|
|
|
send_data(emails.join("\n"), :filename => "brouillons-#{procedure.id}-au-#{date}.csv")
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-27 14:42:21 +01:00
|
|
|
|
def add_administrateur
|
2021-10-14 17:16:12 +02:00
|
|
|
|
add_self = params[:email].blank?
|
|
|
|
|
administrateur_email = add_self ? current_super_admin.email : params[:email]
|
|
|
|
|
administrateur = Administrateur.by_email(administrateur_email)
|
2019-02-27 14:42:21 +01:00
|
|
|
|
if administrateur
|
2021-10-14 17:16:12 +02:00
|
|
|
|
AdministrateursProcedure.create(procedure: procedure, administrateur: administrateur, manager: add_self)
|
|
|
|
|
if add_self
|
|
|
|
|
flash[:notice] = "L’administrateur \"#{administrateur_email}\" est ajouté à la démarche pour la journée."
|
|
|
|
|
else
|
|
|
|
|
flash[:notice] = "L’administrateur \"#{administrateur_email}\" est ajouté à la démarche."
|
|
|
|
|
end
|
2019-02-27 14:42:21 +01:00
|
|
|
|
else
|
2021-10-14 17:16:12 +02:00
|
|
|
|
if add_self
|
|
|
|
|
flash[:alert] = "Vous n’êtes pas connecté en tant qu’administrateur."
|
|
|
|
|
else
|
|
|
|
|
flash[:alert] = "L’administrateur \"#{administrateur_email}\" est introuvable."
|
|
|
|
|
end
|
2019-02-27 14:42:21 +01:00
|
|
|
|
end
|
|
|
|
|
redirect_to manager_procedure_path(procedure)
|
|
|
|
|
end
|
2019-04-17 16:33:24 +02:00
|
|
|
|
|
2019-04-17 16:36:57 +02:00
|
|
|
|
def change_piece_justificative_template
|
|
|
|
|
if type_de_champ.update(type_de_champ_params)
|
|
|
|
|
flash[:notice] = "Le modèle est mis à jour."
|
|
|
|
|
else
|
|
|
|
|
flash[:alert] = type_de_champ.errors.full_messages.join(', ')
|
|
|
|
|
end
|
|
|
|
|
redirect_to manager_procedure_path(procedure)
|
|
|
|
|
end
|
|
|
|
|
|
2019-04-17 16:33:24 +02:00
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def procedure
|
2020-03-26 09:08:52 +01:00
|
|
|
|
@procedure ||= Procedure.with_discarded.find(params[:id])
|
2019-04-17 16:33:24 +02:00
|
|
|
|
end
|
2019-04-17 16:36:57 +02:00
|
|
|
|
|
|
|
|
|
def type_de_champ
|
|
|
|
|
TypeDeChamp.find(params[:type_de_champ][:id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def type_de_champ_params
|
|
|
|
|
params.require(:type_de_champ).permit(:piece_justificative_template)
|
|
|
|
|
end
|
2019-10-31 16:30:39 +01:00
|
|
|
|
|
|
|
|
|
def unfiltered_list?
|
|
|
|
|
action_name == "index" && !params[:search]
|
|
|
|
|
end
|
2017-12-28 19:44:11 +01:00
|
|
|
|
end
|
|
|
|
|
end
|