Commit 4e3b102b authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'dz-redirect-deprecated-snippet-routes' into 'master'

Redirect deprecated snippets routes

See merge request gitlab-org/gitlab!54461
parents 4ca65e16 19cbec3e
...@@ -279,9 +279,13 @@ Rails.application.routes.draw do ...@@ -279,9 +279,13 @@ Rails.application.routes.draw do
# Issue https://gitlab.com/gitlab-org/gitlab/-/issues/210024 # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/210024
scope as: 'deprecated' do scope as: 'deprecated' do
draw :snippets # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/223719
get '/snippets/:id/raw',
to: 'snippets#raw',
format: false,
constraints: { id: /\d+/ }
Gitlab::Routing.redirect_legacy_paths(self, :profile) Gitlab::Routing.redirect_legacy_paths(self, :profile, :snippets)
end end
Gitlab.ee do Gitlab.ee do
......
...@@ -567,13 +567,13 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -567,13 +567,13 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
# Issue https://gitlab.com/gitlab-org/gitlab/issues/118849 # Issue https://gitlab.com/gitlab-org/gitlab/issues/118849
draw :repository draw :repository
# Issue https://gitlab.com/gitlab-org/gitlab/-/issues/29572 # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/223719
resources :snippets, concerns: :awardable, constraints: { id: /\d+/ } do # rubocop: disable Cop/PutProjectRoutesUnderScope # rubocop: disable Cop/PutProjectRoutesUnderScope
member do get '/snippets/:id/raw',
get :raw # rubocop:todo Cop/PutProjectRoutesUnderScope to: 'snippets#raw',
post :mark_as_spam # rubocop:todo Cop/PutProjectRoutesUnderScope format: false,
end constraints: { id: /\d+/ }
end # rubocop: enable Cop/PutProjectRoutesUnderScope
end end
# All new routes should go under /-/ scope. # All new routes should go under /-/ scope.
...@@ -589,7 +589,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -589,7 +589,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
:tracing, :tracing,
:serverless, :clusters, :audit_events, :wikis, :merge_requests, :serverless, :clusters, :audit_events, :wikis, :merge_requests,
:vulnerability_feedback, :security, :dependencies, :issues, :vulnerability_feedback, :security, :dependencies, :issues,
:pipelines, :pipeline_schedules) :pipelines, :pipeline_schedules, :snippets)
end end
# rubocop: disable Cop/PutProjectRoutesUnderScope # rubocop: disable Cop/PutProjectRoutesUnderScope
......
...@@ -113,7 +113,7 @@ RSpec.describe Gitlab::PathRegex do ...@@ -113,7 +113,7 @@ RSpec.describe Gitlab::PathRegex do
let(:deprecated_routes) do let(:deprecated_routes) do
# profile was deprecated in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51646 # profile was deprecated in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51646
%w(profile) %w(profile s)
end end
let(:ee_top_level_words) do let(:ee_top_level_words) do
......
...@@ -320,9 +320,11 @@ RSpec.describe 'project routing' do ...@@ -320,9 +320,11 @@ RSpec.describe 'project routing' do
expect(get('/gitlab/gitlabhq/-/snippets/1')).to route_to('projects/snippets#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') expect(get('/gitlab/gitlabhq/-/snippets/1')).to route_to('projects/snippets#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1')
end end
it 'to #show from unscope routing' do it 'to #raw from unscope routing' do
expect(get('/gitlab/gitlabhq/snippets/1')).to route_to('projects/snippets#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') expect(get('/gitlab/gitlabhq/snippets/1/raw')).to route_to('projects/snippets#raw', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1')
end end
it_behaves_like 'redirecting a legacy path', '/gitlab/gitlabhq/snippets/1', '/gitlab/gitlabhq/-/snippets/1'
end end
# test_project_hook POST /:project_id/-/hooks/:id/test(.:format) hooks#test # test_project_hook POST /:project_id/-/hooks/:id/test(.:format) hooks#test
......
...@@ -96,9 +96,11 @@ RSpec.describe SnippetsController, "routing" do ...@@ -96,9 +96,11 @@ RSpec.describe SnippetsController, "routing" do
expect(get("/-/snippets/1")).to route_to('snippets#show', id: '1') expect(get("/-/snippets/1")).to route_to('snippets#show', id: '1')
end end
it 'to #show from unscoped routing' do it 'to #raw from unscoped routing' do
expect(get("/snippets/1")).to route_to('snippets#show', id: '1') expect(get("/snippets/1/raw")).to route_to('snippets#raw', id: '1')
end end
it_behaves_like 'redirecting a legacy path', '/snippets/1', '/-/snippets/1'
end end
# help GET /help(.:format) help#index # help GET /help(.:format) help#index
......
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