Commit bccf8d86 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Rename `NamespaceValidator` to `DynamicPathValidator`

This reflects better that it validates paths instead of a namespace model
parent 3143a5d2
...@@ -33,7 +33,7 @@ class Namespace < ActiveRecord::Base ...@@ -33,7 +33,7 @@ class Namespace < ActiveRecord::Base
validates :path, validates :path,
presence: true, presence: true,
length: { maximum: 255 }, length: { maximum: 255 },
namespace: true dynamic_path: true
validate :nesting_level_allowed validate :nesting_level_allowed
......
...@@ -196,7 +196,7 @@ class Project < ActiveRecord::Base ...@@ -196,7 +196,7 @@ class Project < ActiveRecord::Base
message: Gitlab::Regex.project_name_regex_message } message: Gitlab::Regex.project_name_regex_message }
validates :path, validates :path,
presence: true, presence: true,
namespace: true, dynamic_path: true,
length: { maximum: 255 }, length: { maximum: 255 },
format: { with: Gitlab::Regex.project_path_regex, format: { with: Gitlab::Regex.project_path_regex,
message: Gitlab::Regex.project_path_regex_message }, message: Gitlab::Regex.project_path_regex_message },
......
...@@ -118,7 +118,7 @@ class User < ActiveRecord::Base ...@@ -118,7 +118,7 @@ class User < ActiveRecord::Base
presence: true, presence: true,
numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Gitlab::Database::MAX_INT_VALUE } numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Gitlab::Database::MAX_INT_VALUE }
validates :username, validates :username,
namespace: true, dynamic_path: true,
presence: true, presence: true,
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
......
# 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 # Values are checked for formatting and exclusion from a list of reserved path
# names. # names.
class NamespaceValidator < ActiveModel::EachValidator class DynamicPathValidator < ActiveModel::EachValidator
# All routes that appear on the top level must be listed here. # All routes that appear on the top level must be listed here.
# This will make sure that groups cannot be created with these names # This will make sure that groups cannot be created with these names
# as these routes would be masked by the paths already in place. # as these routes would be masked by the paths already in place.
...@@ -124,6 +125,8 @@ class NamespaceValidator < ActiveModel::EachValidator ...@@ -124,6 +125,8 @@ class NamespaceValidator < ActiveModel::EachValidator
record.has_parent? ? :wildcard : :top_level record.has_parent? ? :wildcard : :top_level
when Project when Project
:wildcard :wildcard
when User
:top_level
else else
:strict :strict
end end
......
...@@ -2,7 +2,7 @@ class GroupUrlConstrainer ...@@ -2,7 +2,7 @@ class GroupUrlConstrainer
def matches?(request) def matches?(request)
id = request.params[:id] 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? Group.find_by_full_path(id).present?
end end
......
...@@ -4,7 +4,7 @@ class ProjectUrlConstrainer ...@@ -4,7 +4,7 @@ class ProjectUrlConstrainer
project_path = request.params[:project_id] || request.params[:id] project_path = request.params[:project_id] || request.params[:id]
full_path = namespace_path + '/' + project_path full_path = namespace_path + '/' + project_path
unless NamespaceValidator.valid_full_path?(full_path) unless DynamicPathValidator.valid_full_path?(full_path)
return false return false
end end
......
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ module Gitlab
# - Ending in `issues/id`/rendered_title` for the `issue_title` route # - Ending in `issues/id`/rendered_title` for the `issue_title` route
USED_IN_ROUTES = %w[noteable issue notes issues renderred_title USED_IN_ROUTES = %w[noteable issue notes issues renderred_title
commit pipelines merge_requests new].freeze 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) RESERVED_WORDS_REGEX = Regexp.union(*RESERVED_WORDS)
ROUTES = [ ROUTES = [
Gitlab::EtagCaching::Router::Route.new( Gitlab::EtagCaching::Router::Route.new(
......
require 'spec_helper' require 'spec_helper'
describe NamespaceValidator do describe DynamicPathValidator do
let(:validator) { described_class.new(attributes: [:path]) } let(:validator) { described_class.new(attributes: [:path]) }
# Pass in a full path to remove the format segment: # Pass in a full path to remove the format segment:
......
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