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!
|
2023-07-24 11:05:02 +02:00
|
|
|
before_action :alert_for_missing_siret_service
|
2023-07-24 19:01:31 +02:00
|
|
|
before_action :alert_for_missing_service
|
2022-07-28 15:12:24 +02:00
|
|
|
helper_method :administrateur_as_manager?
|
2018-11-14 16:24:34 +01:00
|
|
|
|
2023-07-12 16:50:28 +02:00
|
|
|
def nav_bar_profile
|
|
|
|
:administrateur
|
|
|
|
end
|
|
|
|
|
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
|
2023-07-24 11:05:02 +02:00
|
|
|
|
|
|
|
def alert_for_missing_siret_service
|
|
|
|
procedures = missing_siret_services
|
|
|
|
if procedures.any?
|
|
|
|
errors = []
|
|
|
|
errors << I18n.t('shared.procedures.no_siret')
|
|
|
|
procedures.each do |p|
|
|
|
|
errors << I18n.t('shared.procedures.add_siret_to_service_without_siret_html', link: edit_admin_service_path(p.service, procedure_id: p.id), nom: p.service.nom)
|
|
|
|
end
|
|
|
|
flash.now.alert = errors
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def missing_siret_services
|
|
|
|
current_administrateur
|
|
|
|
.procedures.publiees
|
|
|
|
.joins(:service)
|
|
|
|
.where(service: { siret: nil })
|
|
|
|
end
|
2023-07-24 19:01:31 +02:00
|
|
|
|
|
|
|
def alert_for_missing_service
|
|
|
|
procedures = missing_service
|
|
|
|
if procedures.any?
|
|
|
|
errors = []
|
|
|
|
errors << I18n.t('shared.procedures.no_service')
|
|
|
|
procedures.each do |p|
|
|
|
|
errors << I18n.t('shared.procedures.add_service_html', link: admin_services_path(procedure_id: p.id), id: p.id)
|
|
|
|
end
|
|
|
|
flash.now.alert = errors
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def missing_service
|
|
|
|
current_administrateur
|
|
|
|
.procedures.publiees
|
|
|
|
.where(service_id: nil)
|
|
|
|
end
|
2018-04-13 16:56:00 +02:00
|
|
|
end
|
|
|
|
end
|