diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-21 21:06:14 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-21 21:06:14 +0000 |
commit | 170f0bdcdef9c9b226abfe0a50d6687c65e8d613 (patch) | |
tree | 5c82769a5380a0fd495bd1adb098c8c360334587 /app/validators | |
parent | f1bb2a307e9b125a8ee0be3728cb0d1baa21a3d4 (diff) | |
download | gitlab-ce-170f0bdcdef9c9b226abfe0a50d6687c65e8d613.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/same_project_association_validator.rb | 21 | ||||
-rw-r--r-- | app/validators/zoom_url_validator.rb | 13 |
2 files changed, 34 insertions, 0 deletions
diff --git a/app/validators/same_project_association_validator.rb b/app/validators/same_project_association_validator.rb new file mode 100644 index 00000000000..2af2a21fa9a --- /dev/null +++ b/app/validators/same_project_association_validator.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# SameProjectAssociationValidator +# +# Custom validator to validate that the same project associated with +# the record is also associated with the value +# +# Example: +# class ZoomMeeting < ApplicationRecord +# belongs_to :project, optional: false +# belongs_to :issue, optional: false + +# validates :issue, same_project_association: true +# end +class SameProjectAssociationValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + return if record.project == value&.project + + record.errors[attribute] << 'must associate the same project' + end +end diff --git a/app/validators/zoom_url_validator.rb b/app/validators/zoom_url_validator.rb new file mode 100644 index 00000000000..dc4ca6b9501 --- /dev/null +++ b/app/validators/zoom_url_validator.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# ZoomUrlValidator +# +# Custom validator for zoom urls +# +class ZoomUrlValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + return if Gitlab::ZoomLinkExtractor.new(value).links.size == 1 + + record.errors.add(:url, 'must contain one valid Zoom URL') + end +end |