2021-11-25 16:26:55 +01:00
|
|
|
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)
|
2023-02-07 10:38:44 +01:00
|
|
|
|
|
|
|
Sentry.configure_scope do |scope|
|
|
|
|
scope.set_tags(procedure: @procedure.id)
|
|
|
|
end
|
2018-11-14 16:24:34 +01:00
|
|
|
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
|
2022-12-14 09:15:40 +01:00
|
|
|
@procedure.reset!
|
2018-11-14 16:24:34 +01:00
|
|
|
end
|
2022-07-21 19:14:21 +02:00
|
|
|
|
|
|
|
def ensure_not_super_admin!
|
2022-07-28 15:12:24 +02:00
|
|
|
if administrateur_as_manager?
|
2022-07-21 19:14:21 +02:00
|
|
|
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?
|
2022-07-21 19:14:21 +02:00
|
|
|
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
|