An admin should always have access to the service of it’s procedures

This commit is contained in:
Paul Chavard 2019-03-06 17:06:54 +01:00
parent 64abd8c712
commit 93ceb79dd1
3 changed files with 9 additions and 3 deletions

View file

@ -81,13 +81,19 @@ module NewAdministrateur
end
def services
current_administrateur.services
service_ids = current_administrateur.service_ids
service_ids << maybe_procedure&.service_id
Service.where(id: service_ids.compact.uniq)
end
def procedure_params
params.require(:procedure).permit(:id, :service_id)
end
def maybe_procedure
current_administrateur.procedures.find_by(id: params[:procedure_id])
end
def procedure
current_administrateur.procedures.find(params[:procedure_id])
end

View file

@ -21,7 +21,7 @@
.procedure-list-element{ class: ('active' if active == 'Description') }
Description
%a#onglet-services{ href: current_administrateur.services.present? ? url_for(services_path(procedure_id: @procedure.id)) : url_for(new_service_path(procedure_id: @procedure.id)) }
%a#onglet-services{ href: (@procedure.service.present? || current_administrateur.services.present?) ? url_for(services_path(procedure_id: @procedure.id)) : url_for(new_service_path(procedure_id: @procedure.id)) }
.procedure-list-element
Service
- if @procedure.missing_steps.include?(:service)

View file

@ -9,7 +9,7 @@
= form_for @procedure, url: { controller: "new_administrateur/services", action: :add_to_procedure } , html: { class: 'form' } do |f|
= f.label :service_id, "La démarche #{@procedure.libelle} est affectée au service"
= f.select :service_id,
current_administrateur.services.map { |s| [ s.nom, s.id ] },
@services.map { |s| [ s.nom, s.id ] },
{ prompt: 'choisir un service', selected: @procedure.service&.id },
required: true