fix(instructeur): don't crash when adding a filter too long
This commit is contained in:
parent
5a8859cd28
commit
5ab1d45b8a
3 changed files with 29 additions and 7 deletions
|
@ -148,7 +148,9 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def add_filter
|
||||
procedure_presentation.add_filter(statut, params[:field], params[:value])
|
||||
if !procedure_presentation.add_filter(statut, params[:field], params[:value])
|
||||
flash.alert = procedure_presentation.errors.full_messages
|
||||
end
|
||||
|
||||
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
||||
end
|
||||
|
|
|
@ -319,7 +319,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
'value' => value
|
||||
}
|
||||
|
||||
update!(filters: updated_filters)
|
||||
update(filters: updated_filters)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -457,11 +457,11 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def check_filters_max_length
|
||||
individual_filters = filters.values.flatten.filter { |f| f.is_a?(Hash) }
|
||||
individual_filters.each do |filter|
|
||||
if filter['value']&.length.to_i > FILTERS_VALUE_MAX_LENGTH
|
||||
errors.add(:filters, :too_long)
|
||||
end
|
||||
filters.values.flatten.each do |filter|
|
||||
next if !filter.is_a?(Hash)
|
||||
next if filter['value']&.length.to_i <= FILTERS_VALUE_MAX_LENGTH
|
||||
|
||||
errors.add(:base, "Le filtre #{filter['label']} est trop long (maximum: #{FILTERS_VALUE_MAX_LENGTH} caractères)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue