From fa64e8f1123628156b75f5f8c17d8a061a9e71d3 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 15 Nov 2024 16:44:32 +0100 Subject: [PATCH 1/3] fix: change `>` char in favor of `.` in linked_drop_column.column_id Rails `'>'.to_json` produce `\u003e` because of an html entity escaping system to work around some bugs in browser (see https://github.com/rails/rails/blob/dd8f7185faeca6ee968a6e9367f6d8601a83b8db/activesupport/lib/active_support/json/encoding.rb#L43 ) But our waf dislike `\u003e` and reject xhr request with such char --- app/models/columns/linked_drop_down_column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/columns/linked_drop_down_column.rb b/app/models/columns/linked_drop_down_column.rb index 6399137b0..c7611168e 100644 --- a/app/models/columns/linked_drop_down_column.rb +++ b/app/models/columns/linked_drop_down_column.rb @@ -43,7 +43,7 @@ class Columns::LinkedDropDownColumn < Columns::ChampColumn 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) From aa0b7f53ef847cbbbf040bfbf68b8c4ca7ff3ea8 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 15 Nov 2024 16:45:32 +0100 Subject: [PATCH 2/3] small comment explaining why we need to ensure used columns are present in `procedure.columns` --- app/models/concerns/columns_concern.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/concerns/columns_concern.rb b/app/models/concerns/columns_concern.rb index 5d61dc982..1e02c7370 100644 --- a/app/models/concerns/columns_concern.rb +++ b/app/models/concerns/columns_concern.rb @@ -37,6 +37,7 @@ module ColumnsConcern 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 @@ -48,6 +49,7 @@ module ColumnsConcern 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 From 38e998c2792aa949d73a829917269a576f45a2c6 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 15 Nov 2024 17:00:44 +0100 Subject: [PATCH 3/3] fix: allow previous id with `->` to work --- app/models/concerns/columns_concern.rb | 7 +++++++ spec/models/concerns/columns_concern_spec.rb | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/columns_concern.rb b/app/models/concerns/columns_concern.rb index 1e02c7370..d845bd7d7 100644 --- a/app/models/concerns/columns_concern.rb +++ b/app/models/concerns/columns_concern.rb @@ -12,6 +12,13 @@ module ColumnsConcern 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 diff --git a/spec/models/concerns/columns_concern_spec.rb b/spec/models/concerns/columns_concern_spec.rb index f6666517f..8d68c87f2 100644 --- a/spec/models/concerns/columns_concern_spec.rb +++ b/spec/models/concerns/columns_concern_spec.rb @@ -4,7 +4,8 @@ describe ColumnsConcern do 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 @@ -16,6 +17,17 @@ describe ColumnsConcern do 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