From ecbf98514769911c0b3d6bb252a4854ed1018141 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 27 Sep 2024 14:45:06 +0200 Subject: [PATCH] refactor(dossier): champs_* -> project_champs_* --- app/components/dossiers/errors_full_messages_component.rb | 1 - app/dashboards/dossier_dashboard.rb | 4 ++-- app/models/dossier.rb | 4 ---- app/models/dossier_preloader.rb | 4 +--- ...ackfill_cloned_champs_private_piece_justificatives_task.rb | 4 ++-- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/app/components/dossiers/errors_full_messages_component.rb b/app/components/dossiers/errors_full_messages_component.rb index 207170e8c..01710ed7f 100644 --- a/app/components/dossiers/errors_full_messages_component.rb +++ b/app/components/dossiers/errors_full_messages_component.rb @@ -10,7 +10,6 @@ class Dossiers::ErrorsFullMessagesComponent < ApplicationComponent def dedup_and_partitioned_errors @dossier.errors.to_enum # ActiveModel::Errors.to_a is an alias to full_messages, we don't want that .to_a # but enum.to_a gives back an array - .uniq { |error| [error.inner_error.base] } # dedup cumulated errors from dossier.champs, dossier.champs_public, dossier.champs_private which run the validator one time per association .map { |error| to_error_descriptor(error) } end diff --git a/app/dashboards/dossier_dashboard.rb b/app/dashboards/dossier_dashboard.rb index 1420dba52..f691a69f4 100644 --- a/app/dashboards/dossier_dashboard.rb +++ b/app/dashboards/dossier_dashboard.rb @@ -23,7 +23,7 @@ class DossierDashboard < Administrate::BaseDashboard en_construction_at: Field::DateTime, en_instruction_at: Field::DateTime, processed_at: Field::DateTime, - champs_public: ChampCollectionField, + project_champs_public: ChampCollectionField, groupe_instructeur: Field::BelongsTo }.freeze @@ -47,7 +47,7 @@ class DossierDashboard < Administrate::BaseDashboard :state, :procedure, :groupe_instructeur, - :champs_public, + :project_champs_public, :created_at, :updated_at, :hidden_by_user_at, diff --git a/app/models/dossier.rb b/app/models/dossier.rb index c6b5b2714..9a980ae60 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -49,8 +49,6 @@ class Dossier < ApplicationRecord # We have to remove champs in a particular order - champs with a reference to a parent have to be # removed first, otherwise we get a foreign key constraint error. has_many :champs_to_destroy, -> { order(:parent_id) }, class_name: 'Champ', inverse_of: false, dependent: :destroy - has_many :champs_public, -> { root.public_only }, class_name: 'Champ', inverse_of: false - has_many :champs_private, -> { root.private_only }, class_name: 'Champ', inverse_of: false has_many :commentaires, inverse_of: :dossier, dependent: :destroy has_many :preloaded_commentaires, -> { includes(:dossier_correction, piece_jointe_attachments: :blob) }, class_name: 'Commentaire', inverse_of: :dossier @@ -142,8 +140,6 @@ class Dossier < ApplicationRecord after_destroy_commit :log_destroy accepts_nested_attributes_for :champs - accepts_nested_attributes_for :champs_public - accepts_nested_attributes_for :champs_private accepts_nested_attributes_for :individual include AASM diff --git a/app/models/dossier_preloader.rb b/app/models/dossier_preloader.rb index 7b32e65f4..6882c23c9 100644 --- a/app/models/dossier_preloader.rb +++ b/app/models/dossier_preloader.rb @@ -39,7 +39,7 @@ class DossierPreloader def revisions(pj_template: false) @revisions ||= ProcedureRevision.where(id: @dossiers.pluck(:revision_id).uniq) - .includes(types_de_champ: pj_template ? { piece_justificative_template_attachment: :blob } : []) + .includes(types_de_champ_public: [], types_de_champ_private: [], types_de_champ: pj_template ? { piece_justificative_template_attachment: :blob } : []) .index_by(&:id) end @@ -80,8 +80,6 @@ class DossierPreloader dossier.association(:revision).target = revision end dossier.association(:champs).target = champs - dossier.association(:champs_public).target = dossier.project_champs_public - dossier.association(:champs_private).target = dossier.project_champs_private # remove once parent_id is deprecated champs_by_parent_id = champs.group_by(&:parent_id) diff --git a/app/tasks/maintenance/backfill_cloned_champs_private_piece_justificatives_task.rb b/app/tasks/maintenance/backfill_cloned_champs_private_piece_justificatives_task.rb index ad32ece93..23ad7af96 100644 --- a/app/tasks/maintenance/backfill_cloned_champs_private_piece_justificatives_task.rb +++ b/app/tasks/maintenance/backfill_cloned_champs_private_piece_justificatives_task.rb @@ -7,11 +7,11 @@ module Maintenance end def process(cloned_dossier) - cloned_dossier.champs_private + cloned_dossier.project_champs_private .filter { checkable_pj?(_1, cloned_dossier) } .map do |cloned_champ| parent_champ = cloned_dossier.parent_dossier - .champs_private + .project_champs_private .find { _1.stable_id == cloned_champ.stable_id } next if !parent_champ