diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-11-08 11:41:56 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-11-08 11:41:56 +0300 |
commit | de614b0e1af598d924753497f398f0379a0c1877 (patch) | |
tree | 954657e91c8fab101065dc433b4cb2330c57e4bd /lib | |
parent | cb606c5a79039706016c7537c8e72645b3668592 (diff) | |
parent | 9b0899cb809d826249bb3ad2eb35beec5bdf2190 (diff) |
Merge branch 'bvl-free-paths' into 'master'
Free some reserved group routes
See merge request gitlab-org/gitlab-ce!15052
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/path_regex.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/routing.rb | 19 |
2 files changed, 19 insertions, 16 deletions
diff --git a/lib/gitlab/path_regex.rb b/lib/gitlab/path_regex.rb index 22f8dd669d0..9a91f8bf96a 100644 --- a/lib/gitlab/path_regex.rb +++ b/lib/gitlab/path_regex.rb @@ -112,22 +112,6 @@ module Gitlab # this would map to the activity-page of its parent. GROUP_ROUTES = %w[ - - activity - analytics - audit_events - avatar - edit - group_members - hooks - issues - labels - ldap - ldap_group_links - merge_requests - milestones - notification_setting - pipeline_quota - projects ].freeze ILLEGAL_PROJECT_PATH_WORDS = PROJECT_WILDCARD_ROUTES diff --git a/lib/gitlab/routing.rb b/lib/gitlab/routing.rb index e57890f1143..910533076b0 100644 --- a/lib/gitlab/routing.rb +++ b/lib/gitlab/routing.rb @@ -40,5 +40,24 @@ module Gitlab def self.url_helpers @url_helpers ||= Gitlab::Application.routes.url_helpers end + + def self.redirect_legacy_paths(router, *paths) + build_redirect_path = lambda do |request, _params, path| + # Only replace the last occurence of `path`. + # + # `request.fullpath` includes the querystring + path = request.path.sub(%r{/#{path}/*(?!.*#{path})}, "/-/#{path}/") + path << "?#{request.query_string}" if request.query_string.present? + + path + end + + paths.each do |path| + router.match "/#{path}(/*rest)", + via: [:get, :post, :patch, :delete], + to: router.redirect { |params, request| build_redirect_path.call(request, params, path) }, + as: "legacy_#{path}_redirect" + end + end end end |