2016-07-28 13:54:17 -04:00
|
|
|
class UploadUrlValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
if value.present?
|
|
|
|
uri = URI.parse(value) rescue nil
|
|
|
|
|
2016-08-09 14:14:49 -04:00
|
|
|
unless uri && Discourse.store.has_been_uploaded?(value)
|
2016-07-28 13:54:17 -04:00
|
|
|
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.invalid'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|