2015-12-23 02:04:40 +05:30
|
|
|
# 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
|
2016-11-03 12:29:30 +05:30
|
|
|
RESERVED = %w[
|
|
|
|
.well-known
|
2015-12-23 02:04:40 +05:30
|
|
|
admin
|
|
|
|
all
|
|
|
|
assets
|
|
|
|
ci
|
|
|
|
dashboard
|
|
|
|
files
|
|
|
|
groups
|
|
|
|
help
|
|
|
|
hooks
|
|
|
|
issues
|
|
|
|
merge_requests
|
2016-01-14 18:37:52 +05:30
|
|
|
new
|
2015-12-23 02:04:40 +05:30
|
|
|
notes
|
|
|
|
profile
|
|
|
|
projects
|
|
|
|
public
|
|
|
|
repository
|
2016-11-03 12:29:30 +05:30
|
|
|
robots.txt
|
2015-12-23 02:04:40 +05:30
|
|
|
s
|
|
|
|
search
|
|
|
|
services
|
|
|
|
snippets
|
|
|
|
teams
|
|
|
|
u
|
|
|
|
unsubscribes
|
|
|
|
users
|
2016-11-03 12:29:30 +05:30
|
|
|
].freeze
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
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
|