Commit 9c8d29cc authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'brodock/rename-utils-validator' into 'master'

Refactor ZoomValidator to use `gitlab/zoom_url` namespace

See merge request gitlab-org/gitlab!69650
parents 614eee06 bd88c34c
......@@ -10,7 +10,7 @@ class ZoomMeeting < ApplicationRecord
validates :project, presence: true, unless: :importing?
validates :issue, presence: true, unless: :importing?
validates :url, presence: true, length: { maximum: 255 }, 'gitlab/utils/zoom_url': true
validates :url, presence: true, length: { maximum: 255 }, 'gitlab/zoom_url': true
validates :issue, same_project_association: true, unless: :importing?
enum issue_status: {
......
# 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
# frozen_string_literal: true
module Gitlab
# Gitlab::Utils::ZoomUrlValidator
#
# Custom validator for zoom urls
#
# @example usage
# validates :url, 'gitlab/zoom_url': true
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
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Gitlab::Utils::ZoomUrlValidator do
RSpec.describe Gitlab::ZoomUrlValidator do
let(:zoom_meeting) { build(:zoom_meeting) }
describe 'validations' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment