demarches-normaliennes/app/controllers/manager/procedures_controller.rb

106 lines
3.4 KiB
Ruby
Raw Normal View History

2017-12-28 19:44:11 +01:00
module Manager
class ProceduresController < Manager::ApplicationController
#
# 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
else
# … but allow them to be searched and displayed.
2020-02-05 16:09:03 +01:00
Procedure.with_discarded
end
end
def whitelist
procedure.whitelist!
2018-09-05 14:48:42 +02:00
flash[:notice] = "Démarche whitelistée."
redirect_to manager_procedure_path(procedure)
end
2020-03-26 09:08:52 +01:00
def discard
procedure.discard_and_keep_track!(current_super_admin)
2020-03-26 09:08:52 +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)
end
def restore
procedure.restore(current_super_admin)
flash[:notice] = "La démarche #{procedure.id} a été restauré."
redirect_to manager_procedure_path(procedure)
end
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
date = Time.zone.now.strftime('%d-%m-%Y')
send_data(emails.join("\n"), :filename => "brouillons-#{procedure.id}-au-#{date}.csv")
end
def add_administrateur
add_self = params[:email].blank?
administrateur_email = add_self ? current_super_admin.email : params[:email]
administrateur = Administrateur.by_email(administrateur_email)
if administrateur
AdministrateursProcedure.create(procedure: procedure, administrateur: administrateur, manager: add_self)
if add_self
flash[:notice] = "Ladministrateur \"#{administrateur_email}\" est ajouté à la démarche pour la journée."
else
flash[:notice] = "Ladministrateur \"#{administrateur_email}\" est ajouté à la démarche."
end
else
if add_self
flash[:alert] = "Vous nêtes pas connecté en tant quadministrateur."
else
flash[:alert] = "Ladministrateur \"#{administrateur_email}\" est introuvable."
end
end
redirect_to manager_procedure_path(procedure)
end
2019-04-17 16:33:24 +02:00
def delete_administrateur
administrateur = procedure.administrateurs.find { |admin| admin.email == current_super_admin.email }
if administrateur.present?
procedure.administrateurs.delete(administrateur)
end
redirect_to manager_procedure_path(procedure)
end
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
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
def unfiltered_list?
action_name == "index" && !params[:search]
end
2017-12-28 19:44:11 +01:00
end
end