Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-22 00:06:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-22 00:06:14 +0300
commit170f0bdcdef9c9b226abfe0a50d6687c65e8d613 (patch)
tree5c82769a5380a0fd495bd1adb098c8c360334587 /app/validators
parentf1bb2a307e9b125a8ee0be3728cb0d1baa21a3d4 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/same_project_association_validator.rb21
-rw-r--r--app/validators/zoom_url_validator.rb13
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