[#3477] Make sanitized_column a class method

This commit is contained in:
Frederic Merizen 2019-02-26 19:17:33 +01:00 committed by Frederic Merizen
parent 7241e43a7c
commit f34e65c207

View file

@ -94,7 +94,7 @@ class ProcedurePresentation < ApplicationRecord
.pluck(:id) .pluck(:id)
when 'self', 'user', 'individual', 'etablissement' when 'self', 'user', 'individual', 'etablissement'
return (table == 'self' ? dossiers : dossiers.includes(table)) return (table == 'self' ? dossiers : dossiers.includes(table))
.order("#{sanitized_column(table, column)} #{order}") .order("#{self.class.sanitized_column(table, column)} #{order}")
.pluck(:id) .pluck(:id)
end end
end end
@ -103,7 +103,7 @@ class ProcedurePresentation < ApplicationRecord
dossiers.each { |dossier| assert_matching_procedure(dossier) } dossiers.each { |dossier| assert_matching_procedure(dossier) }
filters[statut].group_by { |filter| filter.slice('table', 'column') } .map do |field, filters| filters[statut].group_by { |filter| filter.slice('table', 'column') } .map do |field, filters|
table, column = field.values_at('table', 'column') table, column = field.values_at('table', 'column')
table_column = sanitized_column(table, column) table_column = self.class.sanitized_column(table, column)
values = filters.pluck('value') values = filters.pluck('value')
case table case table
when 'self' when 'self'
@ -268,7 +268,7 @@ class ProcedurePresentation < ApplicationRecord
@column_whitelist[table] || [] @column_whitelist[table] || []
end end
def sanitized_column(table, column) def self.sanitized_column(table, column)
[(table == 'self' ? 'dossier' : table).pluralize, column] [(table == 'self' ? 'dossier' : table).pluralize, column]
.map { |name| ActiveRecord::Base.connection.quote_column_name(name) } .map { |name| ActiveRecord::Base.connection.quote_column_name(name) }
.join('.') .join('.')