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

gitlabhq's avatar
gitlabhq committed
4
Gitlab::Application.routes.draw do
Valery Sizov's avatar
Valery Sizov committed
5
  use_doorkeeper do
6 7 8
    controllers applications: 'oauth/applications',
                authorized_applications: 'oauth/authorized_applications',
                authorizations: 'oauth/authorizations'
Valery Sizov's avatar
Valery Sizov committed
9
  end
10

11 12 13 14 15
  # Autocomplete
  get '/autocomplete/users' => 'autocomplete#users'
  get '/autocomplete/users/:id' => 'autocomplete#user'


16
  # Search
17 18
  get 'search' => 'search#show'
  get 'search/autocomplete' => 'search#autocomplete', as: :search_autocomplete
Valery Sizov's avatar
Valery Sizov committed
19

20
  # API
21 22
  API::API.logger Rails.logger
  mount API::API => '/api'
23

GitLab's avatar
GitLab committed
24
  # Get all keys of user
25 26
  get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ }

27
  constraint = lambda { |request| request.env['warden'].authenticate? and request.env['warden'].user.admin? }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
28
  constraints constraint do
29
    mount Sidekiq::Web, at: '/admin/sidekiq', as: :sidekiq
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
30
  end
Ariejan de Vroom's avatar
Ariejan de Vroom committed
31

32
  # Enable Grack support
33
  mount Grack::Auth.new({}), at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) }, via: [:get, :post]
34

35
  # Help
Job van der Voort's avatar
Job van der Voort committed
36
  get 'help'                  => 'help#index'
37
  get 'help/:category/:file'  => 'help#show', as: :help_page, constraints: { category: /.*/, file: /[^\/\.]+/ }
Marin Jankovski's avatar
Marin Jankovski committed
38
  get 'help/shortcuts'
39
  get 'help/ui'               => 'help#ui'
40

Andrew8xx8's avatar
Andrew8xx8 committed
41 42 43 44 45
  #
  # Global snippets
  #
  resources :snippets do
    member do
46
      get 'raw'
Andrew8xx8's avatar
Andrew8xx8 committed
47 48
    end
  end
49 50

  get '/s/:username' => 'snippets#index', as: :user_snippets, constraints: { username: /.*/ }
Andrew8xx8's avatar
Andrew8xx8 committed
51

Douwe Maan's avatar
Douwe Maan committed
52 53 54 55 56 57 58
  #
  # Invites
  #

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

63 64 65
  # Spam reports
  resources :abuse_reports, only: [:new, :create]

Valery Sizov's avatar
Valery Sizov committed
66
  #
67
  # Import
Valery Sizov's avatar
Valery Sizov committed
68
  #
69 70
  namespace :import do
    resource :github, only: [:create, :new], controller: :github do
71 72 73 74 75
      get :status
      get :callback
      get :jobs
    end

76
    resource :gitlab, only: [:create, :new], controller: :gitlab do
77 78 79 80
      get :status
      get :callback
      get :jobs
    end
Marcin Kulik's avatar
Marcin Kulik committed
81

Douwe Maan's avatar
Douwe Maan committed
82 83 84 85 86
    resource :bitbucket, only: [:create, :new], controller: :bitbucket do
      get :status
      get :callback
      get :jobs
    end
87

Marcin Kulik's avatar
Marcin Kulik committed
88 89 90 91 92
    resource :gitorious, only: [:create, :new], controller: :gitorious do
      get :status
      get :callback
      get :jobs
    end
93 94 95 96 97

    resource :google_code, only: [:create, :new], controller: :google_code do
      get :status
      post :callback
      get :jobs
98 99 100

      get   :new_user_map,    path: :user_map
      post  :create_user_map, path: :user_map
101
    end
Valery Sizov's avatar
Valery Sizov committed
102
  end
103

104 105 106
  #
  # Uploads
  #
107

108 109
  scope path: :uploads do
    # Note attachments and User/Group/Project avatars
110 111
    get ":model/:mounted_as/:id/:filename",
        to:           "uploads#show",
112
        constraints:  { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /[^\/]+/ }
113 114

    # Project markdown uploads
115
    get ":namespace_id/:project_id/:secret/:filename",
116
      to:           "projects/uploads#show",
117
      constraints:  { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: /[^\/]+/ }
118
  end
Valery Sizov's avatar
Valery Sizov committed
119

120
  # Redirect old note attachments path to new uploads path.
121 122
  get "files/note/:id/:filename",
    to:           redirect("uploads/note/attachment/%{id}/%{filename}"),
123
    constraints:  { filename: /[^\/]+/ }
124

125
  #
Yatish Mehta's avatar
Yatish Mehta committed
126
  # Explore area
127
  #
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
128 129 130 131
  namespace :explore do
    resources :projects, only: [:index] do
      collection do
        get :trending
132
        get :starred
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
133 134 135
      end
    end

136
    resources :groups, only: [:index]
137
    root to: 'projects#trending'
138 139
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
140
  # Compatibility with old routing
141 142
  get 'public' => 'explore/projects#index'
  get 'public/projects' => 'explore/projects#index'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
143

144 145 146
  #
  # Admin Area
  #
Nihad Abbasov's avatar
Nihad Abbasov committed
147
  namespace :admin do
148
    resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
149
      resources :keys, only: [:show, :destroy]
150
      resources :identities, only: [:index, :edit, :update, :destroy]
151

152
      member do
153 154 155
        get :projects
        get :keys
        get :groups
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
156
        put :team_update
157 158
        put :block
        put :unblock
159
        put :unlock
160
        put :confirm
161
        patch :disable_two_factor
162
        delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
163 164
      end
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
165

166
    resources :abuse_reports, only: [:index, :destroy]
Valery Sizov's avatar
Valery Sizov committed
167 168
    resources :applications

169 170
    resources :groups, constraints: { id: /[^\/]+/ } do
      member do
171
        put :members_update
172
      end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
173
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
174

175
    resources :deploy_keys, only: [:index, :new, :create, :destroy]
176

177
    resources :hooks, only: [:index, :create, :destroy] do
Valeriy Sizov's avatar
Valeriy Sizov committed
178 179
      get :test
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
180

181
    resources :broadcast_messages, only: [:index, :create, :destroy]
182
    resource :logs, only: [:show]
183
    resource :background_jobs, controller: 'background_jobs', only: [:show]
184

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

188 189
      resources(:projects,
                path: '/',
Vinnie Okada's avatar
Vinnie Okada committed
190 191 192 193 194 195 196
                constraints: { id: /[a-zA-Z.0-9_\-]+/ },
                only: [:index, :show]) do
        root to: 'projects#show'

        member do
          put :transfer
        end
197 198 199
      end
    end

200 201 202
    resource :application_settings, only: [:show, :update] do
      resources :services
    end
203

Valery Sizov's avatar
Valery Sizov committed
204 205
    resources :labels

206
    root to: 'dashboard#index'
gitlabhq's avatar
gitlabhq committed
207 208
  end

randx's avatar
randx committed
209 210 211
  #
  # Profile Area
  #
212 213
  resource :profile, only: [:show, :update] do
    member do
214
      get :audit_log
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
215
      get :applications
216 217 218 219

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

221
    scope module: :profiles do
222 223 224 225 226
      resource :account, only: [:show, :update] do
        member do
          delete :unlink
        end
      end
227
      resource :notifications, only: [:show, :update]
228 229 230 231 232
      resource :password, only: [:new, :create, :edit, :update] do
        member do
          put :reset
        end
      end
233
      resource :preferences, only: [:show, :update]
234
      resources :keys
235
      resources :emails, only: [:index, :create, :destroy]
236
      resource :avatar, only: [:destroy]
237 238
      resource :two_factor_auth, only: [:new, :create, :destroy] do
        member do
239
          post :codes
240 241
        end
      end
242
    end
243
  end
244

245
  get 'u/:username/calendar' => 'users#calendar', as: :user_calendar,
246 247 248 249
      constraints: { username: /.*/ }

  get 'u/:username/calendar_activities' => 'users#calendar_activities', as: :user_calendar_activities,
      constraints: { username: /.*/ }
250

251
  get '/u/:username' => 'users#show', as: :user,
252
      constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
253

randx's avatar
randx committed
254 255 256
  #
  # Dashboard Area
  #
257
  resource :dashboard, controller: 'dashboard', only: [:show] do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
