project.rb 16.2 KB
Newer Older
1 2 3
resources :projects, only: [:index, :new, :create]

draw :git_http
4

5
constraints(::Constraints::ProjectUrlConstrainer.new) do
6 7 8 9 10 11 12 13
  # If the route has a wildcard segment, the segment has a regex constraint,
  # the segment is potentially followed by _another_ wildcard segment, and
  # the `format` option is not set to false, we need to specify that
  # regex constraint _outside_ of `constraints: {}`.
  #
  # Otherwise, Rails will overwrite the constraint with `/.+?/`,
  # which breaks some of our wildcard routes like `/blob/*id`
  # and `/tree/*id` that depend on the negative lookahead inside
14
  # `Gitlab::PathRegex.full_namespace_route_regex`, which helps the router
15 16 17 18 19 20
  # determine whether a certain path segment is part of `*namespace_id`,
  # `:project_id`, or `*id`.
  #
  # See https://github.com/rails/rails/blob/v4.2.8/actionpack/lib/action_dispatch/routing/mapper.rb#L155
  scope(path: '*namespace_id',
        as: :namespace,
21
        namespace_id: Gitlab::PathRegex.full_namespace_route_regex) do
22
    scope(path: ':project_id',
23
          constraints: { project_id: Gitlab::PathRegex.project_route_regex },
24 25
          module: :projects,
          as: :project) do
26

27 28 29 30 31 32 33 34 35 36 37
      resources :autocomplete_sources, only: [] do
        collection do
          get 'members'
          get 'issues'
          get 'merge_requests'
          get 'labels'
          get 'milestones'
          get 'commands'
        end
      end

38 39 40
      #
      # Templates
      #
41
      get '/templates/:template_type/:key' => 'templates#show', as: :template, constraints: { key: %r{[^/]+} }
42 43 44 45 46 47 48 49 50

      resource  :avatar, only: [:show, :destroy]
      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
51
          get :merge_requests
52 53 54
        end
      end

Rob Watson's avatar
Rob Watson committed
55
      resource :pages, only: [:show, :update, :destroy] do
56
        resources :domains, except: :index, controller: 'pages_domains', constraints: { id: %r{[^/]+} } do
57 58 59 60
          member do
            post :verify
          end
        end
61 62
      end

63 64
      resources :snippets, concerns: :awardable, constraints: { id: /\d+/ } do
        member do
65
          get :raw
66
          post :mark_as_spam
67 68 69
        end
      end

70
      resources :services, constraints: { id: %r{[^/]+} }, only: [:edit, :update] do
71
        member do
72
          put :test
73 74 75
        end
      end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
76
      resource :mattermost, only: [:new, :create]
Z.J. van de Weg's avatar
Z.J. van de Weg committed
77

78
      namespace :prometheus do
79
        resources :metrics, constraints: { id: %r{[^\/]+} }, only: [:index, :new, :create, :edit, :update, :destroy] do
80
          post :validate_query, on: :collection
81
          get :active_common, on: :collection
Pawel Chojnacki's avatar
Pawel Chojnacki committed
82
        end
83 84
      end

85
      resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create, :edit, :update] do
86 87 88 89 90 91
        member do
          put :enable
          put :disable
        end
      end

92
      resources :deploy_tokens, constraints: { id: /\d+/ }, only: [] do
93 94 95 96 97
        member do
          put :revoke
        end
      end

98 99 100
      resources :forks, only: [:index, :new, :create]
      resource :import, only: [:new, :create, :show]

101
      resources :merge_requests, concerns: :awardable, except: [:new, :create], constraints: { id: /\d+/ } do
102
        member do
103
          get :commit_change_content
104
          post :merge
105
          post :cancel_merge_when_pipeline_succeeds
106
          get :pipeline_status
107
          get :ci_environments_status
108
          post :toggle_subscription
109 110

          ## EE-specific
111
          get :approvals
112 113
          post :approvals, action: :approve
          delete :approvals, action: :unapprove
114

115 116 117
          post :rebase
          ## EE-specific

118
          post :remove_wip
119
          post :assign_related_issues
Fatih Acet's avatar
Fatih Acet committed
120
          get :discussions, format: :json
