demarches-normaliennes/app/controllers/administrateurs/administrateur_controller.rb

35 lines
923 B
Ruby
Raw Normal View History

module Administrateurs
2018-04-13 16:56:00 +02:00
class AdministrateurController < ApplicationController
before_action :authenticate_administrateur!
2022-07-28 15:12:24 +02:00
helper_method :administrateur_as_manager?
2018-11-14 16:24:34 +01:00
def retrieve_procedure
id = params[:procedure_id] || params[:id]
@procedure = current_administrateur.procedures.find(id)
rescue ActiveRecord::RecordNotFound
flash.alert = 'Démarche inexistante'
2019-09-24 16:38:58 +02:00
redirect_to admin_procedures_path, status: 404
2018-11-14 16:24:34 +01:00
end
def reset_procedure
@procedure.reset!
2018-11-14 16:24:34 +01:00
end
def ensure_not_super_admin!
2022-07-28 15:12:24 +02:00
if administrateur_as_manager?
redirect_back fallback_location: root_url, alert: "Interdit aux super admins", status: 403
end
end
private
2022-07-28 15:12:24 +02:00
def administrateur_as_manager?
id = params[:procedure_id] || params[:id]
current_administrateur.administrateurs_procedures
.exists?(procedure_id: id, manager: true)
end
2018-04-13 16:56:00 +02:00
end
end