routes.rb 14.2 KB
Newer Older
D
sidekiq  
Dmitriy Zaporozhets 已提交
1
require 'sidekiq/web'
2
require 'api/api'
D
sidekiq  
Dmitriy Zaporozhets 已提交
3

G
gitlabhq 已提交
4
Gitlab::Application.routes.draw do
R
Robert Speicher 已提交
5
  mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
V
Valery Sizov 已提交
6
  use_doorkeeper do
7 8 9
    controllers applications: 'oauth/applications',
                authorized_applications: 'oauth/authorized_applications',
                authorizations: 'oauth/authorizations'
V
Valery Sizov 已提交
10
  end
11

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


17
  # Search
18 19
  get 'search' => 'search#show'
  get 'search/autocomplete' => 'search#autocomplete', as: :search_autocomplete
V
Valery Sizov 已提交
20

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

G
GitLab 已提交
25
  # Get all keys of user
26 27
  get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ }

28
  constraint = lambda { |request| request.env['warden'].authenticate? and request.env['warden'].user.admin? }
D
sidekiq  
Dmitriy Zaporozhets 已提交
29
  constraints constraint do
30
    mount Sidekiq::Web, at: '/admin/sidekiq', as: :sidekiq
D
sidekiq  
Dmitriy Zaporozhets 已提交
31
  end
A
Ariejan de Vroom 已提交
32

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

41
  # Help
J
Job van der Voort 已提交
42
  get 'help'                  => 'help#index'
43
  get 'help/:category/:file'  => 'help#show', as: :help_page, constraints: { category: /.*/, file: /[^\/\.]+/ }
M
Marin Jankovski 已提交
44
  get 'help/shortcuts'
45
  get 'help/ui'               => 'help#ui'
46

A
Andrew8xx8 已提交
47 48 49 50 51
  #
  # Global snippets
  #
  resources :snippets do
    member do
52
      get 'raw'
A
Andrew8xx8 已提交
53 54
    end
  end
55 56

  get '/s/:username' => 'snippets#index', as: :user_snippets, constraints: { username: /.*/ }
A
Andrew8xx8 已提交
57

D
Douwe Maan 已提交
58 59 60 61 62 63 64
  #
  # Invites
  #

  resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do
    member do
      post :accept
D
Douwe Maan 已提交
65
      match :decline, via: [:get, :post]
D
Douwe Maan 已提交
66 67
    end
  end
M
Marin Jankovski 已提交
68

V
Valery Sizov 已提交
69
  #
70
  # Import
V
Valery Sizov 已提交
71
  #
72 73
  namespace :import do
    resource :github, only: [:create, :new], controller: :github do
V
Valery Sizov 已提交
74 75 76 77 78
      get :status
      get :callback
      get :jobs
    end

79
    resource :gitlab, only: [:create, :new], controller: :gitlab do
V
Valery Sizov 已提交
80 81 82 83
      get :status
      get :callback
      get :jobs
    end
M
Marcin Kulik 已提交
84

D
Douwe Maan 已提交
85 86 87 88 89
    resource :bitbucket, only: [:create, :new], controller: :bitbucket do
      get :status
      get :callback
      get :jobs
    end
90

M
Marcin Kulik 已提交
91 92 93 94 95
    resource :gitorious, only: [:create, :new], controller: :gitorious do
      get :status
      get :callback
      get :jobs
    end
96 97 98 99 100

    resource :google_code, only: [:create, :new], controller: :google_code do
      get :status
      post :callback
      get :jobs
D
Douwe Maan 已提交
101 102 103

      get   :new_user_map,    path: :user_map
      post  :create_user_map, path: :user_map
104
    end
V
Valery Sizov 已提交
105
  end
M
Marin Jankovski 已提交
106

107 108 109
  #
  # Uploads
  #
M
Marin Jankovski 已提交
110

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

    # Project markdown uploads
118
    get ":namespace_id/:project_id/:secret/:filename",
119
      to:           "projects/uploads#show",
120
      constraints:  { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: /[^\/]+/ }
121
  end
V
Valery Sizov 已提交
122

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

128
  #
Y
Yatish Mehta 已提交
129
  # Explore area
130
  #
D
Dmitriy Zaporozhets 已提交
131 132 133 134
  namespace :explore do
    resources :projects, only: [:index] do
      collection do
        get :trending
135
        get :starred
D
Dmitriy Zaporozhets 已提交
136 137 138
      end
    end

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

D
Dmitriy Zaporozhets 已提交
143
  # Compatibility with old routing
144 145
  get 'public' => 'explore/projects#index'
  get 'public/projects' => 'explore/projects#index'
D
Dmitriy Zaporozhets 已提交
146

147 148 149
  #
  # Admin Area
  #
N
Nihad Abbasov 已提交
150
  namespace :admin do
151
    resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
152
      resources :keys, only: [:show, :destroy]
153
      member do
D
Dmitriy Zaporozhets 已提交
154
        put :team_update
155 156
        put :block
        put :unblock
157
        delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
D
Dmitriy Zaporozhets 已提交
158 159
      end
    end