121
          post :rebase
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

          scope constraints: { format: nil }, action: :show do
            get :commits, defaults: { tab: 'commits' }
            get :pipelines, defaults: { tab: 'pipelines' }
            get :diffs, defaults: { tab: 'diffs' }
          end

          scope constraints: { format: 'json' }, as: :json do
            get :commits
            get :pipelines
            get :diffs, to: 'merge_requests/diffs#show'
          end

          get :diff_for_path, controller: 'merge_requests/diffs'

          scope controller: 'merge_requests/conflicts' do
            get :conflicts, action: :show
            get :conflict_for_path
            post :resolve_conflicts
          end
142 143 144 145 146 147 148
        end

        collection do
          get :diff_for_path
          post :bulk_update
        end

149 150
        ## EE-specific
        resources :approvers, only: :destroy
Valery Sizov's avatar
Valery Sizov committed
151
        resources :approver_groups, only: :destroy
152 153
        ## EE-specific

154
        resources :discussions, only: [:show], constraints: { id: /\h{40}/ } do
155 156 157 158 159 160 161
          member do
            post :resolve
            delete :resolve, action: :unresolve
          end
        end
      end

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
      controller 'merge_requests/creations', path: 'merge_requests' do
        post '', action: :create, as: nil

        scope path: 'new', as: :new_merge_request do
          get '', action: :new

          scope constraints: { format: nil }, action: :new do
            get :diffs, defaults: { tab: 'diffs' }
            get :pipelines, defaults: { tab: 'pipelines' }
          end

          scope constraints: { format: 'json' }, as: :json do
            get :diffs
            get :pipelines
          end

          get :diff_for_path
          get :branch_from
          get :branch_to
        end
      end

184 185 186 187 188 189 190
      ## EE-specific
      resources :path_locks, only: [:index, :destroy] do
        collection do
          post :toggle
        end
      end

Felipe Artur's avatar
Felipe Artur committed
191 192 193 194
      ## EE-specific
      get '/service_desk' => 'service_desk#show', as: :service_desk
      put '/service_desk' => 'service_desk#update', as: :service_desk_refresh

195
      resource :variables, only: [:show, :update]
196

197 198 199 200 201
      resources :triggers, only: [:index, :create, :edit, :update, :destroy] do
        member do
          post :take_ownership
        end
      end
202

203 204
      resource :mirror, only: [:show, :update] do
        member do
205
          get :ssh_host_keys, constraints: { format: :json }
206 207 208
          post :update_now
        end
      end
209 210

      ## EE-specific
211
      resources :push_rules, constraints: { id: /\d+/ }, only: [:update]
212 213
      ## EE-specific

214 215 216
      resources :pipelines, only: [:index, :new, :create, :show] do
        collection do
          resource :pipelines_settings, path: 'settings', only: [:show, :update]
217
          get :charts
218 219 220
        end

        member do
221
          get :stage
222
          get :stage_ajax
223 224
          post :cancel
          post :retry
Filipa Lacerda's avatar
Filipa Lacerda committed
225
          get :builds
226
          get :failures
227
          get :status
228
          get :security
229 230 231
        end
      end

232 233
      resources :pipeline_schedules, except: [:show] do
        member do
234
          post :play
235 236 237 238
          post :take_ownership
        end
      end

239
      resources :clusters, except: [:edit, :create] do
240
        collection do
241 242
          post :create_gcp
          post :create_user
243
        end
244 245

        member do
246
          get :status, format: :json
247
          get :metrics, format: :json
248

249
          scope :applications do
250
            post '/:application', to: 'clusters/applications#create', as: :install_applications
251
          end
252
        end
253 254
      end

255
      resources :environments, except: [:destroy] do
256 257
        member do
          post :stop
258
          get :terminal
259
          get :metrics
260
          get :additional_metrics
261
          get '/terminal.ws/authorize', to: 'environments#terminal_websocket_authorize', constraints: { format: nil }
262 263 264

          # EE
          get :logs
265
        end
266 267

        collection do
268
          get :metrics, action: :metrics_redirect
269
          get :folder, path: 'folders/*id', constraints: { format: /(html|json)/ }
270
        end
271

272 273 274
        resources :deployments, only: [:index] do
          member do
            get :metrics
275
            get :additional_metrics
276 277
          end
        end
278
      end
279 280 281

      resource :cycle_analytics, only: [:show]

282
      namespace :cycle_analytics do
283
        scope :events, controller: 'events' do