258 259 260
    member do
      get :issues
      get :merge_requests
261
      get :activity
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
262
    end
Douwe Maan's avatar
Douwe Maan committed
263 264 265

    scope module: :dashboard do
      resources :milestones, only: [:index, :show]
266

267
      resources :groups, only: [:index]
268 269 270 271 272 273

      resources :projects, only: [] do
        collection do
          get :starred
        end
      end
Douwe Maan's avatar
Douwe Maan committed
274
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
275
  end
gitlabhq's avatar
gitlabhq committed
276

randx's avatar
randx committed
277 278 279
  #
  # Groups Area
  #
280
  resources :groups, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }  do
randx's avatar
randx committed
281 282 283
    member do
      get :issues
      get :merge_requests
284
      get :projects
randx's avatar
randx committed
285
    end
286

Steven Thonus's avatar
Steven Thonus committed
287
    scope module: :groups do
288
      resources :group_members, only: [:index, :create, :update, :destroy] do
289
        post :resend_invite, on: :member
290
        delete :leave, on: :collection
291
      end
292

Steven Thonus's avatar
Steven Thonus committed
293
      resource :avatar, only: [:destroy]
Douwe Maan's avatar
Douwe Maan committed
294
      resources :milestones, only: [:index, :show, :update]
Steven Thonus's avatar
Steven Thonus committed
295
    end
randx's avatar
randx committed
296 297
  end

298
  resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
299

300
  devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations , passwords: :passwords, sessions: :sessions, confirmations: :confirmations }
gitlabhq's avatar
gitlabhq committed
301

302
  devise_scope :user do
303
    get '/users/auth/:provider/omniauth_error' => 'omniauth_callbacks#omniauth_error', as: :omniauth_error
304
  end
Vinnie Okada's avatar
Vinnie Okada committed
305

Robert Speicher's avatar
Robert Speicher committed
306
  root to: "root#show"
Vinnie Okada's avatar
Vinnie Okada committed
307

308 309 310
  #
  # Project Area
  #
Vinnie Okada's avatar
Vinnie Okada committed
311
  resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
312
    resources(:projects, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }, except:
Vinnie Okada's avatar
Vinnie Okada committed
313 314 315 316 317 318 319 320
              [:new, :create, :index], path: "/") do
      member do
        put :transfer
        post :archive
        post :unarchive
        post :toggle_star
        post :markdown_preview
        get :autocomplete_sources
321
        get :activity
skv's avatar
skv committed
322
      end
323

Vinnie Okada's avatar
Vinnie Okada committed
324 325 326 327 328 329 330 331 332
      scope module: :projects do
        # 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
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
          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 }
          )
Vinnie Okada's avatar
Vinnie Okada committed
350
        end
351

Vinnie Okada's avatar
Vinnie Okada committed
352 353 354 355 356 357 358
        scope do
          get(
            '/raw/*id',
            to: 'raw#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :raw
          )
359
        end
360

Vinnie Okada's avatar
Vinnie Okada committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
        scope do
          get(
            '/tree/*id',
            to: 'tree#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :tree
          )
        end

        scope do
          get(
            '/blame/*id',
            to: 'blame#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :blame
          )
377
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
378

379 380 381 382
        scope do
          get(
            '/commits/*id',
            to: 'commits#show',
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
383
            constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
384 385 386 387 388 389 390 391 392 393 394 395 396
            as: :commits
          )
        end

        resource  :avatar, only: [:show, :destroy]
        resources :commit, only: [:show], constraints: { id: /[[:alnum:]]{6,40}/ } do
          get :branches, on: :member
        end

        resources :compare, only: [:index, :create]
        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
397 398 399
          member do
            get :commits
          end
400
        end
401

Vinnie Okada's avatar
Vinnie Okada committed
402 403
        get '/compare/:from...:to' => 'compare#show', :as => 'compare',
            :constraints => { from: /.+/, to: /.+/ }
404

Vinnie Okada's avatar
Vinnie Okada committed
405 406 407 408
        resources :snippets, constraints: { id: /\d+/ } do
          member do
            get 'raw'
          end
409
        end
410

