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

51 lines
1.5 KiB
Ruby
Raw Normal View History

module Administrateurs
2018-04-13 16:56:00 +02:00
class AdministrateurController < ApplicationController
before_action :authenticate_administrateur!
helper_method :is_administrateur_through_procedure_administration_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 procedure_locked?
if @procedure.locked?
flash.alert = 'Démarche verrouillée'
redirect_to admin_procedure_path(@procedure)
end
end
def procedure_revisable?
if @procedure.locked? && !@procedure.feature_enabled?(:procedure_revisions)
flash.alert = 'Démarche verrouillée'
redirect_to admin_procedure_path(@procedure)
end
end
2018-11-14 16:24:34 +01:00
def reset_procedure
2021-06-24 11:57:05 +02:00
if @procedure.brouillon? || @procedure.draft_changed?
2018-11-14 16:24:34 +01:00
@procedure.reset!
end
end
def ensure_not_super_admin!
if is_administrateur_through_procedure_administration_as_manager?
redirect_back fallback_location: root_url, alert: "Interdit aux super admins", status: 403
end
end
private
def is_administrateur_through_procedure_administration_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