BigW Consortium Gitlab

Commit bccf8d86 by 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
validates :path,
presence: true,
length: { maximum: 255 },
namespace: true
dynamic_path: true
validate :nesting_level_allowed
......
......@@ -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 },
......
......@@ -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 }
......
# 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
......
......@@ -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
......
......@@ -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
......
......@@ -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(
......
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:
......
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