routes.rb 23.7 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
require 'sidekiq/web'
2
require 'sidekiq/cron/web'
3
require 'api/api'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4

Valery Sizov's avatar
Valery Sizov committed
5
Rails.application.routes.draw do
6 7 8 9 10 11 12 13 14 15 16 17 18
  if Gitlab::Sherlock.enabled?
    namespace :sherlock do
      resources :transactions, only: [:index, :show] do
        resources :queries, only: [:show]
        resources :file_samples, only: [:show]

        collection do
          delete :destroy_all
        end
      end
    end
  end

19
  if Rails.env.development?
20 21 22 23
    # Make the built-in Rails routes available in development, otherwise they'd
    # get swallowed by the `namespace/project` route matcher below.
    #
    # See https://git.io/va79N
24 25 26 27 28
    get '/rails/mailers'         => 'rails/mailers#index'
    get '/rails/mailers/:path'   => 'rails/mailers#preview'
    get '/rails/info/properties' => 'rails/info#properties'
    get '/rails/info/routes'     => 'rails/info#routes'
    get '/rails/info'            => 'rails/info#index'
29 30

    mount LetterOpenerWeb::Engine, at: '/rails/letter_opener'
31 32
  end

33 34
  concern :access_requestable do
    post :request_access, on: :collection
35
    post :approve_access_request, on: :member
36 37
  end

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  namespace :ci do
    # CI API
    Ci::API::API.logger Rails.logger
    mount Ci::API::API => '/api'

    resource :lint, only: [:show, :create]

    resources :projects do
      member do
        get :status, to: 'projects#badge'
        get :integration
      end
    end

    root to: 'projects#index'
  end

Valery Sizov's avatar
Valery Sizov committed
55
  use_doorkeeper do
56 57 58
    controllers applications: 'oauth/applications',
                authorized_applications: 'oauth/authorized_applications',
                authorizations: 'oauth/authorizations'
Valery Sizov's avatar
Valery Sizov committed
59
  end
60

61 62 63
  # Autocomplete
  get '/autocomplete/users' => 'autocomplete#users'
  get '/autocomplete/users/:id' => 'autocomplete#user'
64
  get '/autocomplete/projects' => 'autocomplete#projects'
65

Annabel Dunstone's avatar
Annabel Dunstone committed
66 67
  # Emojis
  resources :emojis, only: :index
68

69
  # Search
70 71
  get 'search' => 'search#show'
  get 'search/autocomplete' => 'search#autocomplete', as: :search_autocomplete
Valery Sizov's avatar
Valery Sizov committed
72

Kamil Trzcinski's avatar
Kamil Trzcinski committed
73 74 75
  # JSON Web Token
  get 'jwt/auth' => 'jwt#auth'

76
  # API
77 78
  API::API.logger Rails.logger
  mount API::API => '/api'
79

80
  constraint = lambda { |request| request.env['warden'].authenticate? and request.env['warden'].user.admin? }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
81
  constraints constraint do
82
    mount Sidekiq::Web, at: '/admin/sidekiq', as: :sidekiq
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
83
  end
Ariejan de Vroom's avatar
Ariejan de Vroom committed
84

85
  # Health check
86
  get 'health_check(/:checks)' => 'health_check#index', as: :health_check
87

88 89
  # Enable Grack support (for LFS only)
  mount Grack::AuthSpawner, at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\/(info\/lfs|gitlab-lfs)/.match(request.path_info) }, via: [:get, :post, :put]
90

91
  # Help
Job van der Voort's avatar
Job van der Voort committed
92
  get 'help'                  => 'help#index'
93
  get 'help/:category/:file'  => 'help#show', as: :help_page, constraints: { category: /.*/, file: /[^\/\.]+/ }
Marin Jankovski's avatar
Marin Jankovski committed
94
  get 'help/shortcuts'
95
  get 'help/ui' => 'help#ui'
96

Andrew8xx8's avatar
Andrew8xx8 committed
97 98 99 100 101
  #
  # Global snippets
  #
  resources :snippets do
    member do
102
      get 'raw'
Andrew8xx8's avatar
Andrew8xx8 committed
103 104
    end
  end
105

Long Nguyen's avatar
Long Nguyen committed
106
  get '/s/:username', to: redirect('/u/%{username}/snippets'),
Long Nguyen's avatar
Long Nguyen committed
107
                      constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
Andrew8xx8's avatar
Andrew8xx8 committed
108

Douwe Maan's avatar
Douwe Maan committed
109 110 111 112 113 114 115
  #
  # Invites
  #

  resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do
    member do
      post :accept
Douwe Maan's avatar
Douwe Maan committed
116
      match :decline, via: [:get, :post]
Douwe Maan's avatar
Douwe Maan committed
117 118
    end
  end
119

120
  resources :sent_notifications, only: [], constraints: { id: /\h{32}/ } do
121 122 123 124 125
    member do
      get :unsubscribe
    end
  end

126
  #
127
  # Spam reports
128
  #
129 130
  resources :abuse_reports, only: [:new, :create]

131 132 133 134 135
  #
  # Notification settings
  #
  resources :notification_settings, only: [:create, :update]

Valery Sizov's avatar
Valery Sizov committed
136
  #
137
  # Import
Valery Sizov's avatar
Valery Sizov committed
138
  #
139 140
  namespace :import do
    resource :github, only: [:create, :new], controller: :github do
141
      post :personal_access_token
142 143 144 145 146
      get :status
      get :callback
      get :jobs
    end

147
    resource :gitlab, only: [:create, :new], controller: :gitlab do
148 149 150 151
      get :status
      get :callback
      get :jobs
    end
Marcin Kulik's avatar
Marcin Kulik committed
152

Douwe Maan's avatar
Douwe Maan committed
153 154 155 156 157
    resource :bitbucket, only: [:create, :new], controller: :bitbucket do
      get :status
      get :callback
      get :jobs
    end
158

Marcin Kulik's avatar
Marcin Kulik committed
159 160 161 162 163
    resource :gitorious, only: [:create, :new], controller: :gitorious do
      get :status
      get :callback
      get :jobs
    end
164 165 166 167 168

    resource :google_code, only: [:create, :new], controller: :google_code do
      get :status
      post :callback
      get :jobs
169 170 171

      get   :new_user_map,    path: :user_map
      post  :create_user_map, path: :user_map
172
    end
Jared Szechy's avatar
Jared Szechy committed
173 174 175 176 177 178 179 180 181

    resource :fogbugz, only: [:create, :new], controller: :fogbugz do
      get :status
      post :callback
      get :jobs

      get   :new_user_map,    path: :user_map
      post  :create_user_map, path: :user_map
    end
182

183
    resource :gitlab_project, only: [:create, :new] do
184
      post :create
185
    end
Valery Sizov's avatar
Valery Sizov committed
186
  end
187

188 189 190
  #
  # Uploads
  #
191

192 193
  scope path: :uploads do
    # Note attachments and User/Group/Project avatars
194 195
    get ":model/:mounted_as/:id/:filename",
        to:           "uploads#show",
196
        constraints:  { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /[^\/]+/ }
197

198 199 200 201 202
    # Appearance
    get ":model/:mounted_as/:id/:filename",
        to:           "uploads#show",
        constraints:  { model: /appearance/, mounted_as: /logo|header_logo/, filename: /.+/ }

203
    # Project markdown uploads
204
    get ":namespace_id/:project_id/:secret/:filename",
205
      to:           "projects/uploads#show",
206
      constraints:  { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: /[^\/]+/ }
207
  end
Valery Sizov's avatar
Valery Sizov committed
208

209
  # Redirect old note attachments path to new uploads path.
210 211
  get "files/note/:id/:filename",
    to:           redirect("uploads/note/attachment/%{id}/%{filename}"),
212
    constraints:  { filename: /[^\/]+/ }
213

214
  #
Yatish Mehta's avatar
Yatish Mehta committed
215
  # Explore area
216
  #
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
217 218 219 220
  namespace :explore do
    resources :projects, only: [:index] do
      collection do
        get :trending
221
        get :starred
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
222 223 224
      end
    end

225
    resources :groups, only: [:index]
226
    resources :snippets, only: [:index]
227
    root to: 'projects#trending'
228 229
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
230
  # Compatibility with old routing
231 232
  get 'public' => 'explore/projects#index'
  get 'public/projects' => 'explore/projects#index'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
233

234 235 236
  #
  # Admin Area
  #
Nihad Abbasov's avatar
Nihad Abbasov committed
237
  namespace :admin do
238
    resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
239
      resources :keys, only: [:show, :destroy]
240
      resources :identities, except: [:show]
241

242
      member do
