[#2750] Remove redundant references to procedure
This commit is contained in:
parent
462c818025
commit
f59984ea70
1 changed files with 16 additions and 20 deletions
|
@ -16,7 +16,7 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
displayed_fields.each do |field|
|
displayed_fields.each do |field|
|
||||||
table = field['table']
|
table = field['table']
|
||||||
column = field['column']
|
column = field['column']
|
||||||
if !valid_column?(procedure, table, column)
|
if !valid_column?(table, column)
|
||||||
errors.add(:filters, "#{table}.#{column} n’est pas une colonne permise")
|
errors.add(:filters, "#{table}.#{column} n’est pas une colonne permise")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
def check_allowed_sort_column
|
def check_allowed_sort_column
|
||||||
table = sort['table']
|
table = sort['table']
|
||||||
column = sort['column']
|
column = sort['column']
|
||||||
if !valid_sort_column?(procedure, table, column)
|
if !valid_sort_column?(table, column)
|
||||||
errors.add(:sort, "#{table}.#{column} n’est pas une colonne permise")
|
errors.add(:sort, "#{table}.#{column} n’est pas une colonne permise")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,7 +35,7 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
columns.each do |column|
|
columns.each do |column|
|
||||||
table = column['table']
|
table = column['table']
|
||||||
column = column['column']
|
column = column['column']
|
||||||
if !valid_column?(procedure, table, column)
|
if !valid_column?(table, column)
|
||||||
errors.add(:filters, "#{table}.#{column} n’est pas une colonne permise")
|
errors.add(:filters, "#{table}.#{column} n’est pas une colonne permise")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -86,7 +86,7 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_value(dossier, table, column)
|
def get_value(dossier, table, column)
|
||||||
assert_valid_column(dossier.procedure, table, column)
|
assert_valid_column(table, column)
|
||||||
|
|
||||||
case table
|
case table
|
||||||
when 'self'
|
when 'self'
|
||||||
|
@ -184,27 +184,23 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_valid_column(procedure, table, column)
|
def assert_valid_column(table, column)
|
||||||
if !valid_column?(procedure, table, column)
|
if !valid_column?(table, column)
|
||||||
raise "Invalid column #{table}.#{column}"
|
raise "Invalid column #{table}.#{column}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_column?(procedure, table, column)
|
def valid_column?(table, column)
|
||||||
valid_columns_for_table(procedure, table).include?(column)
|
valid_columns_for_table(table).include?(column)
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_columns_for_table(procedure, table)
|
def valid_columns_for_table(table)
|
||||||
@column_whitelist ||= {}
|
@column_whitelist ||= fields
|
||||||
|
.group_by { |field| field['table'] }
|
||||||
|
.map { |table, fields| [table, Set.new(fields.map { |field| field['column'] }) ] }
|
||||||
|
.to_h
|
||||||
|
|
||||||
if !@column_whitelist.key?(procedure.id)
|
@column_whitelist[table] || []
|
||||||
@column_whitelist[procedure.id] = fields
|
|
||||||
.group_by { |field| field['table'] }
|
|
||||||
.map { |table, fields| [table, Set.new(fields.map { |field| field['column'] }) ] }
|
|
||||||
.to_h
|
|
||||||
end
|
|
||||||
|
|
||||||
@column_whitelist[procedure.id][table] || []
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_valid_order(order)
|
def assert_valid_order(order)
|
||||||
|
@ -225,7 +221,7 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
@dossier_field_service ||= DossierFieldService.new
|
@dossier_field_service ||= DossierFieldService.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_sort_column?(procedure, table, column)
|
def valid_sort_column?(table, column)
|
||||||
valid_column?(procedure, table, column) || EXTRA_SORT_COLUMNS[table]&.include?(column)
|
valid_column?(table, column) || EXTRA_SORT_COLUMNS[table]&.include?(column)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue