[#3477] Extract helper method

This commit is contained in:
Frederic Merizen 2019-02-27 16:48:56 +01:00 committed by Frederic Merizen
parent 656f0df377
commit e8747f7c38

View file

@ -160,20 +160,12 @@ class ProcedurePresentation < ApplicationRecord
def check_allowed_displayed_fields def check_allowed_displayed_fields
displayed_fields.each do |field| displayed_fields.each do |field|
table = field['table'] check_allowed_field(:displayed_fields, field)
column = field['column']
if !valid_column?(table, column)
errors.add(:displayed_fields, "#{table}.#{column} nest pas une colonne permise")
end
end end
end end
def check_allowed_sort_column def check_allowed_sort_column
table = sort['table'] check_allowed_field(:sort, sort, EXTRA_SORT_COLUMNS)
column = sort['column']
if !valid_column?(table, column, EXTRA_SORT_COLUMNS)
errors.add(:sort, "#{table}.#{column} nest pas une colonne permise")
end
end end
def check_allowed_sort_order def check_allowed_sort_order
@ -186,15 +178,19 @@ class ProcedurePresentation < ApplicationRecord
def check_allowed_filter_columns def check_allowed_filter_columns
filters.each do |_, columns| filters.each do |_, columns|
columns.each do |column| columns.each do |column|
table = column['table'] check_allowed_field(:filters, column)
column = column['column']
if !valid_column?(table, column)
errors.add(:filters, "#{table}.#{column} nest pas une colonne permise")
end
end end
end end
end end
def check_allowed_field(kind, field, extra_columns = {})
table = field['table']
column = field['column']
if !valid_column?(table, column, extra_columns)
errors.add(kind, "#{table}.#{column} nest pas une colonne permise")
end
end
def assert_matching_procedure(dossier) def assert_matching_procedure(dossier)
if dossier.procedure != procedure if dossier.procedure != procedure
raise "Procedure mismatch (expected #{procedure.id}, got #{dossier.procedure.id})" raise "Procedure mismatch (expected #{procedure.id}, got #{dossier.procedure.id})"