summaryrefslogtreecommitdiff
path: root/app/validators/gitlab/utils/zoom_url_validator.rb
blob: 57e30dcefa6f89fd79d0de7f4eac92e2a6eff751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

# Gitlab::Utils::ZoomUrlValidator
#
# Custom validator for zoom urls
#
module Gitlab
  module Utils
    class ZoomUrlValidator < ActiveModel::EachValidator
      ALLOWED_SCHEMES = %w(https).freeze

      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
    end
  end
end