alert admin with procedures without service

This commit is contained in:
Christophe Robillard 2023-07-24 19:01:31 +02:00
parent beaf5751bb
commit ef7b0c7377
7 changed files with 37 additions and 1 deletions

View file

@ -2,6 +2,7 @@ module Administrateurs
class AdministrateurController < ApplicationController
before_action :authenticate_administrateur!
before_action :alert_for_missing_siret_service
before_action :alert_for_missing_service
helper_method :administrateur_as_manager?
def nav_bar_profile
@ -58,5 +59,23 @@ module Administrateurs
.joins(:service)
.where(service: { siret: nil })
end
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
end
end

View file

@ -1,6 +1,7 @@
module Administrateurs
class ServicesController < AdministrateurController
skip_before_action :alert_for_missing_siret_service, only: :edit
skip_before_action :alert_for_missing_service, only: :edit
def index
@services = services.ordered
@procedure = procedure

View file

@ -824,6 +824,8 @@ en:
procedures:
no_siret: "Some procedures have service without siret. Please update."
add_siret_to_service_without_siret_html: Add siret for service <a href="%{link}">%{nom}</a>
no_service: "Some procedures have no service."
add_service_html: <a href="%{link}">Add service</a> to procedure %{id}
stats:
usual_processing_time: "Usual processing time"

View file

@ -878,6 +878,8 @@ fr:
procedures:
no_siret: "Vous n'avez pas renseigné le siret du service pour certaines de vos demarches. Merci de les modifier."
add_siret_to_service_without_siret_html: Ajouter le siret du service <a href="%{link}">%{nom}</a>
no_service: "Certaines de vos demarches n'ont pas de service associé."
add_service_html: <a href="%{link}">Ajouter un service</a> à la procédure %{id}
stats:
usual_processing_time: "Temps de traitement usuel"

View file

@ -295,7 +295,7 @@ describe Administrateurs::ProceduresController, type: :controller do
let(:service_2) { create(:service, nom: 'DDT du Loiret') }
let!(:procedure_with_service_1) { create(:procedure_with_dossiers, :published, organisation: nil, service: service_1, dossiers_count: 2) }
let!(:procedure_with_service_2) { create(:procedure_with_dossiers, :published, organisation: nil, service: service_2, dossiers_count: 2) }
let!(:procedure_without_service) { create(:procedure_with_dossiers, :published, organisation: 'DDT du Loiret', dossiers_count: 2) }
let!(:procedure_without_service) { create(:procedure_with_dossiers, :published, service: nil, organisation: 'DDT du Loiret', dossiers_count: 2) }
it 'groups procedures with services as well as procedures with organisations' do
expect(grouped_procedures.length).to eq 2

View file

@ -177,5 +177,16 @@ describe Administrateurs::ServicesController, type: :controller do
expect(flash.alert.last).to include(service.nom)
end
end
context 'when admin has procedure without service' do
let(:procedure) { create(:procedure, :published, service: nil, administrateur: admin) }
it 'display alert' do
get :index, params: { procedure_id: procedure.id }
expect(procedure.service).to be nil
expect(flash.alert.first).to eq "Certaines de vos demarches n'ont pas de service associé."
expect(flash.alert.last).to include "procédure #{procedure.id}"
end
end
end
end

View file

@ -315,6 +315,7 @@ FactoryBot.define do
unpublished_at { nil }
closed_at { nil }
zones { [association(:zone, strategy: :build)] }
service { association :service, administrateur: administrateurs.first }
end
trait :closed do