From 19cbec3ed6e18a4947385567030e285bff661fc8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 17 Feb 2021 16:41:19 +0200 Subject: [PATCH] Redirect deprecated snippets routes Redirect unscoped snippet routes like: * /group/project/snippets -> /group/project/-/snippets * /snippets/1 -> /-/snippets/1 Changelog: removed Signed-off-by: Dmitriy Zaporozhets --- config/routes.rb | 8 ++++++-- config/routes/project.rb | 16 ++++++++-------- spec/lib/gitlab/path_regex_spec.rb | 2 +- spec/routing/project_routing_spec.rb | 6 ++++-- spec/routing/routing_spec.rb | 6 ++++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 3b0370551b9a61..badff3199f49ae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -311,9 +311,13 @@ # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/210024 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 Gitlab.ee do diff --git a/config/routes/project.rb b/config/routes/project.rb index d62e2f1b2f2d39..f76f22fe3d32ef 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -568,13 +568,13 @@ # Issue https://gitlab.com/gitlab-org/gitlab/issues/118849 draw :repository - # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/29572 - resources :snippets, concerns: :awardable, constraints: { id: /\d+/ } do # rubocop: disable Cop/PutProjectRoutesUnderScope - member do - get :raw # rubocop:todo Cop/PutProjectRoutesUnderScope - post :mark_as_spam # rubocop:todo Cop/PutProjectRoutesUnderScope - end - end + # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/223719 + # rubocop: disable Cop/PutProjectRoutesUnderScope + get '/snippets/:id/raw', + to: 'snippets#raw', + format: false, + constraints: { id: /\d+/ } + # rubocop: enable Cop/PutProjectRoutesUnderScope end # All new routes should go under /-/ scope. @@ -589,7 +589,7 @@ :tracing, :serverless, :clusters, :audit_events, :wikis, :merge_requests, :vulnerability_feedback, :security, :dependencies, :issues, - :pipelines, :pipeline_schedules) + :pipelines, :pipeline_schedules, :snippets) end # rubocop: disable Cop/PutProjectRoutesUnderScope diff --git a/spec/lib/gitlab/path_regex_spec.rb b/spec/lib/gitlab/path_regex_spec.rb index cd89674af0f717..fbcb68550c1646 100644 --- a/spec/lib/gitlab/path_regex_spec.rb +++ b/spec/lib/gitlab/path_regex_spec.rb @@ -113,7 +113,7 @@ def failure_message(constant_name, migration_helper, missing_words: [], addition let(:deprecated_routes) do # profile was deprecated in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51646 - %w(profile) + %w(profile s) end let(:ee_top_level_words) do diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index 056f4d30ea5eee..2b742c10b811a0 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -310,9 +310,11 @@ expect(get('/gitlab/gitlabhq/-/snippets/1')).to route_to('projects/snippets#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') end - it 'to #show from unscope routing' do - expect(get('/gitlab/gitlabhq/snippets/1')).to route_to('projects/snippets#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') + it 'to #raw from unscope routing' do + expect(get('/gitlab/gitlabhq/snippets/1/raw')).to route_to('projects/snippets#raw', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') end + + it_behaves_like 'redirecting a legacy path', '/gitlab/gitlabhq/snippets/1', '/gitlab/gitlabhq/-/snippets/1' end # test_project_hook POST /:project_id/-/hooks/:id/test(.:format) hooks#test diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index 7b9ba7838851c3..3bb8e22a63b5ef 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -96,9 +96,11 @@ expect(get("/-/snippets/1")).to route_to('snippets#show', id: '1') end - it 'to #show from unscoped routing' do - expect(get("/snippets/1")).to route_to('snippets#show', id: '1') + it 'to #raw from unscoped routing' do + expect(get("/snippets/1/raw")).to route_to('snippets#raw', id: '1') end + + it_behaves_like 'redirecting a legacy path', '/snippets/1', '/-/snippets/1' end # help GET /help(.:format) help#index -- GitLab