Merge pull request #11052 from demarches-simplifiees/fix_linked_list_filter_again

ETQ instructeur: modification de l'id de column liste liée pour faire satisfaire le waf
This commit is contained in:
LeSim 2024-11-19 13:02:54 +01:00 committed by GitHub
commit 5a2ab37049
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 2 deletions

View file

@ -43,7 +43,7 @@ class Columns::LinkedDropDownColumn < Columns::ChampColumn
private private
def column_id = "type_de_champ/#{stable_id}->#{path}" def column_id = "type_de_champ/#{stable_id}.#{path}"
def typed_value(champ) def typed_value(champ)
primary_value, secondary_value = unpack_values(champ.value) primary_value, secondary_value = unpack_values(champ.value)

View file

@ -12,6 +12,13 @@ module ColumnsConcern
column = columns.find { _1.h_id == h_id } if h_id.present? column = columns.find { _1.h_id == h_id } if h_id.present?
column = columns.find { _1.label == label } if label.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? raise ActiveRecord::RecordNotFound.new("Column: unable to find h_id: #{h_id} or label: #{label} for procedure_id #{id}") if column.nil?
column column
@ -37,6 +44,7 @@ module ColumnsConcern
columns.concat(procedure_chorus_columns) if chorusable? && chorus_configuration.complete? columns.concat(procedure_chorus_columns) if chorusable? && chorus_configuration.complete?
# ensure the columns exist in main list # 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)) } columns.filter { _1.id.in?(self.columns.map(&:id)) }
end end
@ -48,6 +56,7 @@ module ColumnsConcern
columns.concat([groupe_instructeurs_id_column, followers_instructeurs_email_column]) columns.concat([groupe_instructeurs_id_column, followers_instructeurs_email_column])
# ensure the columns exist in main list # 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)) } columns.filter { _1.id.in?(self.columns.map(&:id)) }
end end

View file

@ -4,7 +4,8 @@ describe ColumnsConcern do
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
describe '#find_column' do 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 } let(:notifications_column) { procedure.notifications_column }
it do it do
@ -16,6 +17,17 @@ describe ColumnsConcern do
unknwon = 'unknown' unknwon = 'unknown'
expect { procedure.find_column(h_id: unknwon) }.to raise_error(ActiveRecord::RecordNotFound) 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
end end