0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

Fix file type validation

Dieser Commit ist enthalten in:
Angus McLeod 2020-04-14 16:45:25 +10:00
Ursprung 303c79be1f
Commit d74831aa06
3 geänderte Dateien mit 14 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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"

Datei anzeigen

@ -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))
@ -303,6 +304,10 @@ class CustomWizard::Builder
if type === 'checkbox'
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]
@ -310,6 +315,12 @@ class CustomWizard::Builder
end
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']

Datei anzeigen

@ -13,8 +13,6 @@ class CustomWizard::StepUpdater
end
def update
byebug
if SiteSetting.custom_wizard_enabled &&
@step.present? &&
@step.updater.present? &&