diff --git a/app/models/procedure.rb b/app/models/procedure.rb index ede8d11bc..34ea5f432 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -653,7 +653,7 @@ class Procedure < ApplicationRecord end def missing_zones? - if feature_enabled?(:zonage) + if Rails.application.config.ds_zonage_enabled zones.empty? else false diff --git a/app/views/administrateurs/procedures/_main_menu.html.haml b/app/views/administrateurs/procedures/_main_menu.html.haml index 69d07dca0..9d3d28ef9 100644 --- a/app/views/administrateurs/procedures/_main_menu.html.haml +++ b/app/views/administrateurs/procedures/_main_menu.html.haml @@ -2,4 +2,5 @@ %nav#header-navigation.fr-nav{ role: 'navigation', 'aria-label': 'Menu principal administrateur' } %ul.fr-nav__list %li.fr-nav__item= link_to 'Mes démarches', admin_procedures_path, class:'fr-nav__link', 'aria-current': current_page?(admin_procedures_path) ? 'page' : nil - %li.fr-nav__item= link_to 'Toutes les démarches', all_admin_procedures_path(zone_ids: current_administrateur.zones), class:'fr-nav__link', 'aria-current': current_page?(all_admin_procedures_path) ? 'page' : nil + - if Rails.application.config.ds_zonage_enabled + %li.fr-nav__item= link_to 'Toutes les démarches', all_admin_procedures_path(zone_ids: current_administrateur.zones), class:'fr-nav__link', 'aria-current': current_page?(all_admin_procedures_path) ? 'page' : nil diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index 66f218b2e..4a16cbf3d 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -58,7 +58,7 @@ %h2.fr-mt-5w.fr-mb-3w.fr-h1 Indispensable avant publication .fr-grid-row.fr-grid-row--gutters = render Procedure::Card::PresentationComponent.new(procedure: @procedure) - = render Procedure::Card::ZonesComponent.new(procedure: @procedure) if @procedure.feature_enabled?(:zonage) + = render Procedure::Card::ZonesComponent.new(procedure: @procedure) if Rails.application.config.ds_zonage_enabled = render Procedure::Card::ChampsComponent.new(procedure: @procedure) = render Procedure::Card::ServiceComponent.new(procedure: @procedure, administrateur: current_administrateur) = render Procedure::Card::AdministrateursComponent.new(procedure: @procedure) diff --git a/app/views/administrateurs/procedures/zones.html.haml b/app/views/administrateurs/procedures/zones.html.haml index d854d5206..def635d72 100644 --- a/app/views/administrateurs/procedures/zones.html.haml +++ b/app/views/administrateurs/procedures/zones.html.haml @@ -13,7 +13,7 @@ = f.label :zone do = t('zone', scope: 'activerecord.attributes.procedure') - - if @procedure.feature_enabled?(:zonage) + - if Rails.application.config.ds_zonage_enabled = f.collection_check_boxes :zone_ids, Zone.available_at(@procedure.published_or_created_at), :id, :label do |b| .editable-champ.editable-champ-checkbox = b.check_box diff --git a/config/application.rb b/config/application.rb index 792919e98..3e9e0e172 100644 --- a/config/application.rb +++ b/config/application.rb @@ -77,6 +77,8 @@ module TPS config.ds_opendata_enabled = ENV.fetch('OPENDATA_ENABLED', nil) == 'enabled' + config.ds_zonage_enabled = ENV.fetch("ZONAGE_ENABLED", nil) == "enabled" + config.skylight.probes += [:graphql] # Custom Configuration diff --git a/config/env.example.optional b/config/env.example.optional index 57c940be8..158fd3454 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -149,6 +149,10 @@ DATAGOUV_API_URL="https://www.data.gouv.fr/api/1" DATAGOUV_DESCRIPTIF_DEMARCHES_DATASET="datasetid" DATAGOUV_DESCRIPTIF_DEMARCHES_RESOURCE="resourceid" +# Zonage +ZONAGE_ENABLED='enabled' # zonage disabled by default if `ZONAGE_ENABLED` not set + + # SAML SAML_IDP_CERTIFICATE="idpcertificate" SAML_IDP_SECRET_KEY="-----BEGIN RSA PRIVATE KEY-----\nblabla+blabla\n-----END RSA PRIVATE KEY-----\n" diff --git a/config/environments/test.rb b/config/environments/test.rb index d58d3363b..ccaba8feb 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -80,6 +80,8 @@ Rails.application.configure do status_visible_duration: 500 } + config.ds_zonage_enabled = true + # BCrypt is slow by design - but during tests we want to make it faster # to compute hashes of passwords. silence_warnings do diff --git a/config/routes.rb b/config/routes.rb index 64e70c7d4..2f8be3a6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -450,8 +450,8 @@ Rails.application.routes.draw do collection do get 'new_from_existing' post 'search' - get 'all' - get 'administrateurs' + get 'all' if Rails.application.config.ds_zonage_enabled + get 'administrateurs' if Rails.application.config.ds_zonage_enabled end member do diff --git a/lib/tasks/deployment/20220922151100_populate_zones.rake b/lib/tasks/deployment/20220922151100_populate_zones.rake index a9d42b4e1..3b1b1ad12 100644 --- a/lib/tasks/deployment/20220922151100_populate_zones.rake +++ b/lib/tasks/deployment/20220922151100_populate_zones.rake @@ -1,7 +1,7 @@ namespace :after_party do desc 'Deployment task: populate_zones' task populate_zones: :environment do - if Flipper.enabled? :zonage + if Rails.application.config.ds_zonage_enabled puts "Running deploy task 'populate_zones'" collectivite = Zone.find_or_create_by!(acronym: 'COLLECTIVITE') coll_label = collectivite.labels.find_or_initialize_by(designated_on: Date.parse('1977-07-30')) diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 544029c75..cd947cf18 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -116,6 +116,15 @@ FactoryBot.define do end end + trait :with_zone do + zones { + [ + create(:zone, labels: + [{ designated_on: Time.zone.now, name: "Ministère 1" }]) + ] + } + end + trait :routee do after(:create) do |procedure, _evaluator| procedure.groupe_instructeurs.create(label: 'deuxième groupe') diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index d60b7ed25..8334057eb 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -1243,7 +1243,7 @@ describe Procedure do describe '.missing_zones?' do before do - Flipper.enable :zonage + Rails.application.config.ds_zonage_enabled = true end let(:procedure) { create(:procedure, zones: []) } diff --git a/spec/system/administrateurs/procedure_attestation_template_spec.rb b/spec/system/administrateurs/procedure_attestation_template_spec.rb index f0633b151..3b4e27b3b 100644 --- a/spec/system/administrateurs/procedure_attestation_template_spec.rb +++ b/spec/system/administrateurs/procedure_attestation_template_spec.rb @@ -5,7 +5,7 @@ describe 'As an administrateur, I want to manage the procedure’s attestation', let(:administrateur) { create(:administrateur) } let(:procedure) do - create(:procedure, :with_service, :with_instructeur, + create(:procedure, :with_service, :with_instructeur, :with_zone, aasm_state: :brouillon, administrateurs: [administrateur], libelle: 'libellé de la procédure', diff --git a/spec/system/administrateurs/procedure_cloning_spec.rb b/spec/system/administrateurs/procedure_cloning_spec.rb index afba00816..945cb514e 100644 --- a/spec/system/administrateurs/procedure_cloning_spec.rb +++ b/spec/system/administrateurs/procedure_cloning_spec.rb @@ -6,7 +6,7 @@ describe 'As an administrateur I wanna clone a procedure', js: true do let(:administrateur) { create(:administrateur) } before do - create(:procedure, :with_service, :with_instructeur, + create(:procedure, :with_service, :with_instructeur, :with_zone, aasm_state: :publiee, administrateurs: [administrateur], libelle: 'libellé de la procédure', @@ -29,6 +29,11 @@ describe 'As an administrateur I wanna clone a procedure', js: true do find("#service .fr-btn").click click_on "Assigner" + # select zone + find("#zones .fr-btn").click + check Zone.last.current_label + click_on 'Enregistrer' + # then publish find('#publish-procedure-link').click expect(find_field('procedure_path').value).to eq 'libelle-de-la-procedure' diff --git a/spec/system/administrateurs/procedure_publish_spec.rb b/spec/system/administrateurs/procedure_publish_spec.rb index e459ebf8c..8fab1137b 100644 --- a/spec/system/administrateurs/procedure_publish_spec.rb +++ b/spec/system/administrateurs/procedure_publish_spec.rb @@ -10,6 +10,7 @@ describe 'Publishing a procedure', js: true do :with_path, :with_type_de_champ, :with_service, + :with_zone, instructeurs: instructeurs, administrateur: administrateur) end @@ -51,6 +52,7 @@ describe 'Publishing a procedure', js: true do create(:procedure, :with_path, :with_service, + :with_zone, instructeurs: instructeurs, administrateur: administrateur, types_de_champ_public: [{ type: :repetition, libelle: 'Enfants', children: [] }, { type: :drop_down_list, libelle: 'Civilité', options: [] }], diff --git a/spec/system/api_particulier/api_particulier_spec.rb b/spec/system/api_particulier/api_particulier_spec.rb index 38d0d5546..7d122593c 100644 --- a/spec/system/api_particulier/api_particulier_spec.rb +++ b/spec/system/api_particulier/api_particulier_spec.rb @@ -44,7 +44,7 @@ describe 'fetch API Particulier Data', js: true do context 'when an administrateur is logged in' do let(:procedure) do - create(:procedure, :with_service, :with_instructeur, + create(:procedure, :with_service, :with_instructeur, :with_zone, aasm_state: :brouillon, administrateurs: [administrateur], libelle: 'libellé de la procédure', diff --git a/spec/system/routing/full_scenario_spec.rb b/spec/system/routing/full_scenario_spec.rb index 97328fcb7..4524d22f7 100644 --- a/spec/system/routing/full_scenario_spec.rb +++ b/spec/system/routing/full_scenario_spec.rb @@ -1,6 +1,6 @@ describe 'The routing', js: true do let(:password) { 'a very complicated password' } - let(:procedure) { create(:procedure, :with_type_de_champ, :with_service, :for_individual) } + let(:procedure) { create(:procedure, :with_type_de_champ, :with_service, :for_individual, :with_zone) } let(:administrateur) { create(:administrateur, procedures: [procedure]) } let(:scientifique_user) { create(:user, password: password) } let(:litteraire_user) { create(:user, password: password) } diff --git a/spec/views/administrateurs/procedures/zones.html.haml_spec.rb b/spec/views/administrateurs/procedures/zones.html.haml_spec.rb index 9ab33d000..d42e3689f 100644 --- a/spec/views/administrateurs/procedures/zones.html.haml_spec.rb +++ b/spec/views/administrateurs/procedures/zones.html.haml_spec.rb @@ -3,7 +3,7 @@ describe 'administrateurs/procedures/zones.html.haml' do let(:populate_zones_task) { Rake::Task['after_party:populate_zones'] } before do - Flipper.enable(:zonage) + Rails.application.config.ds_zonage_enabled = true populate_zones_task.invoke end