Class: Gitlab::ZoomUrlValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/gitlab/zoom_url_validator.rb

Overview

Gitlab::Utils::ZoomUrlValidator

Custom validator for zoom urls

Examples:

usage

validates :url, 'gitlab/zoom_url': true

Constant Summary collapse

ALLOWED_SCHEMES =
%w[https].freeze

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



13
14
15
16
17
18
19
20
# File 'app/validators/gitlab/zoom_url_validator.rb', line 13

def validate_each(record, attribute, value)
  links_count = Gitlab::ZoomLinkExtractor.new(value).links.size
  valid = Gitlab::UrlSanitizer.valid?(value, allowed_schemes: ALLOWED_SCHEMES)

  return if links_count == 1 && valid

  record.errors.add(:url, 'must contain one valid Zoom URL')
end