From 12735eefcd7876435cd05f35a9f26bfe2836e09f Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Mon, 24 Apr 2017 12:38:09 +0200 Subject: Minor style adjustments --- app/validators/dynamic_path_validator.rb | 60 ++++++++++++++-------- lib/constraints/project_url_constrainer.rb | 4 +- .../rename_namespaces.rb | 7 +-- lib/gitlab/etag_caching/router.rb | 2 +- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/app/validators/dynamic_path_validator.rb b/app/validators/dynamic_path_validator.rb index ae2bd5984c5..5d2d3228baa 100644 --- a/app/validators/dynamic_path_validator.rb +++ b/app/validators/dynamic_path_validator.rb @@ -16,20 +16,33 @@ class DynamicPathValidator < ActiveModel::EachValidator # the path `api` shouldn't be allowed because it would be masked by `api/*` # TOP_LEVEL_ROUTES = Set.new(%w[ + - .well-known + abuse_reports admin all + api assets + autocomplete ci dashboard + explore files groups + health_check help hooks + import + invites issues + jwt + koding + member merge_requests new notes + notification_settings + oauth profile projects public @@ -37,29 +50,14 @@ class DynamicPathValidator < ActiveModel::EachValidator robots.txt s search + sent_notifications services snippets teams u unsubscribes - users - api - autocomplete - search - member - explore uploads - import - notification_settings - abuse_reports - invites - help - koding - health_check - jwt - oauth - sent_notifications - - + users ]).freeze # All project routes with wildcard argument must be listed here. @@ -71,10 +69,30 @@ class DynamicPathValidator < ActiveModel::EachValidator # without tree as reserved name routing can match 'group/project' as group name, # 'tree' as project name and 'deploy_keys' as route. # - WILDCARD_ROUTES = Set.new(%w[tree commits wikis new edit create update logs_tree - preview blob blame raw files create_dir find_file - artifacts graphs refs badges info/lfs/objects - gitlab-lfs/objects environments/folders]) + WILDCARD_ROUTES = Set.new(%w[ + artifacts + badges + 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 diff --git a/lib/constraints/project_url_constrainer.rb b/lib/constraints/project_url_constrainer.rb index 064e1bd78e3..d0ce2caffff 100644 --- a/lib/constraints/project_url_constrainer.rb +++ b/lib/constraints/project_url_constrainer.rb @@ -4,9 +4,7 @@ class ProjectUrlConstrainer project_path = request.params[:project_id] || request.params[:id] full_path = namespace_path + '/' + project_path - unless DynamicPathValidator.valid?(full_path) - return false - end + return false unless DynamicPathValidator.valid?(full_path) Project.find_by_full_path(full_path).present? end diff --git a/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb b/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb index 4937dfe2d31..4143e0edc62 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb @@ -11,13 +11,14 @@ module Gitlab end def namespaces_for_paths(type:) - namespaces = if type == :wildcard + namespaces = case type + when :wildcard MigrationClasses::Namespace.where.not(parent_id: nil) - elsif type == :top_level + when :top_level MigrationClasses::Namespace.where(parent_id: nil) end with_paths = MigrationClasses::Route.arel_table[:path]. - matches_any(path_patterns) + matches_any(path_patterns) namespaces.joins(:route).where(with_paths) end diff --git a/lib/gitlab/etag_caching/router.rb b/lib/gitlab/etag_caching/router.rb index c7da8b07a56..aac210f19e8 100644 --- a/lib/gitlab/etag_caching/router.rb +++ b/lib/gitlab/etag_caching/router.rb @@ -8,7 +8,7 @@ module Gitlab # regex itself) # - Ending in `noteable/issue//notes` for the `issue_notes` 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 RESERVED_WORDS = DynamicPathValidator::WILDCARD_ROUTES - USED_IN_ROUTES RESERVED_WORDS_REGEX = Regexp.union(*RESERVED_WORDS) -- cgit v1.2.1