diff --git a/app/components/editable_champ/section_component.rb b/app/components/editable_champ/section_component.rb index 9798b9e70..8f3870f55 100644 --- a/app/components/editable_champ/section_component.rb +++ b/app/components/editable_champ/section_component.rb @@ -17,7 +17,7 @@ class EditableChamp::SectionComponent < ApplicationComponent def header_section node = @nodes.first - @dossier.project_champ(node, @row_id) if node.is_a?(TypeDeChamp) && node.header_section? + @dossier.project_champ(node, row_id: @row_id) if node.is_a?(TypeDeChamp) && node.header_section? end def splitted_tail @@ -40,7 +40,7 @@ class EditableChamp::SectionComponent < ApplicationComponent when EditableChamp::SectionComponent [node, nil] else - [nil, @dossier.project_champ(node, @row_id)] + [nil, @dossier.project_champ(node, row_id: @row_id)] end end diff --git a/app/components/viewable_champ/section_component.rb b/app/components/viewable_champ/section_component.rb index 9120ca96c..27b3ccf7b 100644 --- a/app/components/viewable_champ/section_component.rb +++ b/app/components/viewable_champ/section_component.rb @@ -18,11 +18,11 @@ class ViewableChamp::SectionComponent < ApplicationComponent def header_section node = @nodes.first - @dossier.project_champ(node, @row_id) if node.is_a?(TypeDeChamp) && node.header_section? + @dossier.project_champ(node, row_id: @row_id) if node.is_a?(TypeDeChamp) && node.header_section? end def champs - tail.filter_map { _1.is_a?(TypeDeChamp) ? @dossier.project_champ(_1, @row_id) : nil } + tail.filter_map { _1.is_a?(TypeDeChamp) ? @dossier.project_champ(_1, row_id: @row_id) : nil } end def sections diff --git a/app/controllers/champs/champ_controller.rb b/app/controllers/champs/champ_controller.rb index 5af93d346..b551009f0 100644 --- a/app/controllers/champs/champ_controller.rb +++ b/app/controllers/champs/champ_controller.rb @@ -10,9 +10,9 @@ class Champs::ChampController < ApplicationController dossier = policy_scope(Dossier).includes(:champs, revision: [:types_de_champ]).find(params[:dossier_id]) type_de_champ = dossier.find_type_de_champ_by_stable_id(params[:stable_id]) if type_de_champ.repetition? - dossier.project_champ(type_de_champ, nil) + dossier.project_champ(type_de_champ) else - dossier.champ_for_update(type_de_champ, params_row_id, updated_by: current_user.email) + dossier.champ_for_update(type_de_champ, row_id: params_row_id, updated_by: current_user.email) end end diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index 62a2fc575..0d1bf2600 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -321,7 +321,7 @@ module Instructeurs def annotation @dossier = dossier_with_champs(pj_template: false) type_de_champ = @dossier.find_type_de_champ_by_stable_id(params[:stable_id], :private) - annotation = @dossier.project_champ(type_de_champ, params[:row_id]) + annotation = @dossier.project_champ(type_de_champ, row_id: params[:row_id]) respond_to do |format| format.turbo_stream do diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 1fff9841a..626cb0692 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -299,7 +299,7 @@ module Users def champ @dossier = dossier_with_champs(pj_template: false) type_de_champ = dossier.find_type_de_champ_by_stable_id(params[:stable_id], :public) - champ = dossier.project_champ(type_de_champ, params[:row_id]) + champ = dossier.project_champ(type_de_champ, row_id: params[:row_id]) respond_to do |format| format.turbo_stream do diff --git a/app/graphql/mutations/dossier_modifier_annotation.rb b/app/graphql/mutations/dossier_modifier_annotation.rb index ad3728236..01a25c077 100644 --- a/app/graphql/mutations/dossier_modifier_annotation.rb +++ b/app/graphql/mutations/dossier_modifier_annotation.rb @@ -46,7 +46,7 @@ module Mutations .find_by(type_champ: annotation_type_champ, stable_id:) return nil if type_de_champ.nil? - dossier.champ_for_update(type_de_champ, row_id, updated_by: current_administrateur.email) + dossier.champ_for_update(type_de_champ, row_id:, updated_by: current_administrateur.email) end def annotation_type_champ diff --git a/app/graphql/mutations/dossier_modifier_annotation_ajouter_ligne.rb b/app/graphql/mutations/dossier_modifier_annotation_ajouter_ligne.rb index cf65b97b1..61ee2069a 100644 --- a/app/graphql/mutations/dossier_modifier_annotation_ajouter_ligne.rb +++ b/app/graphql/mutations/dossier_modifier_annotation_ajouter_ligne.rb @@ -34,7 +34,7 @@ module Mutations .find_by(type_champ: TypeDeChamp.type_champs.fetch(:repetition), stable_id:) return nil if type_de_champ.nil? - dossier.project_champ(type_de_champ, nil) + dossier.project_champ(type_de_champ) end end end diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index 8aba5d352..10a3693d4 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -92,7 +92,7 @@ class AttestationTemplate < ApplicationRecord used_tags.filter_map do |used_tag| corresponding_type_de_champ = types_de_champ_by_tag_id[used_tag] - if corresponding_type_de_champ && dossier.project_champ(corresponding_type_de_champ, nil).blank? + if corresponding_type_de_champ && dossier.project_champ(corresponding_type_de_champ).blank? corresponding_type_de_champ end end diff --git a/app/models/concerns/dossier_champs_concern.rb b/app/models/concerns/dossier_champs_concern.rb index 40eea293d..176bc72b3 100644 --- a/app/models/concerns/dossier_champs_concern.rb +++ b/app/models/concerns/dossier_champs_concern.rb @@ -3,7 +3,7 @@ module DossierChampsConcern extend ActiveSupport::Concern - def project_champ(type_de_champ, row_id) + def project_champ(type_de_champ, row_id: nil) check_valid_row_id_on_read?(type_de_champ, row_id) champ = champs_by_public_id[type_de_champ.public_id(row_id)] if champ.nil? || !champ.is_type?(type_de_champ.type_champ) @@ -17,11 +17,11 @@ module DossierChampsConcern end def project_champs_public - @project_champs_public ||= revision.types_de_champ_public.map { project_champ(_1, nil) } + @project_champs_public ||= revision.types_de_champ_public.map { project_champ(_1) } end def project_champs_private - @project_champs_private ||= revision.types_de_champ_private.map { project_champ(_1, nil) } + @project_champs_private ||= revision.types_de_champ_private.map { project_champ(_1) } end def filled_champs_public @@ -54,7 +54,7 @@ module DossierChampsConcern def project_champs_public_all revision.types_de_champ_public.flat_map do |type_de_champ| - champ = project_champ(type_de_champ, nil) + champ = project_champ(type_de_champ) if type_de_champ.repetition? [champ] + project_rows_for(type_de_champ).flatten else @@ -65,7 +65,7 @@ module DossierChampsConcern def project_champs_private_all revision.types_de_champ_private.flat_map do |type_de_champ| - champ = project_champ(type_de_champ, nil) + champ = project_champ(type_de_champ) if type_de_champ.repetition? [champ] + project_rows_for(type_de_champ).flatten else @@ -81,7 +81,7 @@ module DossierChampsConcern row_ids = repetition_row_ids(type_de_champ) row_ids.map do |row_id| - children.map { project_champ(_1, row_id) } + children.map { project_champ(_1, row_id:) } end end @@ -101,19 +101,19 @@ module DossierChampsConcern .types_de_champ .filter { _1.stable_id.in?(stable_ids) } .filter { !_1.child?(revision) } - .map { _1.repetition? ? project_champ(_1, nil) : champ_for_update(_1, nil, updated_by: nil) } + .map { _1.repetition? ? project_champ(_1) : champ_for_update(_1, updated_by: nil) } end def champ_value_for_tag(type_de_champ, path = :value) champ = if type_de_champ.repetition? - project_champ(type_de_champ, nil) + project_champ(type_de_champ) else - filled_champ(type_de_champ, nil) + filled_champ(type_de_champ) end type_de_champ.champ_value_for_tag(champ, path) end - def champ_for_update(type_de_champ, row_id, updated_by:) + def champ_for_update(type_de_champ, row_id: nil, updated_by:) champ = champ_upsert_by!(type_de_champ, row_id) champ.updated_by = updated_by champ @@ -155,7 +155,7 @@ module DossierChampsConcern raise "Can't add row to non-repetition type de champ" if !type_de_champ.repetition? row_id = ULID.generate - champ = champ_for_update(type_de_champ, row_id, updated_by:) + champ = champ_for_update(type_de_champ, row_id:, updated_by:) champ.save! reset_champ_cache(champ) row_id @@ -164,7 +164,7 @@ module DossierChampsConcern def repetition_remove_row(type_de_champ, row_id, updated_by:) raise "Can't remove row from non-repetition type de champ" if !type_de_champ.repetition? - champ = champ_for_update(type_de_champ, row_id, updated_by:) + champ = champ_for_update(type_de_champ, row_id:, updated_by:) champ.discard! reset_champ_cache(champ) end @@ -191,7 +191,7 @@ module DossierChampsConcern champs.filter { stable_id_in_revision?(_1.stable_id) } end - def filled_champ(type_de_champ, row_id) + def filled_champ(type_de_champ, row_id: nil) champ = champs_by_public_id[type_de_champ.public_id(row_id)] if type_de_champ.champ_blank?(champ) || !champ.visible? nil diff --git a/app/models/concerns/dossier_clone_concern.rb b/app/models/concerns/dossier_clone_concern.rb index 582dec0d5..e147c9a20 100644 --- a/app/models/concerns/dossier_clone_concern.rb +++ b/app/models/concerns/dossier_clone_concern.rb @@ -175,10 +175,10 @@ module DossierCloneConcern end added_row_ids.each do |row_id, repetition_type_de_champ| - champ_for_update(repetition_type_de_champ, row_id, updated_by: user.email).save! + champ_for_update(repetition_type_de_champ, row_id:, updated_by: user.email).save! end removed_row_ids.each do |row_id, repetition_type_de_champ| - champ_for_update(repetition_type_de_champ, row_id, updated_by: user.email).discard! + champ_for_update(repetition_type_de_champ, row_id:, updated_by: user.email).discard! end end end diff --git a/app/models/concerns/dossier_export_concern.rb b/app/models/concerns/dossier_export_concern.rb index 887b48207..ad717c299 100644 --- a/app/models/concerns/dossier_export_concern.rb +++ b/app/models/concerns/dossier_export_concern.rb @@ -17,7 +17,7 @@ module DossierExportConcern def champ_values_for_export(types_de_champ, row_id: nil, export_template: nil, format:) types_de_champ.flat_map do |type_de_champ| - champ = filled_champ(type_de_champ, row_id) + champ = filled_champ(type_de_champ, row_id:) if export_template.present? export_template .columns_for_stable_id(type_de_champ.stable_id) diff --git a/app/models/concerns/dossier_sections_concern.rb b/app/models/concerns/dossier_sections_concern.rb index c4644dba3..fcfb4c1d7 100644 --- a/app/models/concerns/dossier_sections_concern.rb +++ b/app/models/concerns/dossier_sections_concern.rb @@ -33,7 +33,7 @@ module DossierSectionsConcern return "#{index}.#{index_in_repetition + 1}" if index_in_repetition else return index if tdc.stable_id == type_de_champ.stable_id - next unless project_champ(tdc, nil).visible? + next unless project_champ(tdc).visible? index += 1 if tdc.header_section? end diff --git a/app/models/types_de_champ/prefill_repetition_type_de_champ.rb b/app/models/types_de_champ/prefill_repetition_type_de_champ.rb index 5af53c178..36843d748 100644 --- a/app/models/types_de_champ/prefill_repetition_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_repetition_type_de_champ.rb @@ -65,7 +65,7 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh type_de_champ = revision.types_de_champ.find { _1.stable_id == stable_id } next unless type_de_champ - subchamp = champ.dossier.champ_for_update(type_de_champ, row_id, updated_by: nil) + subchamp = champ.dossier.champ_for_update(type_de_champ, row_id:, updated_by: nil) TypesDeChamp::PrefillTypeDeChamp.build(subchamp.type_de_champ, revision).to_assignable_attributes(subchamp, value) end.compact end diff --git a/spec/models/columns/champ_column_spec.rb b/spec/models/columns/champ_column_spec.rb index a1bf8b8b9..af5cec1fa 100644 --- a/spec/models/columns/champ_column_spec.rb +++ b/spec/models/columns/champ_column_spec.rb @@ -155,13 +155,13 @@ describe Columns::ChampColumn do def expect_type_de_champ_values(type, assertion) type_de_champ = types_de_champ.find { _1.type_champ == type } - champ = dossier.send(:filled_champ, type_de_champ, nil) + champ = dossier.send(:filled_champ, type_de_champ) columns = type_de_champ.columns(procedure:) expect(columns.map { _1.value(champ) }).to assertion end def retrieve_champ(type) type_de_champ = types_de_champ.find { _1.type_champ == type } - dossier.send(:filled_champ, type_de_champ, nil) + dossier.send(:filled_champ, type_de_champ) end end diff --git a/spec/models/concerns/dossier_champs_concern_spec.rb b/spec/models/concerns/dossier_champs_concern_spec.rb index 7d5df328e..96b43cfdb 100644 --- a/spec/models/concerns/dossier_champs_concern_spec.rb +++ b/spec/models/concerns/dossier_champs_concern_spec.rb @@ -36,13 +36,13 @@ RSpec.describe DossierChampsConcern do context "public champ" do let(:row_id) { nil } - subject { dossier.project_champ(type_de_champ_public, row_id) } + subject { dossier.project_champ(type_de_champ_public, row_id:) } it { expect(subject.persisted?).to be_truthy } context "in repetition" do let(:type_de_champ_public) { dossier.find_type_de_champ_by_stable_id(994) } - let(:row_id) { dossier.project_champ(type_de_champ_repetition, nil).row_ids.first } + let(:row_id) { dossier.project_champ(type_de_champ_repetition).row_ids.first } it { expect(subject.new_record?).to be_truthy @@ -88,7 +88,7 @@ RSpec.describe DossierChampsConcern do end context "private champ" do - subject { dossier.project_champ(type_de_champ_private, nil) } + subject { dossier.project_champ(type_de_champ_private) } it { expect(subject.persisted?).to be_truthy } @@ -225,7 +225,7 @@ RSpec.describe DossierChampsConcern do let(:row_id) { nil } context "public champ" do - subject { dossier.champ_for_update(type_de_champ_public, row_id, updated_by: dossier.user.email) } + subject { dossier.champ_for_update(type_de_champ_public, row_id:, updated_by: dossier.user.email) } it { expect(subject.persisted?).to be_truthy @@ -283,7 +283,7 @@ RSpec.describe DossierChampsConcern do end context "private champ" do - subject { dossier.champ_for_update(type_de_champ_private, row_id, updated_by: dossier.user.email) } + subject { dossier.champ_for_update(type_de_champ_private, row_id:, updated_by: dossier.user.email) } it { expect(subject.persisted?).to be_truthy @@ -304,9 +304,9 @@ RSpec.describe DossierChampsConcern do } end - let(:champ_99) { dossier.project_champ(dossier.find_type_de_champ_by_stable_id(99), nil) } - let(:champ_991) { dossier.project_champ(dossier.find_type_de_champ_by_stable_id(991), nil) } - let(:champ_994) { dossier.project_champ(dossier.find_type_de_champ_by_stable_id(994), row_id) } + let(:champ_99) { dossier.project_champ(dossier.find_type_de_champ_by_stable_id(99)) } + let(:champ_991) { dossier.project_champ(dossier.find_type_de_champ_by_stable_id(991)) } + let(:champ_994) { dossier.project_champ(dossier.find_type_de_champ_by_stable_id(994), row_id:) } subject { dossier.update_champs_attributes(attributes, :public, updated_by: dossier.user.email) } @@ -365,7 +365,7 @@ RSpec.describe DossierChampsConcern do } end - let(:annotation_995) { dossier.project_champ(dossier.find_type_de_champ_by_stable_id(995), nil) } + let(:annotation_995) { dossier.project_champ(dossier.find_type_de_champ_by_stable_id(995)) } subject { dossier.update_champs_attributes(attributes, :private, updated_by: dossier.user.email) } diff --git a/spec/models/concerns/dossier_clone_concern_spec.rb b/spec/models/concerns/dossier_clone_concern_spec.rb index 853454cdb..7854b7438 100644 --- a/spec/models/concerns/dossier_clone_concern_spec.rb +++ b/spec/models/concerns/dossier_clone_concern_spec.rb @@ -368,13 +368,13 @@ RSpec.describe DossierCloneConcern do context 'with new revision' do let(:added_champ) { tdc = forked_dossier.revision.types_de_champ.find { _1.libelle == "Un nouveau champ text" } - forked_dossier.champ_for_update(tdc, nil, updated_by: 'test') + forked_dossier.champ_for_update(tdc, updated_by: 'test') } let(:added_repetition_champ) { tdc_repetition = forked_dossier.revision.types_de_champ.find { _1.stable_id == 993 } tdc = forked_dossier.revision.types_de_champ.find { _1.libelle == "Texte en répétition" } row_id = forked_dossier.repetition_row_ids(tdc_repetition).first - forked_dossier.champ_for_update(tdc, row_id, updated_by: 'test') + forked_dossier.champ_for_update(tdc, row_id:, updated_by: 'test') } let(:removed_champ) { dossier.champs.find { _1.stable_id == 99 } } let(:updated_champ) { dossier.champs.find { _1.stable_id == 991 } } diff --git a/spec/models/concerns/dossier_sections_concern_spec.rb b/spec/models/concerns/dossier_sections_concern_spec.rb index 17f86be88..33b77a4b3 100644 --- a/spec/models/concerns/dossier_sections_concern_spec.rb +++ b/spec/models/concerns/dossier_sections_concern_spec.rb @@ -72,7 +72,7 @@ describe DossierSectionsConcern do context "when there are invisible sections" do it "index accordingly header sections" do expect(dossier.index_for_section_header(headers[0])).to eq(1) - expect(dossier.project_champ(headers[1], nil)).not_to be_visible + expect(dossier.project_champ(headers[1])).not_to be_visible expect(dossier.index_for_section_header(headers[2])).to eq(2) end end @@ -81,7 +81,7 @@ describe DossierSectionsConcern do let(:number_value) { 5 } it "index accordingly header sections" do expect(dossier.index_for_section_header(headers[0])).to eq(1) - expect(dossier.project_champ(headers[1], nil)).to be_visible + expect(dossier.project_champ(headers[1])).to be_visible expect(dossier.index_for_section_header(headers[1])).to eq(2) expect(dossier.index_for_section_header(headers[2])).to eq(3) end diff --git a/spec/models/concerns/tags_substitution_concern_spec.rb b/spec/models/concerns/tags_substitution_concern_spec.rb index d70dce98c..a9d10e3bc 100644 --- a/spec/models/concerns/tags_substitution_concern_spec.rb +++ b/spec/models/concerns/tags_substitution_concern_spec.rb @@ -258,7 +258,7 @@ describe TagsSubstitutionConcern, type: :model do context 'and the champ has a primary value' do before do - dossier.champ_for_update(type_de_champ, nil, updated_by: 'test').update(primary_value: 'primo') + dossier.champ_for_update(type_de_champ, updated_by: 'test').update(primary_value: 'primo') dossier.reload end @@ -266,7 +266,7 @@ describe TagsSubstitutionConcern, type: :model do context 'and the champ has a secondary value' do before do - dossier.champ_for_update(type_de_champ, nil, updated_by: 'test').update(secondary_value: 'secundo') + dossier.champ_for_update(type_de_champ, updated_by: 'test').update(secondary_value: 'secundo') dossier.reload end diff --git a/spec/models/type_de_champ_spec.rb b/spec/models/type_de_champ_spec.rb index b8d4e44f3..1ae4c52f9 100644 --- a/spec/models/type_de_champ_spec.rb +++ b/spec/models/type_de_champ_spec.rb @@ -17,7 +17,7 @@ describe TypeDeChamp do it do dossier.revision.types_de_champ_public.each do |type_de_champ| - champ = dossier.project_champ(type_de_champ, nil) + champ = dossier.project_champ(type_de_champ) expect(type_de_champ.dynamic_type.class.name).to match(/^TypesDeChamp::/) expect(champ.class.name).to match(/^Champs::/) end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 170837f9c..8298dfceb 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -127,7 +127,7 @@ RSpec.configure do |config| module SpecHelpers def champ_for_update(champ) - champ.dossier.champ_for_update(champ.type_de_champ, champ.row_id, updated_by: 'test') + champ.dossier.champ_for_update(champ.type_de_champ, row_id: champ.row_id, updated_by: 'test') end end diff --git a/spec/views/shared/dossiers/_edit.html.haml_spec.rb b/spec/views/shared/dossiers/_edit.html.haml_spec.rb index d2222c027..4271d129b 100644 --- a/spec/views/shared/dossiers/_edit.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_edit.html.haml_spec.rb @@ -19,9 +19,9 @@ describe 'shared/dossiers/edit', type: :view do let(:type_de_champ_checkbox) { procedure.draft_types_de_champ_public.find(&:checkbox?) } let(:type_de_champ_textarea) { procedure.draft_types_de_champ_public.find(&:textarea?) } - let(:champ_checkbox) { dossier.project_champ(type_de_champ_checkbox, nil) } - let(:champ_dossier_link) { dossier.project_champ(type_de_champ_dossier_link, nil) } - let(:champ_textarea) { dossier.project_champ(type_de_champ_textarea, nil) } + let(:champ_checkbox) { dossier.project_champ(type_de_champ_checkbox) } + let(:champ_dossier_link) { dossier.project_champ(type_de_champ_dossier_link) } + let(:champ_textarea) { dossier.project_champ(type_de_champ_textarea) } let(:types_de_champ_public) { [{ type: :checkbox }, { type: :header_section }, { type: :explication }, { type: :dossier_link }, { type: :textarea }] }