Commit 2379c8be authored by Robert Speicher's avatar Robert Speicher
Browse files

Inline Gitlab::Blacklist in NamespaceValidator

parent 175f482c
......@@ -2,21 +2,49 @@
#
# Custom validator for GitLab namespace values.
#
# Values are checked for formatting and exclusion from `Gitlab::Blacklist.path`.
# 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 blacklisted?(value)
if reserved?(value)
record.errors.add(attribute, "#{value} is a reserved name")
end
end
private
def blacklisted?(value)
Gitlab::Blacklist.path.include?(value)
def reserved?(value)
RESERVED.include?(value)
end
end
module Gitlab
module Blacklist
extend self
def path
%w(
admin
dashboard
files
groups
help
profile
projects
search
public
assets
u
s
teams
merge_requests
issues
users
snippets
services
repository
hooks
notes
unsubscribes
all
ci
)
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment