Commit 12735eef authored by Bob Van Landuyt's avatar Bob Van Landuyt

Minor style adjustments

parent ea8e86da
...@@ -16,20 +16,33 @@ class DynamicPathValidator < ActiveModel::EachValidator ...@@ -16,20 +16,33 @@ class DynamicPathValidator < ActiveModel::EachValidator
# the path `api` shouldn't be allowed because it would be masked by `api/*` # the path `api` shouldn't be allowed because it would be masked by `api/*`
# #
TOP_LEVEL_ROUTES = Set.new(%w[ TOP_LEVEL_ROUTES = Set.new(%w[
-
.well-known .well-known
abuse_reports
admin admin
all all
api
assets assets
autocomplete
ci ci
dashboard dashboard
explore
files files
groups groups
health_check
help help
hooks hooks
import
invites
issues issues
jwt
koding
member
merge_requests merge_requests
new new
notes notes
notification_settings
oauth
profile profile
projects projects
public public
...@@ -37,29 +50,14 @@ class DynamicPathValidator < ActiveModel::EachValidator ...@@ -37,29 +50,14 @@ class DynamicPathValidator < ActiveModel::EachValidator
robots.txt robots.txt
s s
search search
sent_notifications
services services
snippets snippets
teams teams
u u
unsubscribes unsubscribes
users
api
autocomplete
search
member
explore
uploads uploads
import users
notification_settings
abuse_reports
invites
help
koding
health_check
jwt
oauth
sent_notifications
-
]).freeze ]).freeze
# All project routes with wildcard argument must be listed here. # All project routes with wildcard argument must be listed here.
...@@ -71,10 +69,30 @@ class DynamicPathValidator < ActiveModel::EachValidator ...@@ -71,10 +69,30 @@ class DynamicPathValidator < ActiveModel::EachValidator
# without tree as reserved name routing can match 'group/project' as group name, # without tree as reserved name routing can match 'group/project' as group name,
# 'tree' as project name and 'deploy_keys' as route. # 'tree' as project name and 'deploy_keys' as route.
# #
WILDCARD_ROUTES = Set.new(%w[tree commits wikis new edit create update logs_tree WILDCARD_ROUTES = Set.new(%w[
preview blob blame raw files create_dir find_file artifacts
artifacts graphs refs badges info/lfs/objects badges
gitlab-lfs/objects environments/folders]) blame
blob
commits
create
create_dir
edit
environments/folders
files
find_file
gitlab-lfs/objects
graphs
info/lfs/objects
logs_tree
new
preview
raw
refs
tree
update
wikis
]).freeze
STRICT_RESERVED = (TOP_LEVEL_ROUTES | WILDCARD_ROUTES).freeze STRICT_RESERVED = (TOP_LEVEL_ROUTES | WILDCARD_ROUTES).freeze
......
...@@ -4,9 +4,7 @@ class ProjectUrlConstrainer ...@@ -4,9 +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 DynamicPathValidator.valid?(full_path) return false unless DynamicPathValidator.valid?(full_path)
return false
end
Project.find_by_full_path(full_path).present? Project.find_by_full_path(full_path).present?
end end
......
...@@ -11,13 +11,14 @@ module Gitlab ...@@ -11,13 +11,14 @@ module Gitlab
end end
def namespaces_for_paths(type:) def namespaces_for_paths(type:)
namespaces = if type == :wildcard namespaces = case type
when :wildcard
MigrationClasses::Namespace.where.not(parent_id: nil) MigrationClasses::Namespace.where.not(parent_id: nil)
elsif type == :top_level when :top_level
MigrationClasses::Namespace.where(parent_id: nil) MigrationClasses::Namespace.where(parent_id: nil)
end end
with_paths = MigrationClasses::Route.arel_table[:path]. with_paths = MigrationClasses::Route.arel_table[:path].
matches_any(path_patterns) matches_any(path_patterns)
namespaces.joins(:route).where(with_paths) namespaces.joins(:route).where(with_paths)
end end
......
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
# regex itself) # regex itself)
# - Ending in `noteable/issue/<id>/notes` for the `issue_notes` route # - Ending in `noteable/issue/<id>/notes` for the `issue_notes` route
# - 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 rendered_title
commit pipelines merge_requests new].freeze commit pipelines merge_requests new].freeze
RESERVED_WORDS = DynamicPathValidator::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)
......
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