A
Andrey Kumanyaev 已提交
160

V
Valery Sizov 已提交
161 162
    resources :applications

163 164
    resources :groups, constraints: { id: /[^\/]+/ } do
      member do
165
        put :members_update
166
      end
A
Andrey Kumanyaev 已提交
167
    end
A
Andrey Kumanyaev 已提交
168

169 170
    resources :deploy_keys, only: [:index, :show, :new, :create, :destroy]

R
Robert Speicher 已提交
171
    resources :hooks, only: [:index, :create, :destroy] do
V
Valeriy Sizov 已提交
172 173
      get :test
    end
A
Andrey Kumanyaev 已提交
174

175
    resources :broadcast_messages, only: [:index, :create, :destroy]
176
    resource :logs, only: [:show]
177
    resource :background_jobs, controller: 'background_jobs', only: [:show]
178

V
Vinnie Okada 已提交
179 180 181
    resources :namespaces, path: '/projects', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
      root to: 'projects#index', as: :projects

182 183
      resources(:projects,
                path: '/',
V
Vinnie Okada 已提交
184 185 186 187 188 189 190
                constraints: { id: /[a-zA-Z.0-9_\-]+/ },
                only: [:index, :show]) do
        root to: 'projects#show'

        member do
          put :transfer
        end
191 192 193
      end
    end

M
Marin Jankovski 已提交
194 195 196
    resource :application_settings, only: [:show, :update] do
      resources :services
    end
197

198
    root to: 'dashboard#index'
G
gitlabhq 已提交
199 200
  end

R
randx 已提交
201 202 203
  #
  # Profile Area
  #
204 205 206 207
  resource :profile, only: [:show, :update] do
    member do
      get :history
      get :design
D
Dmitriy Zaporozhets 已提交
208
      get :applications
209 210 211 212

      put :reset_private_token
      put :update_username
    end
D
Dmitriy Zaporozhets 已提交
213

214
    scope module: :profiles do
215 216 217 218 219
      resource :account, only: [:show, :update] do
        member do
          delete :unlink
        end
      end
220
      resource :notifications, only: [:show, :update]
221 222 223 224 225
      resource :password, only: [:new, :create, :edit, :update] do
        member do
          put :reset
        end
      end
226
      resources :keys
227
      resources :emails, only: [:index, :create, :destroy]
228
      resource :avatar, only: [:destroy]
229
      resource :two_factor_auth, only: [:new, :create, :destroy]
230
    end
231
  end
R
Robert Speicher 已提交
232

233
  get 'u/:username/calendar' => 'users#calendar', as: :user_calendar,
234 235 236 237
      constraints: { username: /.*/ }

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

239
  get '/u/:username' => 'users#show', as: :user,
D
Douwe Maan 已提交
240
      constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
D
Dmitriy Zaporozhets 已提交
241

R
randx 已提交
242 243 244
  #
  # Dashboard Area
  #
245
  resource :dashboard, controller: 'dashboard', only: [:show] do
D
Dmitriy Zaporozhets 已提交
246 247 248 249
    member do
      get :issues
      get :merge_requests
    end
D
Douwe Maan 已提交
250 251 252

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

254
      resources :groups, only: [:index]
255 256 257 258 259 260

      resources :projects, only: [] do
        collection do
          get :starred
        end
      end
D
Douwe Maan 已提交
261
    end
D
Dmitriy Zaporozhets 已提交
262
  end
G
gitlabhq 已提交
263

R
randx 已提交
264 265 266
  #
  # Groups Area
  #
D
Douwe Maan 已提交
267
  resources :groups, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }  do
R
randx 已提交
268 269 270
    member do
      get :issues
      get :merge_requests
D
Dmitriy Zaporozhets 已提交
271
      get :projects
R
randx 已提交
272
    end
273

S
Steven Thonus 已提交
274
    scope module: :groups do
275
      resources :group_members, only: [:index, :create, :update, :destroy] do
276
        post :resend_invite, on: :member
277
        delete :leave, on: :collection
278
      end
279

S
Steven Thonus 已提交
280
      resource :avatar, only: [:destroy]
D
Douwe Maan 已提交
281
      resources :milestones, only: [:index, :show, :update]
S
Steven Thonus 已提交
282
    end
R
randx 已提交
283 284
  end

R
Robert Speicher 已提交
285
  resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
286

287
  devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations , passwords: :passwords, sessions: :sessions, confirmations: :confirmations }
G
gitlabhq 已提交
288

289
  devise_scope :user do
290
    get '/users/auth/:provider/omniauth_error' => 'omniauth_callbacks#omniauth_error', as: :omniauth_error
291
  end
V
Vinnie Okada 已提交
292 293 294

  root to: "dashboard#show"

295 296 297
  #
  # Project Area
  #
V
Vinnie Okada 已提交
298
  resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
D
Douwe Maan 已提交
299
    resources(:projects, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }, except:
V
Vinnie Okada 已提交
300 301 302 303 304 305 306 307
              [:new, :create, :index], path: "/") do
      member do
        put :transfer
        post :archive
        post :unarchive
        post :toggle_star
        post :markdown_preview
        get :autocomplete_sources
