Commit 937feb28 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '299882-namespace-monitor-specific-code--validators' into 'master'

Move ZoomUrlValidator into Shared namespace

See merge request gitlab-org/gitlab!54205
parents c4745fdd ecb808b4
......@@ -1977,7 +1977,6 @@ Gitlab/NamespacedClass:
- 'app/validators/untrusted_regexp_validator.rb'
- 'app/validators/nested_attributes_duplicates_validator.rb'
- 'app/validators/x509_certificate_credentials_validator.rb'
- 'app/validators/zoom_url_validator.rb'
- 'app/workers/admin_email_worker.rb'
- 'app/workers/approve_blocked_pending_approval_users_worker.rb'
- 'app/workers/archive_trace_worker.rb'
......
......@@ -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 }, zoom_url: true
validates :url, presence: true, length: { maximum: 255 }, 'gitlab/utils/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
# ZoomUrlValidator
#
# Custom validator for zoom urls
#
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
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe ZoomUrlValidator do
RSpec.describe Gitlab::Utils::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