Skip to content

Commit

Permalink
Merge pull request #11052 from demarches-simplifiees/fix_linked_list_…
Browse files Browse the repository at this point in the history
…filter_again

ETQ instructeur: modification de l'id de column liste liée pour faire satisfaire le waf
  • Loading branch information
LeSim authored Nov 19, 2024
2 parents c65fcf0 + 38e998c commit 5a2ab37
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/columns/linked_drop_down_column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def filtered_ids(dossiers, search_terms)

private

def column_id = "type_de_champ/#{stable_id}->#{path}"
def column_id = "type_de_champ/#{stable_id}.#{path}"

def typed_value(champ)
primary_value, secondary_value = unpack_values(champ.value)
Expand Down
9 changes: 9 additions & 0 deletions app/models/concerns/columns_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def find_column(h_id: nil, label: nil)
column = columns.find { _1.h_id == h_id } if h_id.present?
column = columns.find { _1.label == label } if label.present?

# TODO: to remove after linked_drop_down column column_id migration
if column.nil? && h_id.is_a?(Hash) && h_id[:column_id].present?
h_id[:column_id].gsub!('->', '.')

column = columns.find { _1.h_id == h_id }
end

raise ActiveRecord::RecordNotFound.new("Column: unable to find h_id: #{h_id} or label: #{label} for procedure_id #{id}") if column.nil?

column
Expand All @@ -37,6 +44,7 @@ def usager_columns_for_export
columns.concat(procedure_chorus_columns) if chorusable? && chorus_configuration.complete?

# ensure the columns exist in main list
# otherwise, they will be found by the find_column method
columns.filter { _1.id.in?(self.columns.map(&:id)) }
end

Expand All @@ -48,6 +56,7 @@ def dossier_columns_for_export
columns.concat([groupe_instructeurs_id_column, followers_instructeurs_email_column])

# ensure the columns exist in main list
# otherwise, they will be found by the find_column method
columns.filter { _1.id.in?(self.columns.map(&:id)) }
end

Expand Down
14 changes: 13 additions & 1 deletion spec/models/concerns/columns_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
let(:procedure_id) { procedure.id }

describe '#find_column' do
let(:procedure) { build(:procedure) }
let(:types_de_champ_public) { [{ type: :linked_drop_down_list, libelle: 'linked' }] }
let(:procedure) { create(:procedure, types_de_champ_public:) }
let(:notifications_column) { procedure.notifications_column }

it do
Expand All @@ -16,6 +17,17 @@

unknwon = 'unknown'
expect { procedure.find_column(h_id: unknwon) }.to raise_error(ActiveRecord::RecordNotFound)

value_column = procedure.find_column(label: 'linked')

procedure_id = procedure.id
linked_tdc = procedure.active_revision.types_de_champ
.find { _1.type_champ == 'linked_drop_down_list' }

column_id = "type_de_champ/#{linked_tdc.stable_id}->value"

h_id = { procedure_id:, column_id: }
expect(procedure.find_column(h_id:)).to eq(value_column)
end
end

Expand Down

0 comments on commit 5a2ab37

Please sign in to comment.