diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-04-05 16:41:00 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@gitlab.com> | 2017-05-01 12:14:24 +0300 |
commit | 74fcccaab30ac0f9e11ed9a076c008ade13a50d0 (patch) | |
tree | e3341f6aa020659655b2b6941fe8660befe315bf /app/validators/project_path_validator.rb | |
parent | 536f2bdfd17ac3bab38851de2973dd1c89dccc3f (diff) |
Streamline the path validation in groups & projects
`Project` uses `ProjectPathValidator` which is now a
`NamespaceValidator` that skips the format validation.
That way we're sure we are using the same collection of reserved
paths.
I updated the path constraints to reflect the changes: We now allow
some values that are only used on a top level namespace as a name for
a nested group/project.
Diffstat (limited to 'app/validators/project_path_validator.rb')
-rw-r--r-- | app/validators/project_path_validator.rb | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/app/validators/project_path_validator.rb b/app/validators/project_path_validator.rb index ee2ae65be7b..d41bdaeab84 100644 --- a/app/validators/project_path_validator.rb +++ b/app/validators/project_path_validator.rb @@ -4,25 +4,17 @@ # # Values are checked for formatting and exclusion from a list of reserved path # names. -class ProjectPathValidator < ActiveModel::EachValidator - # All project routes with wildcard argument must be listed here. - # Otherwise it can lead to routing issues when route considered as project name. - # - # Example: - # /group/project/tree/deploy_keys - # - # without tree as reserved name routing can match 'group/project' as group name, - # 'tree' as project name and 'deploy_keys' as route. - # - RESERVED = (NamespaceValidator::STRICT_RESERVED - - %w[dashboard help ci admin search notes services assets profile public]).freeze - +# +# This is basically the same as the `NamespaceValidator` but it skips the validation +# of the format with `Gitlab::Regex.namespace_regex`. The format of projects +# is validated in the class itself. +class ProjectPathValidator < NamespaceValidator def self.valid?(value) !reserved?(value) end - def self.reserved?(value) - RESERVED.include?(value) + def self.reserved?(value, type: :wildcard) + super(value, type: :wildcard) end delegate :reserved?, to: :class |