diff --git a/changelogs/unreleased/dz-scope-some-global-routes.yml b/changelogs/unreleased/dz-scope-some-global-routes.yml new file mode 100644 index 0000000000000000000000000000000000000000..c908c31622799bd6a486ec906f3eb75cedf9eced --- /dev/null +++ b/changelogs/unreleased/dz-scope-some-global-routes.yml @@ -0,0 +1,5 @@ +--- +title: Move some global routes to - scope +merge_request: 27106 +author: +type: changed diff --git a/config/routes.rb b/config/routes.rb index 466555eeee81c2c601b9c04fe5b498abf63ca4e9..a8b2a9b66561b378091ed563ec1ea74ef74e9a9c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,6 +71,8 @@ # Health check get 'health_check(/:checks)' => 'health_check#index', as: :health_check + # Begin of the /-/ scope. + # Use this scope for all new global routes. scope path: '-' do # '/-/health' implemented by BasicHealthCheck middleware get 'liveness' => 'health#liveness' @@ -122,6 +124,10 @@ draw :country_state draw :subscription draw :analytics + + scope '/push_from_secondary/:geo_node_id' do + draw :git_http + end end if ENV['GITLAB_CHAOS_SECRET'] || Rails.env.development? || Rails.env.test? @@ -136,7 +142,24 @@ # Notification settings resources :notification_settings, only: [:create, :update] + + resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do + member do + post :accept + match :decline, via: [:get, :post] + end + end + + resources :sent_notifications, only: [], constraints: { id: /\h{32}/ } do + member do + get :unsubscribe + end + end + + # Spam reports + resources :abuse_reports, only: [:new, :create] end + # End of the /-/ scope. concern :clusterable do resources :clusters, only: [:index, :new, :show, :update, :destroy] do @@ -167,22 +190,24 @@ end end - # Invites - resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do - member do - post :accept - match :decline, via: [:get, :post] + # Deprecated routes. + # Will be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/210024 + scope as: :deprecated do + resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do + member do + post :accept + match :decline, via: [:get, :post] + end end - end - resources :sent_notifications, only: [], constraints: { id: /\h{32}/ } do - member do - get :unsubscribe + resources :sent_notifications, only: [], constraints: { id: /\h{32}/ } do + member do + get :unsubscribe + end end - end - # Spam reports - resources :abuse_reports, only: [:new, :create] + resources :abuse_reports, only: [:new, :create] + end resources :groups, only: [:index, :new, :create] do post :preview_markdown @@ -192,12 +217,6 @@ get '/projects/:id' => 'projects#resolve' - Gitlab.ee do - scope '/-/push_from_secondary/:geo_node_id' do - draw :git_http - end - end - draw :git_http draw :api draw :sidekiq diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index ff002469e3c46186fc1f8aac19df026147cb3866..61599f0876f609bd0b2dd6f2b4729f6b96580d18 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -313,3 +313,34 @@ expect(get('/health_check/email')).to route_to('health_check#index', checks: 'email') end end + +describe InvitesController, 'routing' do + let_it_be(:member) { create(:project_member, :invited) } + + it 'to #show' do + expect(get("/-/invites/#{member.invite_token}")).to route_to('invites#show', id: member.invite_token) + end + + it 'to legacy route' do + expect(get("/invites/#{member.invite_token}")).to route_to('invites#show', id: member.invite_token) + end +end + +describe AbuseReportsController, 'routing' do + let_it_be(:user) { create(:user) } + + it 'to #new' do + expect(get("/-/abuse_reports/new?user_id=#{user.id}")).to route_to('abuse_reports#new', user_id: user.id.to_s) + end + + it 'to legacy route' do + expect(get("/abuse_reports/new?user_id=#{user.id}")).to route_to('abuse_reports#new', user_id: user.id.to_s) + end +end + +describe SentNotificationsController, 'routing' do + it 'to #unsubscribe' do + expect(get("/-/sent_notifications/4bee17d4a63ed60cf5db53417e9aeb4c/unsubscribe")) + .to route_to('sent_notifications#unsubscribe', id: '4bee17d4a63ed60cf5db53417e9aeb4c') + end +end