Skip to content

Commit

Permalink
alert admin with procedures without service
Browse files Browse the repository at this point in the history
  • Loading branch information
krichtof committed Jul 24, 2023
1 parent 46d1a41 commit 3df6332
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/controllers/administrateurs/administrateur_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,5 +59,23 @@ def missing_siret_services
.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
1 change: 1 addition & 0 deletions app/controllers/administrateurs/services_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions spec/controllers/administrateurs/services_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,16 @@ def post_add_to_procedure
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
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 3df6332

Please sign in to comment.