From 4d298600e6ae4d51479a86903c626550a964ec18 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Mon, 24 Jul 2023 12:11:00 +0200 Subject: [PATCH 01/40] chore(graphql): update stored query to include corrections --- app/graphql/api/v2/stored_query.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/graphql/api/v2/stored_query.rb b/app/graphql/api/v2/stored_query.rb index 2ad9d408b95..ff36b5df560 100644 --- a/app/graphql/api/v2/stored_query.rb +++ b/app/graphql/api/v2/stored_query.rb @@ -43,6 +43,7 @@ def self.get(query_id) $includeInstructeurs: Boolean = true $includeAvis: Boolean = false $includeMessages: Boolean = false + $includeCorrections: Boolean = false $includeGeometry: Boolean = false ) { demarche(number: $demarcheNumber) { @@ -135,6 +136,7 @@ def self.get(query_id) $includeInstructeurs: Boolean = true $includeAvis: Boolean = false $includeMessages: Boolean = false + $includeCorrections: Boolean = false $includeGeometry: Boolean = false ) { groupeInstructeur(number: $groupeInstructeurNumber) { @@ -201,6 +203,7 @@ def self.get(query_id) $includeInstructeurs: Boolean = true $includeAvis: Boolean = false $includeMessages: Boolean = false + $includeCorrections: Boolean = false $includeGeometry: Boolean = false ) { dossier(number: $dossierNumber) { @@ -250,6 +253,7 @@ def self.get(query_id) dateTraitement dateExpiration dateSuppressionParUsager + dateDerniereCorrectionEnAttente @include(if: $includeCorrections) motivation motivationAttachment { ...FileFragment @@ -409,6 +413,10 @@ def self.get(query_id) attachments { ...FileFragment } + correction @include(if: $includeCorrections) { + reason + dateResolution + } } fragment GeoAreaFragment on GeoArea { From c86651cfc5da45782a42ebabafa3ca7169993362 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 27 Jul 2023 14:35:01 +0200 Subject: [PATCH 02/40] refactor(routing): refactor options for select --- app/components/procedure/one_groupe_management_component.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/procedure/one_groupe_management_component.rb b/app/components/procedure/one_groupe_management_component.rb index bba162b9b6d..80ab87cd19c 100644 --- a/app/components/procedure/one_groupe_management_component.rb +++ b/app/components/procedure/one_groupe_management_component.rb @@ -60,6 +60,6 @@ def available_values_for_select(targeted_champ) return [] if targeted_champ.is_a?(Logic::Empty) targeted_champ .options(@revision.types_de_champ_public) - .map { |tdc| [tdc.first, constant(tdc.first).to_json] } + .map { |(label, value)| [label, constant(value).to_json] } end end From 4749b436971ee053118eb524e9b75199365ffcc1 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 27 Jul 2023 14:35:47 +0200 Subject: [PATCH 03/40] refactor(routing): use drop_down_options --- .../administrateurs/groupe_instructeurs_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb index 101d05c1f22..c0525b819b1 100644 --- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb +++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb @@ -40,7 +40,7 @@ def create_simple_routing tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id } - tdc_options = tdc.options["drop_down_options"].reject(&:empty?) + tdc_options = tdc.drop_down_options.reject(&:empty?) tdc_options.each do |option_label| gi = @procedure.groupe_instructeurs.find_by({ label: option_label }) || @procedure.groupe_instructeurs From 7680d5093e59201dda26c4da4ed62a93c8b4f34f Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 27 Jul 2023 14:37:01 +0200 Subject: [PATCH 04/40] feat(routing): create routing rule for dropdown other option --- .../groupe_instructeurs_controller.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb index c0525b819b1..33491a1be02 100644 --- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb +++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb @@ -43,9 +43,19 @@ def create_simple_routing tdc_options = tdc.drop_down_options.reject(&:empty?) tdc_options.each do |option_label| - gi = @procedure.groupe_instructeurs.find_by({ label: option_label }) || @procedure.groupe_instructeurs - .create({ label: option_label, instructeurs: [current_administrateur.instructeur] }) - gi.update(routing_rule: ds_eq(champ_value(stable_id), constant(gi.label))) + routing_rule = ds_eq(champ_value(stable_id), constant(option_label)) + @procedure + .groupe_instructeurs + .find_or_create_by(label: option_label) + .update(instructeurs: [current_administrateur.instructeur], routing_rule:) + end + + if tdc.drop_down_other? + routing_rule = ds_eq(champ_value(stable_id), constant(Champs::DropDownListChamp::OTHER)) + @procedure + .groupe_instructeurs + .find_or_create_by(label: 'Autre') + .update(instructeurs: [current_administrateur.instructeur], routing_rule:) end @procedure.toggle_routing From 155a797abaf1c11469794fd67207aba8239fe74b Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 26 Jul 2023 17:28:28 +0200 Subject: [PATCH 05/40] feat(routing): update method checking if routling rule match tdc --- app/models/groupe_instructeur.rb | 3 ++- app/models/type_de_champ.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/groupe_instructeur.rb b/app/models/groupe_instructeur.rb index 7acf19561d7..133d0171144 100644 --- a/app/models/groupe_instructeur.rb +++ b/app/models/groupe_instructeur.rb @@ -117,7 +117,8 @@ def other_groupe_instructeurs def routing_rule_matches_tdc? routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: routing_rule.left.stable_id) - routing_rule.right.value.in?(routing_tdc.options['drop_down_options']) + options = routing_tdc.options_with_drop_down_other + routing_rule.right.value.in?(options) end serialize :routing_rule, LogicSerializer diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 39a23f5a892..e6dc16c5740 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -517,6 +517,14 @@ def drop_down_list_enabled_non_empty_options (drop_down_list_options - drop_down_list_disabled_options).reject(&:empty?) end + def options_with_drop_down_other + if drop_down_other? + drop_down_options + [Champs::DropDownListChamp::OTHER] + else + drop_down_options + end + end + def layer_enabled?(layer) options && options[layer] && options[layer] != '0' end From c85d7f8a5a2f8712e098fdb500e9e5c8aef2374d Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 26 Jul 2023 17:29:54 +0200 Subject: [PATCH 06/40] feat(routing): compute from selected if drop_down_other --- app/models/logic/champ_value.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb index 462f338805d..dee68529f07 100644 --- a/app/models/logic/champ_value.rb +++ b/app/models/logic/champ_value.rb @@ -31,7 +31,7 @@ def compute(champs) targeted_champ = champ(champs) return nil if !targeted_champ.visible? - return nil if targeted_champ.blank? + return nil if targeted_champ.blank? & !targeted_champ.drop_down_other? # on dépense 22ms ici, à cause du map, mais on doit pouvoir passer par un champ type case targeted_champ.type From f2afe5008f769e1d6face37317af5870725d3716 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 13 Jul 2023 18:39:48 +0200 Subject: [PATCH 07/40] chore(schema): remove dossier_corrections#kind, replaced in 5998cf --- app/models/dossier_correction.rb | 2 -- .../20230713163641_remove_dossier_corrections_kind.rb | 7 +++++++ db/schema.rb | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20230713163641_remove_dossier_corrections_kind.rb diff --git a/app/models/dossier_correction.rb b/app/models/dossier_correction.rb index c2ff19b1322..77dcdbf6663 100644 --- a/app/models/dossier_correction.rb +++ b/app/models/dossier_correction.rb @@ -14,8 +14,6 @@ class DossierCorrection < ApplicationRecord belongs_to :dossier belongs_to :commentaire - self.ignored_columns += ['kind'] - validates_associated :commentaire scope :pending, -> { where(resolved_at: nil) } diff --git a/db/migrate/20230713163641_remove_dossier_corrections_kind.rb b/db/migrate/20230713163641_remove_dossier_corrections_kind.rb new file mode 100644 index 00000000000..2b387513cbb --- /dev/null +++ b/db/migrate/20230713163641_remove_dossier_corrections_kind.rb @@ -0,0 +1,7 @@ +class RemoveDossierCorrectionsKind < ActiveRecord::Migration[7.0] + def change + safety_assured do + remove_column :dossier_corrections, :kind, :string, default: 'incorrect', null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 675a76a1527..4f486cfdc6a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_07_19_112020) do +ActiveRecord::Schema[7.0].define(version: 2023_07_18_113920) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -336,7 +336,6 @@ t.bigint "dossier_id", null: false t.datetime "resolved_at", precision: 6 t.datetime "updated_at", precision: 6, null: false - t.string "kind", default: "correction", null: false t.string "reason", default: "incorrect", null: false t.index ["commentaire_id"], name: "index_dossier_corrections_on_commentaire_id" t.index ["dossier_id"], name: "index_dossier_corrections_on_dossier_id" From cb3d971dcba33deabca4e95493f3f01fd1e886cf Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 28 Jul 2023 10:18:39 +0200 Subject: [PATCH 08/40] fix(routing): display Autre instead of __other__ in gis list --- app/models/logic/constant.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/logic/constant.rb b/app/models/logic/constant.rb index 201e3722803..e1042d580f0 100644 --- a/app/models/logic/constant.rb +++ b/app/models/logic/constant.rb @@ -17,6 +17,8 @@ def to_s(_type_de_champs = []) I18n.t('utils.yes') when FalseClass I18n.t('utils.no') + when Champs::DropDownListChamp::OTHER + 'Autre' else @value.to_s end From 550b92500366bd4d5089aaec192ea013c36a99a1 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 28 Jul 2023 14:06:34 +0200 Subject: [PATCH 09/40] db(routing): task to update routing rule for groupe instructeurs routing from drop down other option --- ...r_groups_routing_from_drop_down_other.rake | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/tasks/deployment/20230728085422_update_routing_rule_for_groups_routing_from_drop_down_other.rake diff --git a/lib/tasks/deployment/20230728085422_update_routing_rule_for_groups_routing_from_drop_down_other.rake b/lib/tasks/deployment/20230728085422_update_routing_rule_for_groups_routing_from_drop_down_other.rake new file mode 100644 index 00000000000..67297580089 --- /dev/null +++ b/lib/tasks/deployment/20230728085422_update_routing_rule_for_groups_routing_from_drop_down_other.rake @@ -0,0 +1,23 @@ +namespace :after_party do + desc 'Deployment task: update_routing_rule_for_groups_routing_from_drop_down_other' + task update_routing_rule_for_groups_routing_from_drop_down_other: :environment do + puts "Running deploy task 'update_routing_rule_for_groups_routing_from_drop_down_other'" + + # Put your task implementation HERE. + include Logic + + GroupeInstructeur + .joins(:procedure) + .where(procedures: { routing_enabled: true }) + .in_batches do |groupe_instructeurs| + groupe_instructeurs + .filter { |gi| gi.routing_rule.present? && gi.routing_rule.right.value == 'Autre' } + .each { |gi| gi.update(routing_rule: ds_eq(gi.routing_rule.left, constant('__other__'))) } + end + + # Update task as completed. If you remove the line below, the task will + # run with every deploy (or every time you call after_party:run). + AfterParty::TaskRecord + .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp + end +end From af8b423e4c145faafa23273371edfc973dae6fa0 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Mon, 31 Jul 2023 10:56:05 +0200 Subject: [PATCH 10/40] fix siren spec --- spec/lib/api_entreprise/api_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/lib/api_entreprise/api_spec.rb b/spec/lib/api_entreprise/api_spec.rb index bf69b214199..20d90da1baf 100644 --- a/spec/lib/api_entreprise/api_spec.rb +++ b/spec/lib/api_entreprise/api_spec.rb @@ -108,6 +108,7 @@ let(:siren) { procedure.service.siret[0..8] } let(:dinum_siret) { "13002526500013" } it 'send default recipient' do + ENV["API_ENTREPRISE_DEFAULT_SIRET"] = dinum_siret subject expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/).with(query: hash_including({ recipient: dinum_siret })) end From 2c4679e08b2a385cf13a535bbd55bef008b7f958 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 28 Jul 2023 14:13:33 +0200 Subject: [PATCH 11/40] show in manager when user blocked --- app/dashboards/user_dashboard.rb | 6 +++++- app/views/manager/application/_user_meta.html.erb | 3 ++- app/views/manager/users/show.html.erb | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/dashboards/user_dashboard.rb b/app/dashboards/user_dashboard.rb index 5e9c13ebc9c..4a02aa84436 100644 --- a/app/dashboards/user_dashboard.rb +++ b/app/dashboards/user_dashboard.rb @@ -13,6 +13,8 @@ class UserDashboard < Administrate::BaseDashboard confirmed?: Field::Boolean, created_at: Field::DateTime, updated_at: Field::DateTime, + blocked_at: Field::DateTime, + blocked_reason: Field::String, current_sign_in_at: Field::DateTime, dossiers: Field::HasMany }.freeze @@ -36,7 +38,9 @@ class UserDashboard < Administrate::BaseDashboard :email, :confirmed?, :current_sign_in_at, - :created_at + :created_at, + :blocked_at, + :blocked_reason ].freeze # FORM_ATTRIBUTES diff --git a/app/views/manager/application/_user_meta.html.erb b/app/views/manager/application/_user_meta.html.erb index 46185a0a406..4b76f3ff749 100644 --- a/app/views/manager/application/_user_meta.html.erb +++ b/app/views/manager/application/_user_meta.html.erb @@ -11,7 +11,8 @@ Usager
- <%= link_to('Voir son compte utilisateur', manager_user_path(user)) %> + <% style = "background-color: red;color: white;" if user.blocked_at %> + <%= link_to('Voir son compte utilisateur', manager_user_path(user), style: style) %>
diff --git a/app/views/manager/users/show.html.erb b/app/views/manager/users/show.html.erb index 24b793aa982..03e68bc267c 100644 --- a/app/views/manager/users/show.html.erb +++ b/app/views/manager/users/show.html.erb @@ -20,8 +20,9 @@ as well as a link to its edit page. <% user = page.resource %>