243 244 245
        get :projects
        get :keys
        get :groups
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
246
        put :team_update
247 248
        put :block
        put :unblock
249
        put :unlock
250
        put :confirm
Douwe Maan's avatar
Douwe Maan committed
251
        post :impersonate
252
        patch :disable_two_factor
253
        delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
254 255
      end
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
256

Douwe Maan's avatar
Douwe Maan committed
257 258
    resource :impersonation, only: :destroy

259
    resources :abuse_reports, only: [:index, :destroy]
260 261
    resources :spam_logs, only: [:index, :destroy]

Valery Sizov's avatar
Valery Sizov committed
262 263
    resources :applications

264 265
    resources :groups, constraints: { id: /[^\/]+/ } do
      member do
266
        put :members_update
267
      end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
268
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
269

270
    resources :deploy_keys, only: [:index, :new, :create, :destroy]
271

272
    resources :hooks, only: [:index, :create, :destroy] do
Valeriy Sizov's avatar
Valeriy Sizov committed
273 274
      get :test
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
275

276 277 278 279
    resources :broadcast_messages, only: [:index, :edit, :create, :update, :destroy] do
      post :preview, on: :collection
    end

280
    resource :logs, only: [:show]
281
    resource :health_check, controller: 'health_check', only: [:show]
282
    resource :background_jobs, controller: 'background_jobs', only: [:show]
283
    resource :system_info, controller: 'system_info', only: [:show]
284

Vinnie Okada's avatar
Vinnie Okada committed
285 286 287
    resources :namespaces, path: '/projects', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
      root to: 'projects#index', as: :projects

288 289
      resources(:projects,
                path: '/',
Vinnie Okada's avatar
Vinnie Okada committed
290 291 292 293 294 295
                constraints: { id: /[a-zA-Z.0-9_\-]+/ },
                only: [:index, :show]) do
        root to: 'projects#show'

        member do
          put :transfer
296
          post :repository_check
Vinnie Okada's avatar
Vinnie Okada committed
297
        end
298

299
        resources :runner_projects, only: [:create, :destroy]
300 301 302
      end
    end

303 304 305 306 307 308 309
    resource :appearances, path: 'appearance' do
      member do
        get :preview
        delete :logo
        delete :header_logos
      end
    end
310

311 312
    resource :application_settings, only: [:show, :update] do
      resources :services
313
      put :reset_runners_token
314
      put :reset_health_check_token
315
      put :clear_repository_check_states
316
    end
317

Valery Sizov's avatar
Valery Sizov committed
318 319
    resources :labels

320 321 322 323 324 325 326 327 328 329 330 331 332
    resources :runners, only: [:index, :show, :update, :destroy] do
      member do
        get :resume
        get :pause
      end
    end

    resources :builds, only: :index do
      collection do
        post :cancel_all
      end
    end

333
    root to: 'dashboard#index'
gitlabhq's avatar
gitlabhq committed
334 335
  end

randx's avatar
randx committed
336 337 338
  #
  # Profile Area
  #
339 340
  resource :profile, only: [:show, :update] do
    member do
341
      get :audit_log
342
      get :applications, to: 'oauth/applications#index'
343 344 345 346

      put :reset_private_token
      put :update_username
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
347

348
    scope module: :profiles do
349 350 351 352 353
      resource :account, only: [:show, :update] do
        member do
          delete :unlink
        end
      end
354
      resource :notifications, only: [:show, :update]
355 356 357 358 359
      resource :password, only: [:new, :create, :edit, :update] do
        member do
          put :reset
        end
      end
360
      resource :preferences, only: [:show, :update]
361
      resources :keys
362
      resources :emails, only: [:index, :create, :destroy]
363
      resource :avatar, only: [:destroy]
364

365 366 367 368 369
      resources :personal_access_tokens, only: [:index, :create] do
        member do
          put :revoke
        end
      end
370

371
      resource :two_factor_auth, only: [:show, :create, :destroy] do
372
        member do
373
          post :create_u2f
374
          post :codes
375
          patch :skip
376 377
        end
      end
378
    end
379
  end
380

Long Nguyen's avatar
Long Nguyen committed
381
  scope(path: 'u/:username',
Long Nguyen's avatar
Long Nguyen committed
382
        as: :user,
Long Nguyen's avatar
Long Nguyen committed
383 384
        constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ },
        controller: :users) do
Long Nguyen's avatar
Long Nguyen committed
385 386 387 388 389 390 391
    get :calendar
    get :calendar_activities
    get :groups
    get :projects
    get :contributed, as: :contributed_projects
    get :snippets
    get '/', action: :show
Long Nguyen's avatar
Long Nguyen committed
392
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
393

randx's avatar
randx committed
394 395 396
  #
  # Dashboard Area
  #
397 398 399 400
  resource :dashboard, controller: 'dashboard', only: [] do
    get :issues
    get :merge_requests
    get :activity
Douwe Maan's avatar
Douwe Maan committed
401 402 403

    scope module: :dashboard do
      resources :milestones, only: [:index, :show]
404
      resources :labels, only: [:index]
405

406
      resources :groups, only: [:index]
407
      resources :snippets, only: [:index]
408 409 410 411 412 413

      resources :todos, only: [:index, :destroy] do
        collection do
          delete :destroy_all
        end
      end
414

415
      resources :projects, only: [:index] do
416 417 418 419
        collection do
          get :starred
        end
      end
Douwe Maan's avatar
Douwe Maan committed
420
    end
421 422

    root to: "dashboard/projects#index"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
423
  end
gitlabhq's avatar
gitlabhq committed
424

randx's avatar
randx committed
425 426 427
  #
  # Groups Area
  #
428
  resources :groups, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }  do
randx's avatar
randx committed
429 430 431
    member do
      get :issues
      get :merge_requests
432
      get :projects
433
      get :activity
randx's avatar
randx committed
434
    end
435

Steven Thonus's avatar
Steven Thonus committed
436
    scope module: :groups do
437
      resources :group_members, only: [:index, :create, :update, :destroy], concerns: :access_requestable do
438
        post :resend_invite, on: :member
439
        delete :leave, on: :collection
440
      end
441

Steven Thonus's avatar
Steven Thonus committed
442
      resource :avatar, only: [:destroy]
443
      resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
Steven Thonus's avatar
Steven Thonus committed
444
    end
randx's avatar
randx committed
445 446
  end

447
  resources :projects, constraints: { id: /[^\/]+/ }, only: [:index, :new, :create]
448

449 450 451 452 453
  devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks,
                                    registrations: :registrations,
                                    passwords: :passwords,
                                    sessions: :sessions,
                                    confirmations: :confirmations }
gitlabhq's avatar
gitlabhq committed
454

455
  devise_scope :user do
456
    get '/users/auth/:provider/omniauth_error' => 'omniauth_callbacks#omniauth_error', as: :omniauth_error
Phil Hughes's avatar
Phil Hughes committed
457
    get '/users/almost_there' => 'confirmations#almost_there'
458
  end
Vinnie Okada's avatar
Vinnie Okada committed
459

460
  root to: "root#index"
Vinnie Okada's avatar
Vinnie Okada committed
461

462 463 464
  #
  # Project Area
  #
Vinnie Okada's avatar
Vinnie Okada committed
465
  resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
466
    resources(:projects, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }, except:
Vinnie Okada's avatar
Vinnie Okada committed
467 468 469
              [:new, :create, :index], path: "/") do
      member do
        put :transfer
470
        delete :remove_fork
Vinnie Okada's avatar
Vinnie Okada committed
471 472
        post :archive
        post :unarchive
473
        post :housekeeping
Vinnie Okada's avatar
Vinnie Okada committed
474 475
        post :toggle_star
        post :markdown_preview
476
        post :export
477
        post :remove_export
478
        post :generate_new_export
479
        get :download_export
Vinnie Okada's avatar
Vinnie Okada committed
480
        get :autocomplete_sources
481
        get :activity
482
        get :refs
skv's avatar
skv committed
483
      end
484

Vinnie Okada's avatar
Vinnie Okada committed
485
      scope module: :projects do
486
        # Git HTTP clients ('git clone' etc.)
487
        scope constraints: { id: /.+\.git/, format: nil } do
Jacob Vosmaer's avatar
Jacob Vosmaer committed
488 489 490
          get '/info/refs', to: 'git_http#info_refs'
          post '/git-upload-pack', to: 'git_http#git_upload_pack'
          post '/git-receive-pack', to: 'git_http#git_receive_pack'
491 492
        end

