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 33
  # Enable Grack support
  mount Grack::Bundle.new({
34
    git_path:     Gitlab.config.git.bin_path,
35 36 37
    project_root: Gitlab.config.gitlab_shell.repos_path,
    upload_pack:  Gitlab.config.gitlab_shell.upload_pack,
    receive_pack: Gitlab.config.gitlab_shell.receive_pack
38
  }), at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) }, via: [:get, :post]
39

40
  # Help
Job van der Voort's avatar
Job van der Voort committed
41
  get 'help'                  => 'help#index'
42
  get 'help/:category/:file'  => 'help#show', as: :help_page, constraints: { category: /.*/, file: /[^\/\.]+/ }
Marin Jankovski's avatar
Marin Jankovski committed
43
  get 'help/shortcuts'
44
  get 'help/ui'               => 'help#ui'
45

Andrew8xx8's avatar
Andrew8xx8 committed
46 47 48 49 50
  #
  # Global snippets
  #
  resources :snippets do
    member do
51
      get 'raw'
Andrew8xx8's avatar
Andrew8xx8 committed
52 53
    end
  end
54 55

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

Douwe Maan's avatar
Douwe Maan committed
57 58 59 60 61 62 63
  #
  # Invites
  #

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

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

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

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

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

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

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

106 107 108
  #
  # Uploads
  #
109

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

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

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

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

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

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

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

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

Valery Sizov's avatar
Valery Sizov committed
165 166
    resources :applications

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

173
    resources :deploy_keys, only: [:index, :new, :create, :destroy]
174

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

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

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

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

        member do
          put :transfer
        end
195 196 197
      end
    end

198 199 200
    resource :application_settings, only: [:show, :update] do
      resources :services
    end
201

202
    root to: 'dashboard#index'
gitlabhq's avatar
gitlabhq committed
203 204
  end

randx's avatar
randx committed
205 206 207
  #
  # Profile Area
  #
208 209 210
  resource :profile, only: [:show, :update] do
    member do
      get :history
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
211
      get :applications
212 213 214 215

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

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

241
  get 'u/:username/calendar' => 'users#calendar', as: :user_calendar,
242 243 244 245
      constraints: { username: /.*/ }

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

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

randx's avatar
randx committed
250 251 252
  #
  # Dashboard Area
  #
253
  resource :dashboard, controller: 'dashboard', only: [:show] do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
254 255 256 257
    member do
      get :issues
      get :merge_requests
    end
Douwe Maan's avatar
Douwe Maan committed
258 259 260

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

262
      resources :groups, only: [:index]
263 264 265 266 267 268

      resources :projects, only: [] do
        collection do
          get :starred
        end
      end
Douwe Maan's avatar
Douwe Maan committed
269
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
270
  end
gitlabhq's avatar
gitlabhq committed
271

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

Steven Thonus's avatar
Steven Thonus committed
282
    scope module: :groups do
283
      resources :group_members, only: [:index, :create, :update, :destroy] do
284
        post :resend_invite, on: :member
285
        delete :leave, on: :collection
286
      end
287

Steven Thonus's avatar
Steven Thonus committed
288
      resource :avatar, only: [:destroy]
Douwe Maan's avatar
Douwe Maan committed
289
      resources :milestones, only: [:index, :show, :update]
Steven Thonus's avatar
Steven Thonus committed
290
    end
randx's avatar
randx committed
291 292
  end

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

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

297
  devise_scope :user do
298
    get '/users/auth/:provider/omniauth_error' => 'omniauth_callbacks#omniauth_error', as: :omniauth_error
299
  end
Vinnie Okada's avatar
Vinnie Okada committed
300

Robert Speicher's avatar
Robert Speicher committed
301
  root to: "root#show"
Vinnie Okada's avatar
Vinnie Okada committed
302

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

Vinnie Okada's avatar
Vinnie Okada committed
318 319 320 321 322 323 324 325 326
      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
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
          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
344
        end
345

Vinnie Okada's avatar
Vinnie Okada committed
346 347 348 349 350 351 352
        scope do
          get(
            '/raw/*id',
            to: 'raw#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :raw
          )
353
        end
354

Vinnie Okada's avatar
Vinnie Okada committed
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
        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
          )
371
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
372