284 285 286 287 288 289 290
          get :issue
          get :plan
          get :code
          get :test
          get :review
          get :staging
          get :production
291 292 293
        end
      end

294
      scope '-' do
295 296
        get 'archive/*id', constraints: { format: Gitlab::PathRegex.archive_formats_regex, id: /.+?/ }, to: 'repositories#archive', as: 'archive'

297 298 299 300 301 302 303 304 305 306
        resources :jobs, only: [:index, :show], constraints: { id: /\d+/ } do
          collection do
            post :cancel_all

            resources :artifacts, only: [] do
              collection do
                get :latest_succeeded,
                  path: '*ref_name_and_path',
                  format: false
              end
307 308 309
            end
          end

310 311 312 313 314 315 316 317
          member do
            get :status
            post :cancel
            post :retry
            post :play
            post :erase
            get :trace, defaults: { format: 'json' }
            get :raw
318 319
            get :terminal
            get '/terminal.ws/authorize', to: 'jobs#terminal_websocket_authorize', constraints: { format: nil }
320
          end
321

322 323 324 325 326 327 328
          resource :artifacts, only: [] do
            get :download
            get :browse, path: 'browse(/*path)', format: false
            get :file, path: 'file/*path', format: false
            get :raw, path: 'raw/*path', format: false
            post :keep
          end
329
        end
330 331 332 333

        namespace :ci do
          resource :lint, only: [:show, :create]
        end
334 335
      end

Lin Jen-Shin's avatar
Lin Jen-Shin committed
336
      draw :legacy_builds
337

338
      resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do
339 340 341
        member do
          get :test
        end
342 343 344 345 346 347

        resources :hook_logs, only: [:show] do
          member do
            get :retry
          end
        end
348 349
      end

350 351 352 353 354
      resources :container_registry, only: [:index, :destroy],
                                     controller: 'registry/repositories'

      namespace :registry do
        resources :repository, only: [] do
355 356 357 358 359 360 361
          # We default to JSON format in the controller to avoid ambiguity.
          # `latest.json` could either be a request for a tag named `latest`
          # in JSON format, or a request for tag named `latest.json`.
          scope format: false do
            resources :tags, only: [:index, :destroy],
                             constraints: { id: Gitlab::Regex.container_registry_tag_regex }
          end
362 363
        end
      end
364 365 366

      resources :milestones, constraints: { id: /\d+/ } do
        member do
367
          post :promote
368 369
          put :sort_issues
          put :sort_merge_requests
370 371 372
          get :merge_requests
          get :participants
          get :labels
373 374 375 376 377 378 379 380 381 382
        end
      end

      resources :labels, except: [:show], constraints: { id: /\d+/ } do
        collection do
          post :generate
          post :set_priorities
        end

        member do
383
          post :promote
384 385 386 387 388
          post :toggle_subscription
          delete :remove_priority
        end
      end

389 390 391
      ## EE-specific
      resources :vulnerability_feedback, only: [:index, :create, :destroy], constraints: { id: /\d+/ }

392
      get :issues, to: 'issues#calendar', constraints: lambda { |req| req.format == :ics }
393 394 395 396
      resources :issues, concerns: :awardable, constraints: { id: /\d+/ } do
        member do
          post :toggle_subscription
          post :mark_as_spam
397
          post :move
398 399 400
          get :referenced_merge_requests
          get :related_branches
          get :can_create_branch
401
          get :realtime_changes
402
          post :create_merge_request
403
          get :discussions, format: :json
404 405
        end
        collection do
406 407
          post :bulk_update
          post :export_csv
408 409

          get :service_desk ## EE-specific
410
        end
411 412

        resources :issue_links, only: [:index, :create, :destroy], as: 'links', path: 'links'
413 414
      end