493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
        # Allow /info/refs, /info/refs?service=git-upload-pack, and
        # /info/refs?service=git-receive-pack, but nothing else.
        #
        git_http_handshake = lambda do |request|
          request.query_string.blank? ||
            request.query_string.match(/\Aservice=git-(upload|receive)-pack\z/)
        end

        ref_redirect = redirect do |params, request|
          path = "#{params[:namespace_id]}/#{params[:project_id]}.git/info/refs"
          path << "?#{request.query_string}" unless request.query_string.blank?
          path
        end

        get '/info/refs', constraints: git_http_handshake, to: ref_redirect

Vinnie Okada's avatar
Vinnie Okada committed
509 510 511 512 513 514 515 516
        # Blob routes:
        get '/new/*id', to: 'blob#new', constraints: { id: /.+/ }, as: 'new_blob'
        post '/create/*id', to: 'blob#create', constraints: { id: /.+/ }, as: 'create_blob'
        get '/edit/*id', to: 'blob#edit', constraints: { id: /.+/ }, as: 'edit_blob'
        put '/update/*id', to: 'blob#update', constraints: { id: /.+/ }, as: 'update_blob'
        post '/preview/*id', to: 'blob#preview', constraints: { id: /.+/ }, as: 'preview_blob'

        scope do
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
          get(
            '/blob/*id/diff',
            to: 'blob#diff',
            constraints: { id: /.+/, format: false },
            as: :blob_diff
          )
          get(
            '/blob/*id',
            to: 'blob#show',
            constraints: { id: /.+/, format: false },
            as: :blob
          )
          delete(
            '/blob/*id',
            to: 'blob#destroy',
            constraints: { id: /.+/, format: false }
          )
534 535 536 537 538 539 540 541 542 543
          put(
            '/blob/*id',
            to: 'blob#update',
            constraints: { id: /.+/, format: false }
          )
          post(
            '/blob/*id',
            to: 'blob#create',
            constraints: { id: /.+/, format: false }
          )
Vinnie Okada's avatar
Vinnie Okada committed
544
        end
545

Vinnie Okada's avatar
Vinnie Okada committed
546 547 548 549 550 551 552
        scope do
          get(
            '/raw/*id',
            to: 'raw#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :raw
          )
553
        end
554

Vinnie Okada's avatar
Vinnie Okada committed
555 556 557 558 559 560 561 562 563
        scope do
          get(
            '/tree/*id',
            to: 'tree#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :tree
          )
        end

564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
        scope do
          get(
            '/find_file/*id',
            to: 'find_file#show',
            constraints: { id: /.+/, format: /html/ },
            as: :find_file
          )
        end

        scope do
          get(
            '/files/*id',
            to: 'find_file#list',
            constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ },
            as: :files
          )
        end

Stan Hu's avatar
Stan Hu committed
582 583
        scope do
          post(
Gabriel Mazetto's avatar
Gabriel Mazetto committed
584
            '/create_dir/*id',
Stan Hu's avatar
Stan Hu committed
585 586 587 588 589 590
              to: 'tree#create_dir',
              constraints: { id: /.+/ },
              as: 'create_dir'
          )
        end

Vinnie Okada's avatar
Vinnie Okada committed
591 592 593 594 595 596 597
        scope do
          get(
            '/blame/*id',
            to: 'blame#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :blame
          )
598
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
599

600 601 602 603
        scope do
          get(
            '/commits/*id',
            to: 'commits#show',
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
604
            constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
605 606 607 608 609
            as: :commits
          )
        end

        resource  :avatar, only: [:show, :destroy]
610
        resources :commit, only: [:show], constraints: { id: /\h{7,40}/ } do
611 612
          member do
            get :branches
Kamil Trzcinski's avatar
Kamil Trzcinski committed
613 614 615
            get :builds
            post :cancel_builds
            post :retry_builds
616
            post :revert
617
            post :cherry_pick
618
            get :diff_for_path
619
          end
620 621
        end

622 623
        resources :compare, only: [:index, :create] do
          collection do
624
            get :diff_for_path
625 626 627 628 629
          end
        end

        get '/compare/:from...:to', to: 'compare#show', as: 'compare', constraints: { from: /.+/, to: /.+/ }

630 631 632
        resources :network, only: [:show], constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ }

        resources :graphs, only: [:show], constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ } do
Vinnie Okada's avatar
Vinnie Okada committed
633 634
          member do
            get :commits
635
            get :ci
636
            get :languages
Vinnie Okada's avatar
Vinnie Okada committed
637
          end
638
        end
639

