From d119d3d1b25aac661e6251addf87b280bd37f0c5 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Thu, 11 Apr 2019 06:29:07 +0000 Subject: Align UrlValidator to validate_url gem implementation. Renamed UrlValidator to AddressableUrlValidator to avoid 'url:' naming collision with ActiveModel::Validations::UrlValidator in 'validates' statement. Make use of the options attribute of the parent class ActiveModel::EachValidator. Add more options: allow_nil, allow_blank, message. Renamed 'protocols' option to 'schemes' to match the option naming from UrlValidator. --- app/models/application_setting.rb | 8 ++++---- app/models/badge.rb | 2 +- app/models/ci/build_runner_session.rb | 2 +- app/models/environment.rb | 2 +- app/models/error_tracking/project_error_tracking_setting.rb | 2 +- app/models/generic_commit_status.rb | 2 +- app/models/project.rb | 2 +- app/models/releases/link.rb | 2 +- app/models/remote_mirror.rb | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) (limited to 'app/models') diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index d28a12413bf..21a97c8d773 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -48,17 +48,17 @@ class ApplicationSetting < ApplicationRecord validates :home_page_url, allow_blank: true, - url: true, + addressable_url: true, if: :home_page_url_column_exists? validates :help_page_support_url, allow_blank: true, - url: true, + addressable_url: true, if: :help_page_support_url_column_exists? validates :after_sign_out_path, allow_blank: true, - url: true + addressable_url: true validates :admin_notification_email, devise_email: true, @@ -218,7 +218,7 @@ class ApplicationSetting < ApplicationRecord if: :external_authorization_service_enabled validates :external_authorization_service_url, - url: true, allow_blank: true, + addressable_url: true, allow_blank: true, if: :external_authorization_service_enabled validates :external_authorization_service_timeout, diff --git a/app/models/badge.rb b/app/models/badge.rb index a244ed473de..50299cd6652 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -22,7 +22,7 @@ class Badge < ApplicationRecord scope :order_created_at_asc, -> { reorder(created_at: :asc) } - validates :link_url, :image_url, url: { protocols: %w(http https) } + validates :link_url, :image_url, addressable_url: true validates :type, presence: true def rendered_link_url(project = nil) diff --git a/app/models/ci/build_runner_session.rb b/app/models/ci/build_runner_session.rb index 80dbb150085..997bf298025 100644 --- a/app/models/ci/build_runner_session.rb +++ b/app/models/ci/build_runner_session.rb @@ -13,7 +13,7 @@ module Ci belongs_to :build, class_name: 'Ci::Build', inverse_of: :runner_session validates :build, presence: true - validates :url, url: { protocols: %w(https) } + validates :url, addressable_url: { schemes: %w(https) } def terminal_specification wss_url = Gitlab::UrlHelpers.as_wss(self.url) diff --git a/app/models/environment.rb b/app/models/environment.rb index fa29a83e517..69224635e34 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -35,7 +35,7 @@ class Environment < ApplicationRecord validates :external_url, length: { maximum: 255 }, allow_nil: true, - url: true + addressable_url: true delegate :stop_action, :manual_actions, to: :last_deployment, allow_nil: true diff --git a/app/models/error_tracking/project_error_tracking_setting.rb b/app/models/error_tracking/project_error_tracking_setting.rb index 70954bf8b05..72270ee8b4f 100644 --- a/app/models/error_tracking/project_error_tracking_setting.rb +++ b/app/models/error_tracking/project_error_tracking_setting.rb @@ -22,7 +22,7 @@ module ErrorTracking belongs_to :project - validates :api_url, length: { maximum: 255 }, public_url: true, url: { enforce_sanitization: true, ascii_only: true }, allow_nil: true + validates :api_url, length: { maximum: 255 }, public_url: { enforce_sanitization: true, ascii_only: true }, allow_nil: true validates :api_url, presence: { message: 'is a required field' }, if: :enabled diff --git a/app/models/generic_commit_status.rb b/app/models/generic_commit_status.rb index 3028bf21301..8a768b3a2c0 100644 --- a/app/models/generic_commit_status.rb +++ b/app/models/generic_commit_status.rb @@ -3,7 +3,7 @@ class GenericCommitStatus < CommitStatus before_validation :set_default_values - validates :target_url, url: true, + validates :target_url, addressable_url: true, length: { maximum: 255 }, allow_nil: true diff --git a/app/models/project.rb b/app/models/project.rb index 66fc83113ea..89ad90a964e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -327,7 +327,7 @@ class Project < ApplicationRecord validates :namespace, presence: true validates :name, uniqueness: { scope: :namespace_id } - validates :import_url, public_url: { protocols: ->(project) { project.persisted? ? VALID_MIRROR_PROTOCOLS : VALID_IMPORT_PROTOCOLS }, + validates :import_url, public_url: { schemes: ->(project) { project.persisted? ? VALID_MIRROR_PROTOCOLS : VALID_IMPORT_PROTOCOLS }, ports: ->(project) { project.persisted? ? VALID_MIRROR_PORTS : VALID_IMPORT_PORTS }, enforce_user: true }, if: [:external_import?, :import_url_changed?] validates :star_count, numericality: { greater_than_or_equal_to: 0 } diff --git a/app/models/releases/link.rb b/app/models/releases/link.rb index 36ec33d3e3e..58c2b98e524 100644 --- a/app/models/releases/link.rb +++ b/app/models/releases/link.rb @@ -6,7 +6,7 @@ module Releases belongs_to :release - validates :url, presence: true, url: { protocols: %w(http https ftp) }, uniqueness: { scope: :release } + validates :url, presence: true, addressable_url: { schemes: %w(http https ftp) }, uniqueness: { scope: :release } validates :name, presence: true, uniqueness: { scope: :release } scope :sorted, -> { order(created_at: :desc) } diff --git a/app/models/remote_mirror.rb b/app/models/remote_mirror.rb index 5610cfe0f24..b2fd5394a03 100644 --- a/app/models/remote_mirror.rb +++ b/app/models/remote_mirror.rb @@ -17,7 +17,7 @@ class RemoteMirror < ApplicationRecord belongs_to :project, inverse_of: :remote_mirrors - validates :url, presence: true, public_url: { protocols: %w(ssh git http https), allow_blank: true, enforce_user: true } + validates :url, presence: true, public_url: { schemes: %w(ssh git http https), allow_blank: true, enforce_user: true } before_save :set_new_remote_name, if: :mirror_url_changed? -- cgit v1.2.1