summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-07 16:17:24 -0500
committerRobert Speicher <rspeicher@gmail.com>2015-12-07 16:57:26 -0500
commit175f482c3cd584ba73c66e65aa180c1107e72913 (patch)
treed6a3e746fc564c9c18a3b928b1360f7ab529f3db /app
parent9321d382bd5a0697e0e15a5065ec274e75541851 (diff)
downloadgitlab-ce-175f482c3cd584ba73c66e65aa180c1107e72913.tar.gz
Add custom NamespaceNameValidator
Diffstat (limited to 'app')
-rw-r--r--app/models/namespace.rb6
-rw-r--r--app/validators/namespace_name_validator.rb10
2 files changed, 13 insertions, 3 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index e07c676a9f3..1c4e101cc10 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -23,10 +23,10 @@ class Namespace < ActiveRecord::Base
validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
validates :name,
- presence: true, uniqueness: true,
length: { within: 0..255 },
- format: { with: Gitlab::Regex.namespace_name_regex,
- message: Gitlab::Regex.namespace_name_regex_message }
+ namespace_name: true,
+ presence: true,
+ uniqueness: true
validates :description, length: { within: 0..255 }
validates :path,
diff --git a/app/validators/namespace_name_validator.rb b/app/validators/namespace_name_validator.rb
new file mode 100644
index 00000000000..2e51af2982d
--- /dev/null
+++ b/app/validators/namespace_name_validator.rb
@@ -0,0 +1,10 @@
+# NamespaceNameValidator
+#
+# Custom validator for GitLab namespace name strings.
+class NamespaceNameValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ unless value =~ Gitlab::Regex.namespace_name_regex
+ record.errors.add(attribute, Gitlab::Regex.namespace_name_regex_message)
+ end
+ end
+end