Vinnie Okada's avatar
Vinnie Okada committed
640 641 642 643
        resources :snippets, constraints: { id: /\d+/ } do
          member do
            get 'raw'
          end
644
        end
645

646
        WIKI_SLUG_ID = { id: /\S+/ } unless defined? WIKI_SLUG_ID
647

Stan Hu's avatar
Stan Hu committed
648 649 650 651 652 653 654 655 656 657 658 659
        scope do
          # Order matters to give priority to these matches
          get '/wikis/git_access', to: 'wikis#git_access'
          get '/wikis/pages', to: 'wikis#pages', as: 'wiki_pages'
          post '/wikis', to: 'wikis#create'

          get '/wikis/*id/history', to: 'wikis#history', as: 'wiki_history', constraints: WIKI_SLUG_ID
          get '/wikis/*id/edit', to: 'wikis#edit', as: 'wiki_edit', constraints: WIKI_SLUG_ID

          get '/wikis/*id', to: 'wikis#show', as: 'wiki', constraints: WIKI_SLUG_ID
          delete '/wikis/*id', to: 'wikis#destroy', constraints: WIKI_SLUG_ID
          put '/wikis/*id', to: 'wikis#update', constraints: WIKI_SLUG_ID
660
          post '/wikis/*id/markdown_preview', to: 'wikis#markdown_preview', constraints: WIKI_SLUG_ID, as: 'wiki_markdown_preview'
661
        end
662

Vinnie Okada's avatar
Vinnie Okada committed
663 664 665 666 667
        resource :repository, only: [:show, :create] do
          member do
            get 'archive', constraints: { format: Gitlab::Regex.archive_formats_regex }
          end
        end
miks's avatar
miks committed
668

Vinnie Okada's avatar
Vinnie Okada committed
669 670 671 672
        resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
          member do
            get :test
          end
673
        end
gitlabhq's avatar
gitlabhq committed
674

675
        resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do
Vinnie Okada's avatar
Vinnie Okada committed
676 677 678 679
          member do
            put :enable
            put :disable
          end
680
        end
gitlabhq's avatar
gitlabhq committed
681

682
        resources :forks, only: [:index, :new, :create]
Vinnie Okada's avatar
Vinnie Okada committed
683 684 685 686 687 688 689 690 691 692
        resource :import, only: [:new, :create, :show]

        resources :refs, only: [] do
          collection do
            get 'switch'
          end

          member do
            # tree viewer logs
            get 'logs_tree', constraints: { id: Gitlab::Regex.git_reference_regex }
693 694
            # Directories with leading dots erroneously get rejected if git
            # ref regex used in constraints. Regex verification now done in controller.
695
            get 'logs_tree/*path' => 'refs#logs_tree', as: :logs_file, constraints: {
696
              id: /.*/,
Vinnie Okada's avatar
Vinnie Okada committed
697 698 699
              path: /.*/
            }
          end
700
        end
701

702
        resources :merge_requests, constraints: { id: /\d+/ } do
Vinnie Okada's avatar
Vinnie Okada committed
703
          member do
704
            get :commits
Vinnie Okada's avatar
Vinnie Okada committed
705
            get :diffs
706
            get :builds
707 708
            get :merge_check
            post :merge
709
            post :cancel_merge_when_build_succeeds
Vinnie Okada's avatar
Vinnie Okada committed
710
            get :ci_status
Valery Sizov's avatar
tests  
Valery Sizov committed
711
            post :toggle_subscription
712
            post :toggle_award_emoji
713
            post :remove_wip
714
            get :diff_for_path
Vinnie Okada's avatar
Vinnie Okada committed
715 716 717 718 719 720
          end

          collection do
            get :branch_from
            get :branch_to
            get :update_branches
721
            get :diff_for_path
Vinnie Okada's avatar
Vinnie Okada committed
722
          end
723
        end
724

Vinnie Okada's avatar
Vinnie Okada committed
725
        resources :branches, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
726 727
        resources :tags, only: [:index, :show, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } do
          resource :release, only: [:edit, :update]
728 729
        end