415
      resources :project_members, except: [:show, :new, :edit], constraints: { id: %r{[a-zA-Z./0-9_\-#%+]+} }, concerns: :access_requestable do
416 417 418 419 420 421 422 423 424 425 426 427 428 429
        collection do
          delete :leave

          # Used for import team
          # from another project
          get :import
          post :apply_import
        end

        member do
          post :resend_invite
        end
      end

430
      resources :group_links, only: [:index, :create, :update, :destroy], constraints: { id: /\d+/ }
431

432
      resources :notes, only: [:create, :destroy, :update], concerns: :awardable, constraints: { id: /\d+/ } do
433 434 435 436 437 438 439
        member do
          delete :delete_attachment
          post :resolve
          delete :resolve, action: :unresolve
        end
      end

440 441
      get 'noteable/:target_type/:target_id/notes' => 'notes#index', as: 'noteable_notes'

442
      # On CE only index and show are needed
443
      resources :boards, only: [:index, :show, :create, :update, :destroy]
444 445 446 447 448

      resources :todos, only: [:create]

      resources :uploads, only: [:create] do
        collection do
449
          get ":secret/:filename", action: :show, as: :show, constraints: { filename: %r{[^/]+} }
450
          post :authorize
451 452 453 454 455
        end
      end

      resources :runners, only: [:index, :edit, :update, :destroy, :show] do
        member do
456 457
          post :resume
          post :pause
458 459 460 461
        end

        collection do
          post :toggle_shared_runners
462
          post :toggle_group_runners
463 464 465
        end
      end

466 467
      ## EE-specific
      resources :approvers, only: :destroy
Valery Sizov's avatar
Valery Sizov committed
468
      resources :approver_groups, only: :destroy
469 470
      ## EE-specific

471 472 473
      resources :runner_projects, only: [:create, :destroy]
      resources :badges, only: [:index] do
        collection do
474
          scope '*ref', constraints: { ref: Gitlab::PathRegex.git_reference_regex } do
475
            constraints format: /svg/ do
476 477 478
              # Keep around until 10.0, see gitlab-org/gitlab-ce#35307
              get :build, to: "badges#pipeline"
              get :pipeline
479 480 481 482 483
              get :coverage
            end
          end
        end
      end
484 485 486 487

      ## EE-specific
      resources :audit_events, only: [:index]
      ## EE-specific
488

489
      namespace :settings do
490
        get :members, to: redirect("%{namespace_id}/%{project_id}/project_members")
491
        resource :ci_cd, only: [:show, :update], controller: 'ci_cd' do
492
          post :reset_cache
493
        end
494
        resource :integrations, only: [:show]
Valery Sizov's avatar
Valery Sizov committed
495

496
        resource :slack, only: [:destroy, :edit, :update] do
Valery Sizov's avatar
Valery Sizov committed
497 498 499
          get :slack_auth
        end

500 501 502
        resource :repository, only: [:show], controller: :repository do
          post :create_deploy_token, path: 'deploy_token/create'
        end
503
        resources :badges, only: [:index]
504 505
      end

506 507 508 509
      # Since both wiki and repository routing contains wildcard characters
      # its preferable to keep it below all other project routes
      draw :wiki
      draw :repository
510
    end
511 512 513

    resources(:projects,
              path: '/',
514
              constraints: { id: Gitlab::PathRegex.project_route_regex },
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
              only: [:edit, :show, :update, :destroy]) do
      member do
        put :transfer
        delete :remove_fork
        post :archive
        post :unarchive
        post :housekeeping
        post :toggle_star
        post :preview_markdown
        post :export
        post :remove_export
        post :generate_new_export
        get :download_export
        get :activity
        get :refs
530
        put :new_issuable_address
531 532
      end
    end
533
  end
534
end
535

536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
# EE-specific
scope path: '/-/jira', as: :jira do
  scope path: '*namespace_id/:project_id',
        namespace_id: Gitlab::Jira::Dvcs::ENCODED_ROUTE_REGEX,
        project_id: Gitlab::Jira::Dvcs::ENCODED_ROUTE_REGEX do
    get '/', to: redirect { |params, req|
      ::Gitlab::Jira::Dvcs.restore_full_path(
        namespace: params[:namespace_id],
        project: params[:project_id]
      )
    }

    get 'commit/:id', constraints: { id: /\h{7,40}/ }, to: redirect { |params, req|
      project_full_path = ::Gitlab::Jira::Dvcs.restore_full_path(
        namespace: params[:namespace_id],
        project: params[:project_id]
      )

      "/#{project_full_path}/commit/#{params[:id]}"
    }

    get 'tree/*id', as: nil, to: redirect { |params, req|
      project_full_path = ::Gitlab::Jira::Dvcs.restore_full_path(
        namespace: params[:namespace_id],
        project: params[:project_id]
      )

      "/#{project_full_path}/tree/#{params[:id]}"
    }
565
  end
566
end