Skip to content

Commit

Permalink
Merge pull request #9353 from demarches-simplifiees/9347-warning-siret
Browse files Browse the repository at this point in the history
ETQ admin, je suis alerté lorsque mes demarches publiées ont des services sans siret ou pas de service
  • Loading branch information
tchak authored Jul 27, 2023
2 parents f692846 + e28e31c commit fed6b8c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
39 changes: 39 additions & 0 deletions app/controllers/administrateurs/administrateur_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -38,5 +40,42 @@ def administrateur_as_manager?
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
2 changes: 2 additions & 0 deletions app/controllers/administrateurs/services_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
Expand Down
5 changes: 5 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 n’avez 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 n’ont 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}."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
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
Expand Down
32 changes: 32 additions & 0 deletions spec/controllers/administrateurs/services_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,36 @@ def post_add_to_procedure
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 n’avez 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 n’ont pas de service associé."
expect(flash.alert.last).to include "démarche #{procedure.id}"
end
end
end
end
1 change: 1 addition & 0 deletions spec/factories/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@
unpublished_at { nil }
closed_at { nil }
zones { [association(:zone, strategy: :build)] }
service { association :service, administrateur: administrateurs.first }
end

trait :closed do
Expand Down

0 comments on commit fed6b8c

Please sign in to comment.