Merge pull request #9353 from demarches-simplifiees/9347-warning-siret

ETQ admin, je suis alerté lorsque mes demarches publiées ont des services sans siret ou pas de service
This commit is contained in:
Paul Chavard 2023-07-27 08:25:04 +00:00 committed by GitHub
commit fed6b8c663
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 1 deletions

View file

@ -1,6 +1,8 @@
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
@ -38,5 +40,42 @@ module Administrateurs
current_administrateur.administrateurs_procedures
.exists?(procedure_id: id, manager: true)
end
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
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,5 +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

@ -822,6 +822,11 @@ en:
merger_token_expired: "Le delay to merge your FranceConnect and %{application_name} accounts is expired. Please retry."
shared:
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"
processing_time_description: "%{percentile}% of submitted files in the last %{span} days were processed in less than %{days}."

View file

@ -876,6 +876,11 @@ fr:
merger_token_expired: "Le délai pour fusionner les comptes FranceConnect et %{application_name} est expirée. Veuillez recommencer la procédure pour vous fusionner les comptes."
shared:
procedures:
no_siret: "Vous navez pas renseigné le siret du service pour certaines de vos démarches. 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 démarches nont pas de service associé."
add_service_html: <a href="%{link}">Ajouter un service</a> à la démarche %{id}
stats:
usual_processing_time: "Temps de traitement usuel"
processing_time_description: "%{percentile}% des demandes des %{span} derniers jours ont été traitées en moins de %{days}."

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

@ -157,4 +157,36 @@ describe Administrateurs::ServicesController, type: :controller do
it { expect(procedure.reload.service_id).to be_nil }
end
end
describe "#index" do
let(:admin) { create(:administrateur) }
before do
sign_in(admin.user)
end
context 'when admin has service without siret' do
let(:service) { create(:service) }
let(:procedure) { create(:procedure, :published, service: service, administrateur: admin) }
it 'display alert when admin has service without siret' do
service.siret = nil
service.save(validate: false)
get :index, params: { procedure_id: procedure.id }
expect(flash.alert.first).to eq "Vous navez pas renseigné le siret du service pour certaines de vos démarches. Merci de les modifier."
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 démarches nont pas de service associé."
expect(flash.alert.last).to include "démarche #{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