2019-10-21 17:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# ZoomUrlValidator
|
|
|
|
#
|
|
|
|
# Custom validator for zoom urls
|
|
|
|
#
|
|
|
|
class ZoomUrlValidator < ActiveModel::EachValidator
|
2020-12-07 16:10:08 -05:00
|
|
|
ALLOWED_SCHEMES = %w(https).freeze
|
|
|
|
|
2019-10-21 17:06:14 -04:00
|
|
|
def validate_each(record, attribute, value)
|
2020-12-07 16:10:08 -05:00
|
|
|
links_count = Gitlab::ZoomLinkExtractor.new(value).links.size
|
|
|
|
valid = Gitlab::UrlSanitizer.valid?(value, allowed_schemes: ALLOWED_SCHEMES)
|
|
|
|
|
|
|
|
return if links_count == 1 && valid
|
2019-10-21 17:06:14 -04:00
|
|
|
|
|
|
|
record.errors.add(:url, 'must contain one valid Zoom URL')
|
|
|
|
end
|
|
|
|
end
|