Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 17:30:29 +01:00
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"
|
too_short: "%{label} must be at least %{min} characters"
|
||||||
required: "%{label} is required."
|
required: "%{label} is required."
|
||||||
not_url: "%{label} must be a valid url"
|
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."
|
none: "We couldn't find a wizard at that address."
|
||||||
no_skip: "Wizard can't be skipped"
|
no_skip: "Wizard can't be skipped"
|
||||||
export:
|
export:
|
||||||
error:
|
error:
|
||||||
select_one: "Please select atleast one wizard"
|
select_one: "Please select atleast one wizard"
|
||||||
|
|
||||||
import:
|
import:
|
||||||
error:
|
error:
|
||||||
no_file: "No file selected"
|
no_file: "No file selected"
|
||||||
|
|
|
@ -287,6 +287,7 @@ class CustomWizard::Builder
|
||||||
required = field['required']
|
required = field['required']
|
||||||
id = field['id'].to_s
|
id = field['id'].to_s
|
||||||
min_length = field['min_length'] if is_text_type(field)
|
min_length = field['min_length'] if is_text_type(field)
|
||||||
|
file_types = field['file_types']
|
||||||
|
|
||||||
if required && !value
|
if required && !value
|
||||||
updater.errors.add(id, I18n.t('wizard.field.required', label: label))
|
updater.errors.add(id, I18n.t('wizard.field.required', label: label))
|
||||||
|
@ -304,6 +305,10 @@ class CustomWizard::Builder
|
||||||
updater.fields[id] = standardise_boolean(value)
|
updater.fields[id] = standardise_boolean(value)
|
||||||
end
|
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|
|
CustomWizard::Builder.field_validators.each do |validator|
|
||||||
if type === validator[:type]
|
if type === validator[:type]
|
||||||
validator[:block].call(field, updater, step_template)
|
validator[:block].call(field, updater, step_template)
|
||||||
|
@ -311,6 +316,12 @@ class CustomWizard::Builder
|
||||||
end
|
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)
|
def is_text_type(field)
|
||||||
['text', 'textarea'].include? field['type']
|
['text', 'textarea'].include? field['type']
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,8 +13,6 @@ class CustomWizard::StepUpdater
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
byebug
|
|
||||||
|
|
||||||
if SiteSetting.custom_wizard_enabled &&
|
if SiteSetting.custom_wizard_enabled &&
|
||||||
@step.present? &&
|
@step.present? &&
|
||||||
@step.updater.present? &&
|
@step.updater.present? &&
|
||||||
|
|
Laden …
In neuem Issue referenzieren