routes.rb 13 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
  # Search
12 13
  get 'search' => 'search#show'
  get 'search/autocomplete' => 'search#autocomplete', as: :search_autocomplete
Valery Sizov's avatar
Valery Sizov committed
14

15
  # API
16 17
  API::API.logger Rails.logger
  mount API::API => '/api'
18

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

22
  constraint = lambda { |request| request.env['warden'].authenticate? and request.env['warden'].user.admin? }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
23
  constraints constraint do
24
    mount Sidekiq::Web, at: '/admin/sidekiq', as: :sidekiq
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
25
  end
Ariejan de Vroom's avatar
Ariejan de Vroom committed
26

27 28
  # Enable Grack support
  mount Grack::Bundle.new({
29
    git_path:     Gitlab.config.git.bin_path,
30 31 32
    project_root: Gitlab.config.gitlab_shell.repos_path,
    upload_pack:  Gitlab.config.gitlab_shell.upload_pack,
    receive_pack: Gitlab.config.gitlab_shell.receive_pack
33
  }), 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
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
  get '/s/:username' => 'snippets#user_index', as: :user_snippets, constraints: { username: /.*/ }
Andrew8xx8's avatar
Andrew8xx8 committed
50

51

Valery Sizov's avatar
Valery Sizov committed
52
  #
53
  # Import
Valery Sizov's avatar
Valery Sizov committed
54
  #
55 56
  namespace :import do
    resource :github, only: [:create, :new], controller: :github do
57 58 59 60 61
      get :status
      get :callback
      get :jobs
    end

62
    resource :gitlab, only: [:create, :new], controller: :gitlab do
63 64 65 66
      get :status
      get :callback
      get :jobs
    end
Marcin Kulik's avatar
Marcin Kulik committed
67

Douwe Maan's avatar
Douwe Maan committed
68 69 70 71 72
    resource :bitbucket, only: [:create, :new], controller: :bitbucket do
      get :status
      get :callback
      get :jobs
    end
73

Marcin Kulik's avatar
Marcin Kulik committed
74 75 76 77 78
    resource :gitorious, only: [:create, :new], controller: :gitorious do
      get :status
      get :callback
      get :jobs
    end
Valery Sizov's avatar
Valery Sizov committed
79
  end
80

81 82 83
  #
  # Uploads
  #
84

85 86
  scope path: :uploads do
    # Note attachments and User/Group/Project avatars
87 88
    get ":model/:mounted_as/:id/:filename",
        to:           "uploads#show",
Douwe Maan's avatar
Douwe Maan committed
89
        constraints:  { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /.+/ }
90 91

    # Project markdown uploads
92
    get ":namespace_id/:project_id/:secret/:filename",
93
      to:           "projects/uploads#show",
94
      constraints:  { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: /.+/ }
95
  end
Valery Sizov's avatar
Valery Sizov committed
96

97
  # Redirect old note attachments path to new uploads path.
98 99 100 101
  get "files/note/:id/:filename",
    to:           redirect("uploads/note/attachment/%{id}/%{filename}"),
    constraints:  { filename: /.+/ }

102
  #
Yatish Mehta's avatar
Yatish Mehta committed
103
  # Explore area
104
  #
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
105 106 107 108
  namespace :explore do
    resources :projects, only: [:index] do
      collection do
        get :trending
109
        get :starred
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
110 111 112
      end
    end

113
    resources :groups, only: [:index]
114
    root to: 'projects#trending'
115 116
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
117
  # Compatibility with old routing
118 119
  get 'public' => 'explore/projects#index'
  get 'public/projects' => 'explore/projects#index'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
120

121 122 123
  #
  # Admin Area
  #
Nihad Abbasov's avatar
Nihad Abbasov committed
124
  namespace :admin do
125
    resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
126
      resources :keys, only: [:show, :destroy]
127
      member do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
128
        put :team_update
129 130
        put :block
        put :unblock
131
        delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
132 133
      end
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
134

Valery Sizov's avatar
Valery Sizov committed
135 136
    resources :applications

137 138
    resources :groups, constraints: { id: /[^\/]+/ } do
      member do
139
        put :project_teams_update
140
      end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
141
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
142

143
    resources :hooks, only: [:index, :create, :destroy] do
Valeriy Sizov's avatar
Valeriy Sizov committed
144 145
      get :test
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
146

147
    resources :broadcast_messages, only: [:index, :create, :destroy]
148
    resource :logs, only: [:show]
149
    resource :background_jobs, controller: 'background_jobs', only: [:show]
150

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

154 155
      resources(:projects,
                path: '/',
Vinnie Okada's avatar
Vinnie Okada committed
156 157 158 159 160 161 162
                constraints: { id: /[a-zA-Z.0-9_\-]+/ },
                only: [:index, :show]) do
        root to: 'projects#show'

        member do
          put :transfer
        end
163 164 165
      end
    end

166 167 168
    resource :application_settings, only: [:show, :update] do
      resources :services
    end
169

170
    root to: 'dashboard#index'
gitlabhq's avatar
gitlabhq committed
171 172
  end

randx's avatar
randx committed
173 174 175
  #
  # Profile Area
  #
176 177 178 179
  resource :profile, only: [:show, :update] do
    member do
      get :history
      get :design
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
180
      get :applications
181 182 183 184

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

186
    scope module: :profiles do
187
      resource :account, only: [:show, :update]
188
      resource :notifications, only: [:show, :update]
189 190 191 192 193
      resource :password, only: [:new, :create, :edit, :update] do
        member do
          put :reset
        end
      end
194
      resources :keys
195
      resources :emails, only: [:index, :create, :destroy]
196
      resource :avatar, only: [:destroy]
197
    end
198
  end
199

200 201 202
  get 'u/:username/calendar' => 'users#calendar', as: :user_calendar,
      constraints: { username: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }

203 204
  get '/u/:username' => 'users#show', as: :user,
      constraints: { username: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
205

randx's avatar
randx committed
206 207 208
  #
  # Dashboard Area
  #
209
  resource :dashboard, controller: 'dashboard', only: [:show] do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
210 211 212 213
    member do
      get :issues
      get :merge_requests
    end
Douwe Maan's avatar
Douwe Maan committed
214 215 216

    scope module: :dashboard do
      resources :milestones, only: [:index, :show]
217 218 219 220 221 222

      resources :groups, only: [:index] do
        member do
          delete :leave
        end
      end
223 224 225 226 227 228

      resources :projects, only: [] do
        collection do
          get :starred
        end
      end
Douwe Maan's avatar
Douwe Maan committed
229
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
230
  end
gitlabhq's avatar
gitlabhq committed
231

randx's avatar
randx committed
232 233 234
  #
  # Groups Area
  #
235
  resources :groups, constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }  do
randx's avatar
randx committed
236 237 238
    member do
      get :issues
      get :merge_requests
239
      get :members
240
      get :projects
randx's avatar
randx committed
241
    end
242

Steven Thonus's avatar
Steven Thonus committed
243
    scope module: :groups do
244
      resources :group_members, only: [:create, :update, :destroy]
Steven Thonus's avatar
Steven Thonus committed
245
      resource :avatar, only: [:destroy]
Douwe Maan's avatar
Douwe Maan committed
246
      resources :milestones, only: [:index, :show, :update]
Steven Thonus's avatar
Steven Thonus committed
247
    end
randx's avatar
randx committed
248 249
  end

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

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

254
  devise_scope :user do
255
    get '/users/auth/:provider/omniauth_error' => 'omniauth_callbacks#omniauth_error', as: :omniauth_error
256
  end
Vinnie Okada's avatar
Vinnie Okada committed
257 258 259

  root to: "dashboard#show"

260 261 262
  #
  # Project Area
  #
Vinnie Okada's avatar
Vinnie Okada committed
263 264 265 266 267 268 269 270 271 272
  resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
    resources(:projects, constraints: { id: /[a-zA-Z.0-9_\-]+/ }, except:
              [: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
273
      end
274

Vinnie Okada's avatar
Vinnie Okada committed
275 276 277 278 279 280 281 282 283
      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
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
          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
301
        end
302

Vinnie Okada's avatar
Vinnie Okada committed
303 304 305 306 307 308 309
        scope do
          get(
            '/raw/*id',
            to: 'raw#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :raw
          )
310
        end
311

Vinnie Okada's avatar
Vinnie Okada committed
312 313 314 315 316 317 318 319 320
        scope do
          get(
            '/tree/*id',
            to: 'tree#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :tree
          )
        end
        resource  :avatar,    only: [:show, :destroy]
321

Vinnie Okada's avatar
Vinnie Okada committed
322 323
        resources :commit,    only: [:show], constraints: { id: /[[:alnum:]]{6,40}/ } do
          get :branches, on: :member
324 325
        end

Vinnie Okada's avatar
Vinnie Okada committed
326 327 328 329 330 331 332 333 334 335
        resources :commits,   only: [:show], constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }
        resources :compare,   only: [:index, :create]

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

Vinnie Okada's avatar
Vinnie Okada committed
338 339 340 341 342
        resources :network,   only: [:show], constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ }
        resources :graphs,    only: [:show], constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ } do
          member do
            get :commits
          end
