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
|
|
|
|
procedure.discard_and_keep_track!(current_administration)
|
|
|
|
|
|
|
|
logger.info("La démarche #{procedure.id} est supprimée par #{current_administration.email}")
|
|
|
|
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
|
|
|
|
procedure.restore(current_administration)
|
|
|
|
|
|
|
|
flash[:notice] = "La démarche #{procedure.id} a été restauré."
|
|
|
|
|
|
|
|
redirect_to manager_procedure_path(procedure)
|
|
|
|
end
|
|
|
|
|
2019-02-27 14:42:21 +01:00
|
|
|
def add_administrateur
|
2020-01-30 17:08:09 +01:00
|
|
|
administrateur = Administrateur.by_email(params[:email])
|
2019-02-27 14:42:21 +01:00
|
|
|
if administrateur
|
|
|
|
procedure.administrateurs << administrateur
|
|
|
|
flash[:notice] = "L'administrateur \"#{params[:email]}\" est ajouté à la démarche."
|
|
|
|
else
|
|
|
|
flash[:alert] = "L'administrateur \"#{params[:email]}\" est introuvable."
|
|
|
|
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
|