Fix file type validation
Dieser Commit ist enthalten in:
Ursprung
303c79be1f
Commit
d74831aa06
3 geänderte Dateien mit 14 neuen und 2 gelöschten Zeilen
|
@ -10,11 +10,14 @@ en:
|
|||
too_short: "%{label} must be at least %{min} characters"
|
||||
required: "%{label} is required."
|
||||
not_url: "%{label} must be a valid url"
|
||||
invalid_file: "%{label} must be a %{types}"
|
||||
|
||||
none: "We couldn't find a wizard at that address."
|
||||
no_skip: "Wizard can't be skipped"
|
||||
export:
|
||||
error:
|
||||
select_one: "Please select atleast one wizard"
|
||||
|
||||
import:
|
||||
error:
|
||||
no_file: "No file selected"
|
||||
|
|
|
@ -287,6 +287,7 @@ class CustomWizard::Builder
|
|||
required = field['required']
|
||||
id = field['id'].to_s
|
||||
min_length = field['min_length'] if is_text_type(field)
|
||||
file_types = field['file_types']
|
||||
|
||||
if required && !value
|
||||
updater.errors.add(id, I18n.t('wizard.field.required', label: label))
|
||||
|
@ -304,6 +305,10 @@ class CustomWizard::Builder
|
|||
updater.fields[id] = standardise_boolean(value)
|
||||
end
|
||||
|
||||
if type === 'upload' && !validate_file_type(value, file_types)
|
||||
updater.errors.add(id, I18n.t('wizard.field.invalid_file', label: label, types: file_types))
|
||||
end
|
||||
|
||||
CustomWizard::Builder.field_validators.each do |validator|
|
||||
if type === validator[:type]
|
||||
validator[:block].call(field, updater, step_template)
|
||||
|
@ -311,6 +316,12 @@ class CustomWizard::Builder
|
|||
end
|
||||
end
|
||||
|
||||
def validate_file_type(value, file_types)
|
||||
file_types.split(',')
|
||||
.map { |t| t.gsub('.', '') }
|
||||
.include?(File.extname(value['original_filename'])[1..-1])
|
||||
end
|
||||
|
||||
def is_text_type(field)
|
||||
['text', 'textarea'].include? field['type']
|
||||
end
|
||||
|
|
|
@ -13,8 +13,6 @@ class CustomWizard::StepUpdater
|
|||
end
|
||||
|
||||
def update
|
||||
byebug
|
||||
|
||||
if SiteSetting.custom_wizard_enabled &&
|
||||
@step.present? &&
|
||||
@step.updater.present? &&
|
||||
|
|
Laden …
In neuem Issue referenzieren