373 374 375 376
        scope do
          get(
            '/commits/*id',
            to: 'commits#show',
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
377
            constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
378 379 380 381 382 383 384 385 386 387 388 389 390
            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
391 392 393
          member do
            get :commits
          end
394
        end
395

Vinnie Okada's avatar
Vinnie Okada committed
396 397
        get '/compare/:from...:to' => 'compare#show', :as => 'compare',
            :constraints => { from: /.+/, to: /.+/ }
398

Vinnie Okada's avatar
Vinnie Okada committed
399 400 401 402
        resources :snippets, constraints: { id: /\d+/ } do
          member do
            get 'raw'
          end
403
        end
404

Vinnie Okada's avatar
Vinnie Okada committed
405 406 407 408 409 410
        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
411

Vinnie Okada's avatar
Vinnie Okada committed
412 413 414
          member do
            get 'history'
          end
415
        end
416

Vinnie Okada's avatar
Vinnie Okada committed
417 418 419 420 421
        resource :repository, only: [:show, :create] do
          member do
            get 'archive', constraints: { format: Gitlab::Regex.archive_formats_regex }
          end
        end
miks's avatar
miks committed
422

Vinnie Okada's avatar
Vinnie Okada committed
423 424 425 426
        resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
          member do
            get :test
          end
427
        end
gitlabhq's avatar
gitlabhq committed
428

429
        resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do
Vinnie Okada's avatar
Vinnie Okada committed
430 431 432 433
          member do
            put :enable
            put :disable
          end
434
        end
gitlabhq's avatar
gitlabhq committed
435

Vinnie Okada's avatar
Vinnie Okada committed
436 437 438 439 440 441 442 443 444 445 446
        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 }
447
            get 'logs_tree/*path' => 'refs#logs_tree', as: :logs_file, constraints: {
Vinnie Okada's avatar
Vinnie Okada committed
448 449 450 451
              id: Gitlab::Regex.git_reference_regex,
              path: /.*/
            }
          end
452
        end
453

Vinnie Okada's avatar
Vinnie Okada committed
454 455 456
        resources :merge_requests, constraints: { id: /\d+/ }, except: [:destroy] do
          member do
            get :diffs
457
            get :commits
Vinnie Okada's avatar
Vinnie Okada committed
458 459 460
            post :automerge
            get :automerge_check
            get :ci_status
Valery Sizov's avatar
tests  
Valery Sizov committed
461
            post :toggle_subscription
Vinnie Okada's avatar
Vinnie Okada committed
462 463 464 465 466 467 468
          end

          collection do
            get :branch_from
            get :branch_to
            get :update_branches
          end
469
        end
470

Vinnie Okada's avatar
Vinnie Okada committed
471 472 473 474 475 476 477 478
        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
479
        end
480

Vinnie Okada's avatar
Vinnie Okada committed
481 482 483 484 485
        resources :milestones, except: [:destroy], constraints: { id: /\d+/ } do
          member do
            put :sort_issues
            put :sort_merge_requests
          end
486
        end
487

Vinnie Okada's avatar
Vinnie Okada committed
488 489 490 491
        resources :labels, constraints: { id: /\d+/ } do
          collection do
            post :generate
          end
492
        end
493

Vinnie Okada's avatar
Vinnie Okada committed
494
        resources :issues, constraints: { id: /\d+/ }, except: [:destroy] do
Valery Sizov's avatar
Valery Sizov committed
495
          member do
Valery Sizov's avatar
tests  
Valery Sizov committed
496
            post :toggle_subscription
Valery Sizov's avatar
Valery Sizov committed
497
          end
Vinnie Okada's avatar
Vinnie Okada committed
498 499 500
          collection do
            post  :bulk_update
          end
501
        end
Robert Speicher's avatar
Robert Speicher committed
502

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

Vinnie Okada's avatar
Vinnie Okada committed
507 508 509 510 511
            # Used for import team
            # from another project
            get :import
            post :apply_import
          end
512 513 514 515

          member do
            post :resend_invite
          end
516
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
517

Vinnie Okada's avatar
Vinnie Okada committed
518 519 520 521
        resources :notes, only: [:index, :create, :destroy, :update], constraints: { id: /\d+/ } do
          member do
            delete :delete_attachment
          end
522
        end
523 524 525

        resources :uploads, only: [:create] do
          collection do
526
            get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
527
          end
528
        end
529
      end
530

531
    end
gitlabhq's avatar
gitlabhq committed
532
  end
533

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