343
        end
344

Vinnie Okada's avatar
Vinnie Okada committed
345 346
        get '/compare/:from...:to' => 'compare#show', :as => 'compare',
            :constraints => { from: /.+/, to: /.+/ }
347

Vinnie Okada's avatar
Vinnie Okada committed
348 349 350 351
        resources :snippets, constraints: { id: /\d+/ } do
          member do
            get 'raw'
          end
352
        end
353

Vinnie Okada's avatar
Vinnie Okada committed
354 355 356 357 358 359
        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
360

Vinnie Okada's avatar
Vinnie Okada committed
361 362 363
          member do
            get 'history'
          end
364
        end
365

Vinnie Okada's avatar
Vinnie Okada committed
366 367 368 369 370
        resource :repository, only: [:show, :create] do
          member do
            get 'archive', constraints: { format: Gitlab::Regex.archive_formats_regex }
          end
        end
miks's avatar
miks committed
371

Vinnie Okada's avatar
Vinnie Okada committed
372 373 374 375
        resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
          member do
            get :test
          end
376
        end
gitlabhq's avatar
gitlabhq committed
377

Vinnie Okada's avatar
Vinnie Okada committed
378 379 380 381 382
        resources :deploy_keys, constraints: { id: /\d+/ } do
          member do
            put :enable
            put :disable
          end
383
        end
gitlabhq's avatar
gitlabhq committed
384

Vinnie Okada's avatar
Vinnie Okada committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
        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 }
            get 'logs_tree/:path' => 'refs#logs_tree', as: :logs_file, constraints: {
              id: Gitlab::Regex.git_reference_regex,
              path: /.*/
            }
          end
401
        end
402

Vinnie Okada's avatar
Vinnie Okada committed
403 404 405 406 407 408 409 410 411 412 413 414 415
        resources :merge_requests, constraints: { id: /\d+/ }, except: [:destroy] do
          member do
            get :diffs
            post :automerge
            get :automerge_check
            get :ci_status
          end

          collection do
            get :branch_from
            get :branch_to
            get :update_branches
          end
416
        end
417

Vinnie Okada's avatar
Vinnie Okada committed
418 419 420 421 422 423 424 425
        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
426
        end
427

Vinnie Okada's avatar
Vinnie Okada committed
428 429 430 431 432 433
        resources :team, controller: 'team_members', only: [:index]
        resources :milestones, except: [:destroy], constraints: { id: /\d+/ } do
          member do
            put :sort_issues
            put :sort_merge_requests
          end
434
        end
435

Vinnie Okada's avatar
Vinnie Okada committed
436 437 438 439
        resources :labels, constraints: { id: /\d+/ } do
          collection do
            post :generate
          end
440
        end
441

Vinnie Okada's avatar
Vinnie Okada committed
442 443 444 445
        resources :issues, constraints: { id: /\d+/ }, except: [:destroy] do
          collection do
            post  :bulk_update
          end
446
        end
Robert Speicher's avatar
Robert Speicher committed
447

Vinnie Okada's avatar
Vinnie Okada committed
448 449 450
        resources :team_members, except: [:index, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ } do
          collection do
            delete :leave
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
451

Vinnie Okada's avatar
Vinnie Okada committed
452 453 454 455 456
            # Used for import team
            # from another project
            get :import
            post :apply_import
          end
457
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
458

Vinnie Okada's avatar
Vinnie Okada committed
459 460 461 462
        resources :notes, only: [:index, :create, :destroy, :update], constraints: { id: /\d+/ } do
          member do
            delete :delete_attachment
          end
463
        end
464 465 466 467 468

        resources :uploads, only: [:create] do
          collection do
            get ":secret/:filename", action: :show, as: :show, constraints: { filename: /.+/ }
          end
469
        end
470
      end
471

472
    end
gitlabhq's avatar
gitlabhq committed
473
  end
474

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