S
skv 已提交
308
      end
309

V
Vinnie Okada 已提交
310 311 312 313 314 315 316 317 318
      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
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
          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 }
          )
V
Vinnie Okada 已提交
336
        end
337

V
Vinnie Okada 已提交
338 339 340 341 342 343 344
        scope do
          get(
            '/raw/*id',
            to: 'raw#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :raw
          )
345
        end
346

V
Vinnie Okada 已提交
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
        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
          )
363
        end
D
Dmitriy Zaporozhets 已提交
364

365 366 367 368
        scope do
          get(
            '/commits/*id',
            to: 'commits#show',
D
Dmitriy Zaporozhets 已提交
369
            constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
370 371 372 373 374 375 376 377 378 379 380 381 382
            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
V
Vinnie Okada 已提交
383 384 385
          member do
            get :commits
          end
386
        end
V
Valery Sizov 已提交
387

V
Vinnie Okada 已提交
388 389
        get '/compare/:from...:to' => 'compare#show', :as => 'compare',
            :constraints => { from: /.+/, to: /.+/ }
390

V
Vinnie Okada 已提交
391 392 393 394
        resources :snippets, constraints: { id: /\d+/ } do
          member do
            get 'raw'
          end
395
        end
396

V
Vinnie Okada 已提交
397 398 399 400 401 402
        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
D
Dmitriy Zaporozhets 已提交
403

V
Vinnie Okada 已提交
404 405 406
          member do
            get 'history'
          end
407
        end
408

V
Vinnie Okada 已提交
409 410 411 412 413
        resource :repository, only: [:show, :create] do
          member do
            get 'archive', constraints: { format: Gitlab::Regex.archive_formats_regex }
          end
        end
M
miks 已提交
414

V
Vinnie Okada 已提交
415 416 417 418
        resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
          member do
            get :test
          end
419
        end
G
gitlabhq 已提交
420

421
        resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :show, :new, :create] do
V
Vinnie Okada 已提交
422 423 424 425
          member do
            put :enable
            put :disable
          end
426
        end
G
gitlabhq 已提交
427

V
Vinnie Okada 已提交
428 429 430 431 432 433 434 435 436 437 438
        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 }
439
            get 'logs_tree/*path' => 'refs#logs_tree', as: :logs_file, constraints: {
V
Vinnie Okada 已提交
440 441 442 443
              id: Gitlab::Regex.git_reference_regex,
              path: /.*/
            }
          end
444
        end
445

V
Vinnie Okada 已提交
446 447 448 449 450 451
        resources :merge_requests, constraints: { id: /\d+/ }, except: [:destroy] do
          member do
            get :diffs
            post :automerge
            get :automerge_check
            get :ci_status
V
tests  
Valery Sizov 已提交
452
            post :toggle_subscription
V
Vinnie Okada 已提交
453 454 455 456 457 458 459
          end

          collection do
            get :branch_from
            get :branch_to
            get :update_branches
          end
460
        end
461

V
Vinnie Okada 已提交
462 463 464 465 466 467 468 469
        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
470
        end
471

V
Vinnie Okada 已提交
472 473 474 475 476
        resources :milestones, except: [:destroy], constraints: { id: /\d+/ } do
          member do
            put :sort_issues
            put :sort_merge_requests
          end
D
Dmitriy Zaporozhets 已提交
477
        end
478

V
Vinnie Okada 已提交
479 480 481 482
        resources :labels, constraints: { id: /\d+/ } do
          collection do
            post :generate
          end
483
        end
484

V
Vinnie Okada 已提交
485
        resources :issues, constraints: { id: /\d+/ }, except: [:destroy] do
V
Valery Sizov 已提交
486
          member do
V
tests  
Valery Sizov 已提交
487
            post :toggle_subscription
V
Valery Sizov 已提交
488
          end
V
Vinnie Okada 已提交
489 490 491
          collection do
            post  :bulk_update
          end
492
        end
R
Robert Speicher 已提交
493

494
        resources :project_members, except: [:new, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ } do
V
Vinnie Okada 已提交
495 496
          collection do
            delete :leave
D
Dmitriy Zaporozhets 已提交
497

V
Vinnie Okada 已提交
498 499 500 501 502
            # Used for import team
            # from another project
            get :import
            post :apply_import
          end
503 504 505 506

          member do
            post :resend_invite
          end
507
        end
D
Dmitriy Zaporozhets 已提交
508

V
Vinnie Okada 已提交
509 510 511 512
        resources :notes, only: [:index, :create, :destroy, :update], constraints: { id: /\d+/ } do
          member do
            delete :delete_attachment
          end
513
        end
514 515 516

        resources :uploads, only: [:create] do
          collection do
517
            get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
518
          end
519
        end
520
      end
521

522
    end
G
gitlabhq 已提交
523
  end
R
Robert Speicher 已提交
524

525
  get ':id' => 'namespaces#show', constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }
G
gitlabhq 已提交
526
end