summaryrefslogtreecommitdiff
path: root/config/routes.rb
blob: 38030a24cb5e1830101c7f1899d5d768eafeb01d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# frozen_string_literal: true

require 'sidekiq/web'
require 'sidekiq/cron/web'
require 'product_analytics/collector_app'

Rails.application.routes.draw do
  concern :access_requestable do
    post :request_access, on: :collection
    post :approve_access_request, on: :member
  end

  concern :awardable do
    post :toggle_award_emoji, on: :member
  end

  favicon_redirect = redirect do |_params, _request|
    ActionController::Base.helpers.asset_url(Gitlab::Favicon.main)
  end
  get 'favicon.png', to: favicon_redirect
  get 'favicon.ico', to: favicon_redirect

  draw :sherlock
  draw :development

  use_doorkeeper do
    controllers applications: 'oauth/applications',
                authorized_applications: 'oauth/authorized_applications',
                authorizations: 'oauth/authorizations',
                token_info: 'oauth/token_info',
                tokens: 'oauth/tokens'
  end

  # This prefixless path is required because Jira gets confused if we set it up with a path
  # More information: https://gitlab.com/gitlab-org/gitlab/issues/6752
  scope path: '/login/oauth', controller: 'oauth/jira/authorizations', as: :oauth_jira do
    get :authorize, action: :new
    get :callback
    post :access_token

    match '*all', via: [:get, :post], to: proc { [404, {}, ['']] }
  end

  draw :oauth

  use_doorkeeper_openid_connect

  # Sign up
  scope path: '/users/sign_up', module: :registrations, as: :users_sign_up do
    resource :welcome, only: [:show, :update], controller: 'welcome' do
      Gitlab.ee do
        get :trial_getting_started, on: :collection
        get :trial_onboarding_board, on: :collection
      end
    end

    resource :experience_level, only: [:show, :update]

    Gitlab.ee do
      resources :groups, only: [:new, :create]
      resources :group_invites, only: [:new, :create]
      resources :projects, only: [:new, :create]
    end
  end

  # Search
  get 'search' => 'search#show', as: :search
  get 'search/autocomplete' => 'search#autocomplete', as: :search_autocomplete
  get 'search/count' => 'search#count', as: :search_count
  get 'search/opensearch' => 'search#opensearch', as: :search_opensearch

  # JSON Web Token
  get 'jwt/auth' => 'jwt#auth'

  # 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
    # Autocomplete
    get '/autocomplete/users' => 'autocomplete#users'
    get '/autocomplete/users/:id' => 'autocomplete#user'
    get '/autocomplete/projects' => 'autocomplete#projects'
    get '/autocomplete/award_emojis' => 'autocomplete#award_emojis'
    get '/autocomplete/merge_request_target_branches' => 'autocomplete#merge_request_target_branches'
    get '/autocomplete/deploy_keys_with_owners' => 'autocomplete#deploy_keys_with_owners'

    Gitlab.ee do
      get '/autocomplete/project_groups' => 'autocomplete#project_groups'
      get '/autocomplete/project_routes' => 'autocomplete#project_routes'
      get '/autocomplete/namespace_routes' => 'autocomplete#namespace_routes'
    end

    get '/whats_new' => 'whats_new#index'

    # '/-/health' implemented by BasicHealthCheck middleware
    get 'liveness' => 'health#liveness'
    get 'readiness' => 'health#readiness'
    controller :metrics do
      get 'metrics', action: :index
      get 'metrics/system', action: :system
    end
    mount Peek::Railtie => '/peek', as: 'peek_routes'

    get 'runner_setup/platforms' => 'runner_setup#platforms'

    # Boards resources shared between group and projects
    resources :boards, only: [] do
      resources :lists, module: :boards, only: [:index, :create, :update, :destroy] do
        collection do
          post :generate
        end

        resources :issues, only: [:index, :create, :update]
      end

      resources :issues, module: :boards, only: [:index, :update] do
        collection do
          put :bulk_move, format: :json
        end
      end

      Gitlab.ee do
        resources :users, module: :boards, only: [:index]
        resources :milestones, module: :boards, only: [:index]
      end
    end

    get 'acme-challenge/' => 'acme_challenges#show'

    # UserCallouts
    resources :user_callouts, only: [:create]

    scope :ide, as: :ide, format: false do
      get '/', to: 'ide#index'
      get '/project', to: 'ide#index'

      scope path: 'project/:project_id', as: :project, constraints: { project_id: Gitlab::PathRegex.full_namespace_route_regex } do
        %w[edit tree blob].each do |action|
          get "/#{action}", to: 'ide#index'
          get "/#{action}/*branch/-/*path", to: 'ide#index'
          get "/#{action}/*branch/-", to: 'ide#index'
          get "/#{action}/*branch", to: 'ide#index'
        end

        get '/merge_requests/:merge_request_id', to: 'ide#index', constraints: { merge_request_id: /\d+/ }
        get '/', to: 'ide#index'
      end
    end

    resource :projects

    draw :operations
    draw :jira_connect

    Gitlab.ee do
      draw :security
      draw :smartcard
      draw :username
      draw :trial
      draw :trial_registration
      draw :country
      draw :country_state
      draw :subscription

      scope '/push_from_secondary/:geo_node_id' do
        draw :git_http
      end

      # Used for survey responses
      resources :survey_responses, only: :index
    end

    if ENV['GITLAB_CHAOS_SECRET'] || Rails.env.development? || Rails.env.test?
      resource :chaos, only: [] do
        get :leakmem
        get :cpu_spin
        get :db_spin
        get :sleep
        get :kill
        post :gc
      end
    end

    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]

    # JWKS (JSON Web Key Set) endpoint
    # Used by third parties to verify CI_JOB_JWT
    get 'jwks' => 'jwks#index'

    draw :snippets
    draw :profile

    # Product analytics collector
    match '/collector/i', to: ProductAnalytics::CollectorApp.new, via: :all
  end
  # End of the /-/ scope.

  concern :clusterable do
    resources :clusters, only: [:index, :new, :show, :update, :destroy] do
      collection do
        post :create_user
        post :create_gcp
        post :create_aws
        post :authorize_aws_role
      end

      member do
        Gitlab.ee do
          get :metrics, format: :json
          get :environments, format: :json
        end

        scope :applications do
          post '/:application', to: 'clusters/applications#create', as: :install_applications
          patch '/:application', to: 'clusters/applications#update', as: :update_applications
          delete '/:application', to: 'clusters/applications#destroy', as: :uninstall_applications
        end

        get :metrics_dashboard
        get :'/prometheus/api/v1/*proxy_path', to: 'clusters#prometheus_proxy', as: :prometheus_api
        get :cluster_status, format: :json
        delete :clear_cache
      end
    end
  end

  # Deprecated routes.
  # Will be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/210024
  scope as: :deprecated do
    # Autocomplete
    get '/autocomplete/users' => 'autocomplete#users'
    get '/autocomplete/users/:id' => 'autocomplete#user'
    get '/autocomplete/projects' => 'autocomplete#projects'
    get '/autocomplete/award_emojis' => 'autocomplete#award_emojis'
    get '/autocomplete/merge_request_target_branches' => 'autocomplete#merge_request_target_branches'

    Gitlab.ee do
      get '/autocomplete/project_groups' => 'autocomplete#project_groups'
      get '/autocomplete/project_routes' => 'autocomplete#project_routes'
      get '/autocomplete/namespace_routes' => 'autocomplete#namespace_routes'
    end

    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

    resources :abuse_reports, only: [:new, :create]
  end

  resources :groups, only: [:index, :new, :create] do
    post :preview_markdown
  end

  draw :group

  resources :projects, only: [:index, :new, :create]

  get '/projects/:id' => 'projects#resolve'

  draw :git_http
  draw :api
  draw :sidekiq
  draw :help
  draw :google_api
  draw :import
  draw :uploads
  draw :explore
  draw :admin
  draw :dashboard
  draw :user
  draw :project
  draw :unmatched_project

  # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/210024
  scope as: 'deprecated' do
    draw :snippets

    Gitlab::Routing.redirect_legacy_paths(self, :profile)
  end

  Gitlab.ee do
    get '/sitemap' => 'sitemap#show', format: :xml
  end

  # Creates shorthand helper methods for project resources.
  # For example; for the `namespace_project_path` this also creates `project_path`.
  #
  # TODO: We don't need the `Gitlab::Routing` module at all as we can use
  # the `direct` DSL method of Rails to define url helpers. Move all the
  # custom url helpers to use the `direct` DSL method and remove the `Gitlab::Routing`.
  # For more information: https://gitlab.com/gitlab-org/gitlab/-/issues/299583
  Gitlab::Application.routes.set.filter_map { |route| route.name if route.name&.include?('namespace_project') }.each do |name|
    new_name = name.sub('namespace_project', 'project')

    direct(new_name) do |project, *args|
      # This is due to a bug I've found in Rails.
      # For more information: https://gitlab.com/gitlab-org/gitlab/-/issues/299591
      args.pop if args.last == {}

      send("#{name}_url", project&.namespace, project, *args)
    end
  end

  root to: "root#index"

  get '*unmatched_route', to: 'application#route_not_found'
end

Gitlab::Routing.add_helpers(TimeboxesRoutingHelper)