730
        resources :protected_branches, only: [:index, :show, :create, :update, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
Phil Hughes's avatar
Phil Hughes committed
731
        resources :variables, only: [:index, :show, :update, :create, :destroy]
732
        resources :triggers, only: [:index, :create, :destroy]
733

Kamil Trzcinski's avatar
Kamil Trzcinski committed
734
        resources :pipelines, only: [:index, :new, :create, :show] do
Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
735 736 737 738 739 740
          member do
            post :cancel
            post :retry
          end
        end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
741
        resources :environments, only: [:index, :show, :new, :create, :destroy]
Kamil Trzcinski's avatar
Kamil Trzcinski committed
742

743
        resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
744
          collection do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
745
            post :cancel_all
Kamil Trzcinski's avatar
Kamil Trzcinski committed
746 747
          end

748 749
          member do
            get :status
750
            post :cancel
751
            post :retry
752
            post :erase
753
            get :trace
754
            get :raw
755
          end
756

757 758
          resource :artifacts, only: [] do
            get :download
759 760
            get :browse, path: 'browse(/*path)', format: false
            get :file, path: 'file/*path', format: false
761
            post :keep
762
          end
763
        end
764

Vinnie Okada's avatar
Vinnie Okada committed
765 766 767 768
        resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
          member do
            get :test
          end
769
        end
770

Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
771
        resources :container_registry, only: [:index, :destroy], constraints: { id: Gitlab::Regex.container_registry_reference_regex }
772

773
        resources :milestones, constraints: { id: /\d+/ } do
Vinnie Okada's avatar
Vinnie Okada committed
774 775 776 777
          member do
            put :sort_issues
            put :sort_merge_requests
          end
778
        end
779

Vinnie Okada's avatar
Vinnie Okada committed
780 781 782
        resources :labels, constraints: { id: /\d+/ } do
          collection do
            post :generate
Alfredo Sumaran's avatar
Alfredo Sumaran committed
783
            post :set_priorities
Vinnie Okada's avatar
Vinnie Okada committed
784
          end
785 786 787

          member do
            post :toggle_subscription
788
            delete :remove_priority
789
          end
790
        end
791

792
        resources :issues, constraints: { id: /\d+/ } do
Valery Sizov's avatar
Valery Sizov committed
793
          member do
Valery Sizov's avatar
tests  
Valery Sizov committed
794
            post :toggle_subscription
795
            post :toggle_award_emoji
796 797
            get :referenced_merge_requests
            get :related_branches
798
            get :can_create_branch
Valery Sizov's avatar
Valery Sizov committed
799
          end
Vinnie Okada's avatar
Vinnie Okada committed
800 801 802
          collection do
            post  :bulk_update
          end
803
        end
Robert Speicher's avatar
Robert Speicher committed
804

805
        resources :project_members, except: [:new, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ }, concerns: :access_requestable do
Vinnie Okada's avatar
Vinnie Okada committed
806 807
          collection do
            delete :leave
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
808

Vinnie Okada's avatar
Vinnie Okada committed
809 810 811 812 813
            # Used for import team
            # from another project
            get :import
            post :apply_import
          end
814 815 816 817

          member do
            post :resend_invite
          end
818
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
819

820 821
        resources :group_links, only: [:index, :create, :destroy], constraints: { id: /\d+/ }

Vinnie Okada's avatar
Vinnie Okada committed
822 823
        resources :notes, only: [:index, :create, :destroy, :update], constraints: { id: /\d+/ } do
          member do
Fatih Acet's avatar
Fatih Acet committed
824
            post :toggle_award_emoji
Vinnie Okada's avatar
Vinnie Okada committed
825 826
            delete :delete_attachment
          end
827
        end
828

Phil Hughes's avatar
Phil Hughes committed
829
        resources :todos, only: [:create]
830

831 832
        resources :uploads, only: [:create] do
          collection do
833
            get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
834
          end
835
        end
836

837 838 839 840 841
        resources :runners, only: [:index, :edit, :update, :destroy, :show] do
          member do
            get :resume
            get :pause
          end
842 843 844 845

          collection do
            post :toggle_shared_runners
          end
846
        end
847 848

        resources :runner_projects, only: [:create, :destroy]
849
        resources :badges, only: [:index] do
850
          collection do
851 852 853
            scope '*ref', constraints: { ref: Gitlab::Regex.git_reference_regex } do
              get :build, constraints: { format: /svg/ }
            end
854 855
          end
        end
856
      end
857
    end
gitlabhq's avatar
gitlabhq committed
858
  end
859

860
  # Get all keys of user
861
  get ':username.keys' => 'profiles/keys#get_keys', constraints: { username: /.*/ }
862

863
  get ':id' => 'namespaces#show', constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }
gitlabhq's avatar
gitlabhq committed
864
end