diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-12-08 12:50:25 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-12-08 12:50:25 +0100 |
commit | 3c80a543153f8f686ec99d2d04b181b2d2c8a665 (patch) | |
tree | 679ca3921b00bd9e0904b4ad1be4e01d0a753ee9 /app/validators/namespace_validator.rb | |
parent | 1a942111653e9376d6275c5bd31f23cb27f58ab5 (diff) | |
parent | f5430e48b42227f1c1874ca27c6907f0f704be28 (diff) | |
download | gitlab-ce-ui/misc.tar.gz |
Merge branch 'master' into ui/miscui/misc
Diffstat (limited to 'app/validators/namespace_validator.rb')
-rw-r--r-- | app/validators/namespace_validator.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/validators/namespace_validator.rb b/app/validators/namespace_validator.rb new file mode 100644 index 00000000000..10e35ce665a --- /dev/null +++ b/app/validators/namespace_validator.rb @@ -0,0 +1,50 @@ +# NamespaceValidator +# +# Custom validator for GitLab namespace values. +# +# Values are checked for formatting and exclusion from a list of reserved path +# names. +class NamespaceValidator < ActiveModel::EachValidator + RESERVED = %w( + admin + all + assets + ci + dashboard + files + groups + help + hooks + issues + merge_requests + notes + profile + projects + public + repository + s + search + services + snippets + teams + u + unsubscribes + users + ).freeze + + def validate_each(record, attribute, value) + unless value =~ Gitlab::Regex.namespace_regex + record.errors.add(attribute, Gitlab::Regex.namespace_regex_message) + end + + if reserved?(value) + record.errors.add(attribute, "#{value} is a reserved name") + end + end + + private + + def reserved?(value) + RESERVED.include?(value) + end +end |