Commit aee6da52 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'dz-redirect-old-repo-routes' into 'master'

Redirect some deprecated repository routes

See merge request gitlab-org/gitlab!34867
parents 530a93a0 3e65aab3
---
title: Redirect some of deprecated repository routes
merge_request: 34867
author:
type: removed
...@@ -386,7 +386,6 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -386,7 +386,6 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
# The wiki and repository routing contains wildcard characters so # The wiki and repository routing contains wildcard characters so
# its preferable to keep it below all other project routes # its preferable to keep it below all other project routes
draw :repository_scoped draw :repository_scoped
draw :repository
draw :wiki draw :wiki
namespace :import do namespace :import do
...@@ -584,6 +583,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -584,6 +583,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
# Introduced in 12.0. # Introduced in 12.0.
# Should be removed with https://gitlab.com/gitlab-org/gitlab/issues/28848. # Should be removed with https://gitlab.com/gitlab-org/gitlab/issues/28848.
Gitlab::Routing.redirect_legacy_paths(self, :mirror, :tags, :hooks, Gitlab::Routing.redirect_legacy_paths(self, :mirror, :tags, :hooks,
:commits, :commit, :find_file, :files, :compare,
:cycle_analytics, :mattermost, :variables, :triggers, :cycle_analytics, :mattermost, :variables, :triggers,
:environments, :protected_environments, :error_tracking, :alert_management, :environments, :protected_environments, :error_tracking, :alert_management,
:tracing, :tracing,
......
# frozen_string_literal: true # frozen_string_literal: true
# All routing related to repository browsing # All routing related to repository browsing
#
# NOTE: Add new routes to repository_scoped.rb instead (see
# https://docs.gitlab.com/ee/development/routing.html#project-routes).
resource :repository, only: [:create] resource :repository, only: [:create]
resources :commit, only: [:show], constraints: { id: /\h{7,40}/ } do
member do
get :branches
get :pipelines
post :revert
post :cherry_pick
get :diff_for_path
get :diff_files
get :merge_requests
end
end
# NOTE: Add new routes to repository_scoped.rb instead (see
# https://docs.gitlab.com/ee/development/routing.html#project-routes).
#
# Don't use format parameter as file extension (old 3.0.x behavior) # Don't use format parameter as file extension (old 3.0.x behavior)
# See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments # See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments
scope format: false do scope format: false do
get '/compare/:from...:to', to: 'compare#show', as: 'compare', constraints: { from: /.+/, to: /.+/ } get '/refs/switch',
to: redirect('%{namespace_id}/%{project_id}/-/refs/switch')
resources :compare, only: [:index, :create] do get '/refs/:id/logs_tree',
collection do to: redirect('%{namespace_id}/%{project_id}/-/refs/%{id}/logs_tree'),
get :diff_for_path constraints: { id: Gitlab::PathRegex.git_reference_regex }
get :signatures
end
end
resources :refs, only: [] do
collection do
get 'switch'
end
member do get '/refs/:id/logs_tree/*path',
# tree viewer logs to: redirect('%{namespace_id}/%{project_id}/-/refs/%{id}/logs_tree/%{path}'),
get 'logs_tree', constraints: { id: Gitlab::PathRegex.git_reference_regex } constraints: { id: /.*/, path: /[^\0]*/ }
# Directories with leading dots erroneously get rejected if git
# ref regex used in constraints. Regex verification now done in controller.
get 'logs_tree/*path', action: :logs_tree, as: :logs_file, format: false, constraints: {
id: /.*/,
path: /[^\0]*/
}
end
end
scope constraints: { id: /[^\0]+/ } do scope constraints: { id: /[^\0]+/ } do
scope controller: :blob do # Deprecated. Keep for compatibility.
get '/new/*id', action: :new, as: :new_blob # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/118849
post '/create/*id', action: :create, as: :create_blob get '/tree/*id', to: 'tree#show', as: :deprecated_tree
get '/edit/*id', action: :edit, as: :edit_blob get '/blob/*id', to: 'blob#show', as: :deprecated_blob
put '/update/*id', action: :update, as: :update_blob get '/raw/*id', to: 'raw#show', as: :deprecated_raw
post '/preview/*id', action: :preview, as: :preview_blob get '/blame/*id', to: 'blame#show', as: :deprecated_blame
scope path: '/blob/*id', as: :blob do # Redirect those explicitly since `redirect_legacy_paths` conflicts with project new/edit actions
get :diff get '/new/*id', to: redirect('%{namespace_id}/%{project_id}/-/new/%{id}')
get '/', action: :show get '/edit/*id', to: redirect('%{namespace_id}/%{project_id}/-/edit/%{id}')
delete '/', action: :destroy
post '/', action: :create
put '/', action: :update
end
end
get '/tree/*id', to: 'tree#show', as: :tree
get '/raw/*id', to: 'raw#show', as: :raw
get '/blame/*id', to: 'blame#show', as: :blame
get '/commits', to: 'commits#commits_root', as: :commits_root
get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures
get '/commits/*id', to: 'commits#show', as: :commits
post '/create_dir/*id', to: 'tree#create_dir', as: :create_dir
scope controller: :find_file do
get '/find_file/*id', action: :show, as: :find_file
get '/files/*id', action: :list, as: :files
end
end end
end end
...@@ -6,6 +6,33 @@ ...@@ -6,6 +6,33 @@
# Don't use format parameter as file extension (old 3.0.x behavior) # Don't use format parameter as file extension (old 3.0.x behavior)
# See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments # See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments
scope format: false do scope format: false do
get '/compare/:from...:to', to: 'compare#show', as: 'compare', constraints: { from: /.+/, to: /.+/ }
resources :compare, only: [:index, :create] do
collection do
get :diff_for_path
get :signatures
end
end
resources :refs, only: [] do
collection do
get 'switch'
end
member do
# tree viewer logs
get 'logs_tree', constraints: { id: Gitlab::PathRegex.git_reference_regex }
# Directories with leading dots erroneously get rejected if git
# ref regex used in constraints. Regex verification now done in controller.
get 'logs_tree/*path', action: :logs_tree, as: :logs_file, format: false, constraints: {
id: /.*/,
path: /[^\0]*/
}
end
end
scope constraints: { id: Gitlab::PathRegex.git_reference_regex } do scope constraints: { id: Gitlab::PathRegex.git_reference_regex } do
resources :network, only: [:show] resources :network, only: [:show]
...@@ -38,4 +65,51 @@ scope format: false do ...@@ -38,4 +65,51 @@ scope format: false do
end end
end end
end end
scope constraints: { id: /[^\0]+/ } do
scope controller: :blob do
get '/new/*id', action: :new, as: :new_blob
post '/create/*id', action: :create, as: :create_blob
get '/edit/*id', action: :edit, as: :edit_blob
put '/update/*id', action: :update, as: :update_blob
post '/preview/*id', action: :preview, as: :preview_blob
scope path: '/blob/*id', as: :blob do
get :diff
get '/', action: :show
delete '/', action: :destroy
post '/', action: :create
put '/', action: :update
end
end
get '/tree/*id', to: 'tree#show', as: :tree
get '/raw/*id', to: 'raw#show', as: :raw
get '/blame/*id', to: 'blame#show', as: :blame
get '/commits', to: 'commits#commits_root', as: :commits_root
get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures
get '/commits/*id', to: 'commits#show', as: :commits
post '/create_dir/*id', to: 'tree#create_dir', as: :create_dir
scope controller: :find_file do
get '/find_file/*id', action: :show, as: :find_file
get '/files/*id', action: :list, as: :files
end
end
end
resources :commit, only: [:show], constraints: { id: /\h{7,40}/ } do
member do
get :branches
get :pipelines
post :revert
post :cherry_pick
get :diff_for_path
get :diff_files
get :merge_requests
end
end end
resource :repository, only: [:create]
...@@ -202,6 +202,16 @@ RSpec.describe 'project routing' do ...@@ -202,6 +202,16 @@ RSpec.describe 'project routing' do
namespace_id: 'gitlab', project_id: 'gitlabhq', namespace_id: 'gitlab', project_id: 'gitlabhq',
id: "stable", path: "new\n\nline.txt" }) id: "stable", path: "new\n\nline.txt" })
end end
it_behaves_like 'redirecting a legacy path', '/gitlab/gitlabhq/refs/switch', '/gitlab/gitlabhq/-/refs/switch'
it_behaves_like 'redirecting a legacy path',
'/gitlab/gitlabhq/refs/feature%2345/logs_tree',
'/gitlab/gitlabhq/-/refs/feature%2345/logs_tree'
it_behaves_like 'redirecting a legacy path',
'/gitlab/gitlabhq/refs/stable/logs_tree/new%0A%0Aline.txt',
'/gitlab/gitlabhq/-/refs/stable/logs_tree/new%0A%0Aline.txt'
end end
describe Projects::MergeRequestsController, 'routing' do describe Projects::MergeRequestsController, 'routing' do
...@@ -357,9 +367,7 @@ RSpec.describe 'project routing' do ...@@ -357,9 +367,7 @@ RSpec.describe 'project routing' do
expect(get('/gitlab/gitlabhq/-/commit/4246fbd13872934f72a8fd0d6fb1317b47b59cb5')).to route_to('projects/commit#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '4246fbd13872934f72a8fd0d6fb1317b47b59cb5') expect(get('/gitlab/gitlabhq/-/commit/4246fbd13872934f72a8fd0d6fb1317b47b59cb5')).to route_to('projects/commit#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '4246fbd13872934f72a8fd0d6fb1317b47b59cb5')
end end
it 'to #show unscoped routing' do it_behaves_like 'redirecting a legacy path', "/gitlab/gitlabhq/commit/4246fbd", "/gitlab/gitlabhq/-/commit/4246fbd"
expect(get('/gitlab/gitlabhq/commit/4246fbd')).to route_to('projects/commit#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '4246fbd')
end
end end
# patch_project_commit GET /:project_id/commits/:id/patch(.:format) commits#patch # patch_project_commit GET /:project_id/commits/:id/patch(.:format) commits#patch
...@@ -376,9 +384,7 @@ RSpec.describe 'project routing' do ...@@ -376,9 +384,7 @@ RSpec.describe 'project routing' do
expect(get('/gitlab/gitlabhq/-/commits/master.atom')).to route_to('projects/commits#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master.atom') expect(get('/gitlab/gitlabhq/-/commits/master.atom')).to route_to('projects/commits#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master.atom')
end end
it 'to #show unscoped routing' do it_behaves_like 'redirecting a legacy path', "/gitlab/gitlabhq/commits/master", "/gitlab/gitlabhq/-/commits/master"
expect(get('/gitlab/gitlabhq/commits/master.atom')).to route_to('projects/commits#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master.atom')
end
end end
# project_project_members GET /:project_id/project_members(.:format) project_members#index # project_project_members GET /:project_id/project_members(.:format) project_members#index
...@@ -517,6 +523,7 @@ RSpec.describe 'project routing' do ...@@ -517,6 +523,7 @@ RSpec.describe 'project routing' do
end end
it 'to #show from unscoped routing' do it 'to #show from unscoped routing' do
expect(get('/gitlab/gitlabhq/tree/master')).to route_to('projects/tree#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master')
expect(get('/gitlab/gitlabhq/tree/master/app/models/project.rb')).to route_to('projects/tree#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb') expect(get('/gitlab/gitlabhq/tree/master/app/models/project.rb')).to route_to('projects/tree#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
end end
end end
...@@ -545,6 +552,9 @@ RSpec.describe 'project routing' do ...@@ -545,6 +552,9 @@ RSpec.describe 'project routing' do
namespace_id: 'gitlab', project_id: 'gitlabhq', namespace_id: 'gitlab', project_id: 'gitlabhq',
id: "#{newline_file}" }) id: "#{newline_file}" })
end end
it_behaves_like 'redirecting a legacy path', "/gitlab/gitlabhq/find_file", "/gitlab/gitlabhq/-/find_file"
it_behaves_like 'redirecting a legacy path', "/gitlab/gitlabhq/files/master", "/gitlab/gitlabhq/-/files/master"
end end
describe Projects::BlobController, 'routing' do describe Projects::BlobController, 'routing' do
...@@ -575,6 +585,9 @@ RSpec.describe 'project routing' do ...@@ -575,6 +585,9 @@ RSpec.describe 'project routing' do
namespace_id: 'gitlab', project_id: 'gitlabhq', namespace_id: 'gitlab', project_id: 'gitlabhq',
id: "master/docs/#{newline_file}" }) id: "master/docs/#{newline_file}" })
end end
it_behaves_like 'redirecting a legacy path', "/gitlab/gitlabhq/new/master", "/gitlab/gitlabhq/-/new/master"
it_behaves_like 'redirecting a legacy path', "/gitlab/gitlabhq/edit/master/README", "/gitlab/gitlabhq/-/edit/master/README"
end end
# project_raw GET /:project_id/-/raw/:id(.:format) raw#show {id: /[^\0]+/, project_id: /[^\/]+/} # project_raw GET /:project_id/-/raw/:id(.:format) raw#show {id: /[^\0]+/, project_id: /[^\/]+/}
...@@ -610,6 +623,9 @@ RSpec.describe 'project routing' do ...@@ -610,6 +623,9 @@ RSpec.describe 'project routing' do
expect(get('/gitlab/gitlabhq/-/compare/master...stable')).to route_to('projects/compare#show', namespace_id: 'gitlab', project_id: 'gitlabhq', from: 'master', to: 'stable') expect(get('/gitlab/gitlabhq/-/compare/master...stable')).to route_to('projects/compare#show', namespace_id: 'gitlab', project_id: 'gitlabhq', from: 'master', to: 'stable')
expect(get('/gitlab/gitlabhq/-/compare/issue/1234...stable')).to route_to('projects/compare#show', namespace_id: 'gitlab', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable') expect(get('/gitlab/gitlabhq/-/compare/issue/1234...stable')).to route_to('projects/compare#show', namespace_id: 'gitlab', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable')
end end
it_behaves_like 'redirecting a legacy path', '/gitlab/gitlabhq/compare', '/gitlab/gitlabhq/-/compare'
it_behaves_like 'redirecting a legacy path', '/gitlab/gitlabhq/compare/master...stable', '/gitlab/gitlabhq/-/compare/master...stable'
end end
describe Projects::NetworkController, 'routing' do describe Projects::NetworkController, 'routing' do
......
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