Vinnie Okada's avatar
Vinnie Okada committed
411 412 413 414 415 416
        resources :wikis, only: [:show, :edit, :destroy, :create], constraints: { id: /[a-zA-Z.0-9_\-\/]+/ } do
          collection do
            get :pages
            put ':id' => 'wikis#update'
            get :git_access
          end
417

Vinnie Okada's avatar
Vinnie Okada committed
418 419 420
          member do
            get 'history'
          end
421
        end
422

Vinnie Okada's avatar
Vinnie Okada committed
423 424 425 426 427
        resource :repository, only: [:show, :create] do
          member do
            get 'archive', constraints: { format: Gitlab::Regex.archive_formats_regex }
          end
        end
miks's avatar
miks committed
428

Vinnie Okada's avatar
Vinnie Okada committed
429 430 431 432
        resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
          member do
            get :test
          end
433
        end
gitlabhq's avatar
gitlabhq committed
434

435
        resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do
Vinnie Okada's avatar
Vinnie Okada committed
436 437 438 439
          member do
            put :enable
            put :disable
          end
440
        end
gitlabhq's avatar
gitlabhq committed
441

Vinnie Okada's avatar
Vinnie Okada committed
442 443 444 445 446 447 448 449 450 451 452
        resource :fork, only: [:new, :create]
        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 }
453
            get 'logs_tree/*path' => 'refs#logs_tree', as: :logs_file, constraints: {
Vinnie Okada's avatar
Vinnie Okada committed
454 455 456 457
              id: Gitlab::Regex.git_reference_regex,
              path: /.*/
            }
          end
458
        end
459

Vinnie Okada's avatar
Vinnie Okada committed
460 461 462
        resources :merge_requests, constraints: { id: /\d+/ }, except: [:destroy] do
          member do
            get :diffs
463
            get :commits
464 465
            post :merge
            get :merge_check
Vinnie Okada's avatar
Vinnie Okada committed
466
            get :ci_status
Valery Sizov's avatar
tests  
Valery Sizov committed
467
            post :toggle_subscription
Vinnie Okada's avatar
Vinnie Okada committed
468 469 470 471 472 473 474
          end

          collection do
            get :branch_from
            get :branch_to
            get :update_branches
          end
475
        end
476

Vinnie Okada's avatar
Vinnie Okada committed
477 478 479 480 481 482 483 484
        resources :branches, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
        resources :tags, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
        resources :protected_branches, only: [:index, :create, :update, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }

        resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
          member do
            get :test
          end
485
        end
486

487
        resources :milestones, constraints: { id: /\d+/ } do
Vinnie Okada's avatar
Vinnie Okada committed
488 489 490 491
          member do
            put :sort_issues
            put :sort_merge_requests
          end
492
        end
493

Vinnie Okada's avatar
Vinnie Okada committed
494 495 496 497
        resources :labels, constraints: { id: /\d+/ } do
          collection do
            post :generate
          end
498
        end
499

Vinnie Okada's avatar
Vinnie Okada committed
500
        resources :issues, constraints: { id: /\d+/ }, except: [:destroy] do
Valery Sizov's avatar
Valery Sizov committed
501
          member do
Valery Sizov's avatar
tests  
Valery Sizov committed
502
            post :toggle_subscription
Valery Sizov's avatar
Valery Sizov committed
503
          end
Vinnie Okada's avatar
Vinnie Okada committed
504 505 506
          collection do
            post  :bulk_update
          end
507
        end
Robert Speicher's avatar
Robert Speicher committed
508

509
        resources :project_members, except: [:new, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ } do
Vinnie Okada's avatar
Vinnie Okada committed
510 511
          collection do
            delete :leave
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
512

Vinnie Okada's avatar
Vinnie Okada committed
513 514 515 516 517
            # Used for import team
            # from another project
            get :import
            post :apply_import
          end
518 519 520 521

          member do
            post :resend_invite
          end
522
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
523

Vinnie Okada's avatar
Vinnie Okada committed
524 525 526 527
        resources :notes, only: [:index, :create, :destroy, :update], constraints: { id: /\d+/ } do
          member do
            delete :delete_attachment
          end
528
        end
529 530 531

        resources :uploads, only: [:create] do
          collection do
532
            get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
533
          end
534
        end
535
      end
536

537
    end
gitlabhq's avatar
gitlabhq committed
538
  end
539

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