diff options
-rw-r--r-- | app/models/namespace.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/validators/dynamic_path_validator.rb (renamed from app/validators/namespace_validator.rb) | 9 | ||||
-rw-r--r-- | lib/constraints/group_url_constrainer.rb | 2 | ||||
-rw-r--r-- | lib/constraints/project_url_constrainer.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/etag_caching/router.rb | 2 | ||||
-rw-r--r-- | spec/validators/dynamic_path_validator_spec.rb (renamed from spec/validators/namespace_validator_spec.rb) | 2 |
8 files changed, 13 insertions, 10 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 1570470d63f..397dc7a25ab 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -33,7 +33,7 @@ class Namespace < ActiveRecord::Base validates :path, presence: true, length: { maximum: 255 }, - namespace: true + dynamic_path: true validate :nesting_level_allowed diff --git a/app/models/project.rb b/app/models/project.rb index 0ed4b4fddd6..9ebb9638ca4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -196,7 +196,7 @@ class Project < ActiveRecord::Base message: Gitlab::Regex.project_name_regex_message } validates :path, presence: true, - namespace: true, + dynamic_path: true, length: { maximum: 255 }, format: { with: Gitlab::Regex.project_path_regex, message: Gitlab::Regex.project_path_regex_message }, diff --git a/app/models/user.rb b/app/models/user.rb index bd9c9f99663..2b7ebe6c1a7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -118,7 +118,7 @@ class User < ActiveRecord::Base presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Gitlab::Database::MAX_INT_VALUE } validates :username, - namespace: true, + dynamic_path: true, presence: true, uniqueness: { case_sensitive: false } diff --git a/app/validators/namespace_validator.rb b/app/validators/dynamic_path_validator.rb index ed71d5ad5b5..ce363c052d8 100644 --- a/app/validators/namespace_validator.rb +++ b/app/validators/dynamic_path_validator.rb @@ -1,10 +1,11 @@ -# NamespaceValidator +# DynamicPathValidator # -# Custom validator for GitLab namespace values. +# Custom validator for GitLab path values. +# These paths are assigned to `Namespace` (& `Group` as a subclass) & `Project` # # Values are checked for formatting and exclusion from a list of reserved path # names. -class NamespaceValidator < ActiveModel::EachValidator +class DynamicPathValidator < ActiveModel::EachValidator # All routes that appear on the top level must be listed here. # This will make sure that groups cannot be created with these names # as these routes would be masked by the paths already in place. @@ -124,6 +125,8 @@ class NamespaceValidator < ActiveModel::EachValidator record.has_parent? ? :wildcard : :top_level when Project :wildcard + when User + :top_level else :strict end diff --git a/lib/constraints/group_url_constrainer.rb b/lib/constraints/group_url_constrainer.rb index 559f510944a..48a33690cb2 100644 --- a/lib/constraints/group_url_constrainer.rb +++ b/lib/constraints/group_url_constrainer.rb @@ -2,7 +2,7 @@ class GroupUrlConstrainer def matches?(request) id = request.params[:id] - return false unless NamespaceValidator.valid_full_path?(id) + return false unless DynamicPathValidator.valid_full_path?(id) Group.find_by_full_path(id).present? end diff --git a/lib/constraints/project_url_constrainer.rb b/lib/constraints/project_url_constrainer.rb index f83fa1618a5..72c457d0369 100644 --- a/lib/constraints/project_url_constrainer.rb +++ b/lib/constraints/project_url_constrainer.rb @@ -4,7 +4,7 @@ class ProjectUrlConstrainer project_path = request.params[:project_id] || request.params[:id] full_path = namespace_path + '/' + project_path - unless NamespaceValidator.valid_full_path?(full_path) + unless DynamicPathValidator.valid_full_path?(full_path) return false end diff --git a/lib/gitlab/etag_caching/router.rb b/lib/gitlab/etag_caching/router.rb index 67aa237f2f1..c7da8b07a56 100644 --- a/lib/gitlab/etag_caching/router.rb +++ b/lib/gitlab/etag_caching/router.rb @@ -10,7 +10,7 @@ module Gitlab # - Ending in `issues/id`/rendered_title` for the `issue_title` route USED_IN_ROUTES = %w[noteable issue notes issues renderred_title commit pipelines merge_requests new].freeze - RESERVED_WORDS = NamespaceValidator::WILDCARD_ROUTES - USED_IN_ROUTES + RESERVED_WORDS = DynamicPathValidator::WILDCARD_ROUTES - USED_IN_ROUTES RESERVED_WORDS_REGEX = Regexp.union(*RESERVED_WORDS) ROUTES = [ Gitlab::EtagCaching::Router::Route.new( diff --git a/spec/validators/namespace_validator_spec.rb b/spec/validators/dynamic_path_validator_spec.rb index 589175a2ced..6c490b1be2e 100644 --- a/spec/validators/namespace_validator_spec.rb +++ b/spec/validators/dynamic_path_validator_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe NamespaceValidator do +describe DynamicPathValidator do let(:validator) { described_class.new(attributes: [:path]) } # Pass in a full path to remove the format segment: |