2015-12-07 16:17:12 -05:00
|
|
|
# NamespaceValidator
|
|
|
|
#
|
|
|
|
# Custom validator for GitLab namespace values.
|
|
|
|
#
|
2015-12-07 16:29:39 -05:00
|
|
|
# Values are checked for formatting and exclusion from a list of reserved path
|
|
|
|
# names.
|
2015-12-07 16:17:12 -05:00
|
|
|
class NamespaceValidator < ActiveModel::EachValidator
|
2016-09-29 04:36:38 -04:00
|
|
|
RESERVED = %w[
|
|
|
|
.well-known
|
2015-12-07 16:29:39 -05:00
|
|
|
admin
|
|
|
|
all
|
|
|
|
assets
|
|
|
|
ci
|
|
|
|
dashboard
|
|
|
|
files
|
|
|
|
groups
|
|
|
|
help
|
|
|
|
hooks
|
|
|
|
issues
|
|
|
|
merge_requests
|
2016-01-08 04:19:22 -05:00
|
|
|
new
|
2015-12-07 16:29:39 -05:00
|
|
|
notes
|
|
|
|
profile
|
|
|
|
projects
|
|
|
|
public
|
|
|
|
repository
|
2016-10-10 21:58:26 -04:00
|
|
|
robots.txt
|
2015-12-07 16:29:39 -05:00
|
|
|
s
|
|
|
|
search
|
|
|
|
services
|
|
|
|
snippets
|
|
|
|
teams
|
|
|
|
u
|
|
|
|
unsubscribes
|
|
|
|
users
|
2016-09-29 04:36:38 -04:00
|
|
|
].freeze
|
2015-12-07 16:29:39 -05:00
|
|
|
|
2015-12-07 16:17:12 -05:00
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
unless value =~ Gitlab::Regex.namespace_regex
|
|
|
|
record.errors.add(attribute, Gitlab::Regex.namespace_regex_message)
|
|
|
|
end
|
|
|
|
|
2015-12-07 16:29:39 -05:00
|
|
|
if reserved?(value)
|
2015-12-07 16:17:12 -05:00
|
|
|
record.errors.add(attribute, "#{value} is a reserved name")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-12-07 16:29:39 -05:00
|
|
|
def reserved?(value)
|
|
|
|
RESERVED.include?(value)
|
2015-12-07 16:17:12 -05:00
|
|
|
end
|
|
|
|
end
|