diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-12-07 16:17:12 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-12-07 16:57:26 -0500 |
commit | 9321d382bd5a0697e0e15a5065ec274e75541851 (patch) | |
tree | 98c24ffe03b2bbd5212935ec7680d1bb1f122ec1 /app/validators | |
parent | ad6a771dc680b52e4b46c73f20bc39340d08bf32 (diff) | |
download | gitlab-ce-9321d382bd5a0697e0e15a5065ec274e75541851.tar.gz |
Add custom NamespaceValidator
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/namespace_validator.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/validators/namespace_validator.rb b/app/validators/namespace_validator.rb new file mode 100644 index 00000000000..4ab1706abda --- /dev/null +++ b/app/validators/namespace_validator.rb @@ -0,0 +1,22 @@ +# NamespaceValidator +# +# Custom validator for GitLab namespace values. +# +# Values are checked for formatting and exclusion from `Gitlab::Blacklist.path`. +class NamespaceValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + unless value =~ Gitlab::Regex.namespace_regex + record.errors.add(attribute, Gitlab::Regex.namespace_regex_message) + end + + if blacklisted?(value) + record.errors.add(attribute, "#{value} is a reserved name") + end + end + + private + + def blacklisted?(value) + Gitlab::Blacklist.path.include?(value) + end +end |