From f5f31ea9e6b908f3cc08a98db1dfa6211188ea1a Mon Sep 17 00:00:00 2001 From: Pia B Date: Tue, 9 Jun 2026 12:38:44 +0200 Subject: [PATCH] check for key in json instead of filename --- app/models/form/import.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/form/import.rb b/app/models/form/import.rb index 0b818669261..a7df46f47eb 100644 --- a/app/models/form/import.rb +++ b/app/models/form/import.rb @@ -59,7 +59,7 @@ class Form::Import end def guessed_type_json - :custom_filters if file_name_matches?('custom_filters') + :custom_filters if parse_json.keys.any?('custom_filters') end # Whether the uploaded CSV file seems to correspond to a different import type than the one selected @@ -195,7 +195,7 @@ class Form::Import def validate_json_data errors.add(:data, I18n.t('imports.errors.over_rows_processing_limit', count: ROWS_PROCESSING_LIMIT)) if json_data.count > ROWS_PROCESSING_LIMIT - errors.add(:data, I18n.t('imports.errors.incompatible_type')) unless allowed_json_key? + errors.add(:data, I18n.t('imports.errors.incompatible_type')) unless allowed_type_for_json? end def content_type_is_json? @@ -203,10 +203,14 @@ class Form::Import end def json_data - @json_data ||= JSON.parse(data.read)['custom_filters'].map(&:deep_symbolize_keys) + parse_json['custom_filters'].map(&:deep_symbolize_keys) end - def allowed_json_key? + def parse_json + @parse_json ||= JSON.parse(data.read) + end + + def allowed_type_for_json? type.to_sym.in?(%i(custom_filters)) end end