PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/config/routes.rb

https://gitlab.com/simepy/gitlab-ce
Ruby | 538 lines | 405 code | 89 blank | 44 comment | 0 complexity | 681f2f8ead964ba840b8895c2ee7b499 MD5 | raw file
  1. require 'sidekiq/web'
  2. require 'api/api'
  3. Gitlab::Application.routes.draw do
  4. use_doorkeeper do
  5. controllers applications: 'oauth/applications',
  6. authorized_applications: 'oauth/authorized_applications',
  7. authorizations: 'oauth/authorizations'
  8. end
  9. # Autocomplete
  10. get '/autocomplete/users' => 'autocomplete#users'
  11. get '/autocomplete/users/:id' => 'autocomplete#user'
  12. # Search
  13. get 'search' => 'search#show'
  14. get 'search/autocomplete' => 'search#autocomplete', as: :search_autocomplete
  15. # API
  16. API::API.logger Rails.logger
  17. mount API::API => '/api'
  18. # Get all keys of user
  19. get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ }
  20. constraint = lambda { |request| request.env['warden'].authenticate? and request.env['warden'].user.admin? }
  21. constraints constraint do
  22. mount Sidekiq::Web, at: '/admin/sidekiq', as: :sidekiq
  23. end
  24. # Enable Grack support
  25. mount Grack::Bundle.new({
  26. git_path: Gitlab.config.git.bin_path,
  27. project_root: Gitlab.config.gitlab_shell.repos_path,
  28. upload_pack: Gitlab.config.gitlab_shell.upload_pack,
  29. receive_pack: Gitlab.config.gitlab_shell.receive_pack
  30. }), at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) }, via: [:get, :post]
  31. # Help
  32. get 'help' => 'help#index'
  33. get 'help/:category/:file' => 'help#show', as: :help_page, constraints: { category: /.*/, file: /[^\/\.]+/ }
  34. get 'help/shortcuts'
  35. get 'help/ui' => 'help#ui'
  36. #
  37. # Global snippets
  38. #
  39. resources :snippets do
  40. member do
  41. get 'raw'
  42. end
  43. end
  44. get '/s/:username' => 'snippets#index', as: :user_snippets, constraints: { username: /.*/ }
  45. #
  46. # Invites
  47. #
  48. resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do
  49. member do
  50. post :accept
  51. match :decline, via: [:get, :post]
  52. end
  53. end
  54. #
  55. # Import
  56. #
  57. namespace :import do
  58. resource :github, only: [:create, :new], controller: :github do
  59. get :status
  60. get :callback
  61. get :jobs
  62. end
  63. resource :gitlab, only: [:create, :new], controller: :gitlab do
  64. get :status
  65. get :callback
  66. get :jobs
  67. end
  68. resource :bitbucket, only: [:create, :new], controller: :bitbucket do
  69. get :status
  70. get :callback
  71. get :jobs
  72. end
  73. resource :gitorious, only: [:create, :new], controller: :gitorious do
  74. get :status
  75. get :callback
  76. get :jobs
  77. end
  78. resource :google_code, only: [:create, :new], controller: :google_code do
  79. get :status
  80. post :callback
  81. get :jobs
  82. get :new_user_map, path: :user_map
  83. post :create_user_map, path: :user_map
  84. end
  85. end
  86. #
  87. # Uploads
  88. #
  89. scope path: :uploads do
  90. # Note attachments and User/Group/Project avatars
  91. get ":model/:mounted_as/:id/:filename",
  92. to: "uploads#show",
  93. constraints: { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /[^\/]+/ }
  94. # Project markdown uploads
  95. get ":namespace_id/:project_id/:secret/:filename",
  96. to: "projects/uploads#show",
  97. constraints: { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: /[^\/]+/ }
  98. end
  99. # Redirect old note attachments path to new uploads path.
  100. get "files/note/:id/:filename",
  101. to: redirect("uploads/note/attachment/%{id}/%{filename}"),
  102. constraints: { filename: /[^\/]+/ }
  103. #
  104. # Explore area
  105. #
  106. namespace :explore do
  107. resources :projects, only: [:index] do
  108. collection do
  109. get :trending
  110. get :starred
  111. end
  112. end
  113. resources :groups, only: [:index]
  114. root to: 'projects#trending'
  115. end
  116. # Compatibility with old routing
  117. get 'public' => 'explore/projects#index'
  118. get 'public/projects' => 'explore/projects#index'
  119. #
  120. # Admin Area
  121. #
  122. namespace :admin do
  123. resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
  124. resources :keys, only: [:show, :destroy]
  125. resources :identities, only: [:index, :edit, :update, :destroy]
  126. member do
  127. get :projects
  128. get :keys
  129. get :groups
  130. put :team_update
  131. put :block
  132. put :unblock
  133. put :unlock
  134. patch :disable_two_factor
  135. delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
  136. end
  137. end
  138. resources :applications
  139. resources :groups, constraints: { id: /[^\/]+/ } do
  140. member do
  141. put :members_update
  142. end
  143. end
  144. resources :deploy_keys, only: [:index, :new, :create, :destroy]
  145. resources :hooks, only: [:index, :create, :destroy] do
  146. get :test
  147. end
  148. resources :broadcast_messages, only: [:index, :create, :destroy]
  149. resource :logs, only: [:show]
  150. resource :background_jobs, controller: 'background_jobs', only: [:show]
  151. resources :namespaces, path: '/projects', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
  152. root to: 'projects#index', as: :projects
  153. resources(:projects,
  154. path: '/',
  155. constraints: { id: /[a-zA-Z.0-9_\-]+/ },
  156. only: [:index, :show]) do
  157. root to: 'projects#show'
  158. member do
  159. put :transfer
  160. end
  161. end
  162. end
  163. resource :application_settings, only: [:show, :update] do
  164. resources :services
  165. end
  166. root to: 'dashboard#index'
  167. end
  168. #
  169. # Profile Area
  170. #
  171. resource :profile, only: [:show, :update] do
  172. member do
  173. get :audit_log
  174. get :applications
  175. put :reset_private_token
  176. put :update_username
  177. end
  178. scope module: :profiles do
  179. resource :account, only: [:show, :update] do
  180. member do
  181. delete :unlink
  182. end
  183. end
  184. resource :notifications, only: [:show, :update]
  185. resource :password, only: [:new, :create, :edit, :update] do
  186. member do
  187. put :reset
  188. end
  189. end
  190. resource :preferences, only: [:show, :update]
  191. resources :keys
  192. resources :emails, only: [:index, :create, :destroy]
  193. resource :avatar, only: [:destroy]
  194. resource :two_factor_auth, only: [:new, :create, :destroy] do
  195. member do
  196. post :codes
  197. end
  198. end
  199. end
  200. end
  201. get 'u/:username/calendar' => 'users#calendar', as: :user_calendar,
  202. constraints: { username: /.*/ }
  203. get 'u/:username/calendar_activities' => 'users#calendar_activities', as: :user_calendar_activities,
  204. constraints: { username: /.*/ }
  205. get '/u/:username' => 'users#show', as: :user,
  206. constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
  207. #
  208. # Dashboard Area
  209. #
  210. resource :dashboard, controller: 'dashboard', only: [:show] do
  211. member do
  212. get :issues
  213. get :merge_requests
  214. end
  215. scope module: :dashboard do
  216. resources :milestones, only: [:index, :show]
  217. resources :groups, only: [:index]
  218. resources :projects, only: [] do
  219. collection do
  220. get :starred
  221. end
  222. end
  223. end
  224. end
  225. #
  226. # Groups Area
  227. #
  228. resources :groups, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ } do
  229. member do
  230. get :issues
  231. get :merge_requests
  232. get :projects
  233. end
  234. scope module: :groups do
  235. resources :group_members, only: [:index, :create, :update, :destroy] do
  236. post :resend_invite, on: :member
  237. delete :leave, on: :collection
  238. end
  239. resource :avatar, only: [:destroy]
  240. resources :milestones, only: [:index, :show, :update]
  241. end
  242. end
  243. resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
  244. devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations , passwords: :passwords, sessions: :sessions, confirmations: :confirmations }
  245. devise_scope :user do
  246. get '/users/auth/:provider/omniauth_error' => 'omniauth_callbacks#omniauth_error', as: :omniauth_error
  247. end
  248. root to: "root#show"
  249. #
  250. # Project Area
  251. #
  252. resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
  253. resources(:projects, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }, except:
  254. [:new, :create, :index], path: "/") do
  255. member do
  256. put :transfer
  257. post :archive
  258. post :unarchive
  259. post :toggle_star
  260. post :markdown_preview
  261. get :autocomplete_sources
  262. get :activity
  263. end
  264. scope module: :projects do
  265. # Blob routes:
  266. get '/new/*id', to: 'blob#new', constraints: { id: /.+/ }, as: 'new_blob'
  267. post '/create/*id', to: 'blob#create', constraints: { id: /.+/ }, as: 'create_blob'
  268. get '/edit/*id', to: 'blob#edit', constraints: { id: /.+/ }, as: 'edit_blob'
  269. put '/update/*id', to: 'blob#update', constraints: { id: /.+/ }, as: 'update_blob'
  270. post '/preview/*id', to: 'blob#preview', constraints: { id: /.+/ }, as: 'preview_blob'
  271. scope do
  272. get(
  273. '/blob/*id/diff',
  274. to: 'blob#diff',
  275. constraints: { id: /.+/, format: false },
  276. as: :blob_diff
  277. )
  278. get(
  279. '/blob/*id',
  280. to: 'blob#show',
  281. constraints: { id: /.+/, format: false },
  282. as: :blob
  283. )
  284. delete(
  285. '/blob/*id',
  286. to: 'blob#destroy',
  287. constraints: { id: /.+/, format: false }
  288. )
  289. end
  290. scope do
  291. get(
  292. '/raw/*id',
  293. to: 'raw#show',
  294. constraints: { id: /.+/, format: /(html|js)/ },
  295. as: :raw
  296. )
  297. end
  298. scope do
  299. get(
  300. '/tree/*id',
  301. to: 'tree#show',
  302. constraints: { id: /.+/, format: /(html|js)/ },
  303. as: :tree
  304. )
  305. end
  306. scope do
  307. get(
  308. '/blame/*id',
  309. to: 'blame#show',
  310. constraints: { id: /.+/, format: /(html|js)/ },
  311. as: :blame
  312. )
  313. end
  314. scope do
  315. get(
  316. '/commits/*id',
  317. to: 'commits#show',
  318. constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
  319. as: :commits
  320. )
  321. end
  322. resource :avatar, only: [:show, :destroy]
  323. resources :commit, only: [:show], constraints: { id: /[[:alnum:]]{6,40}/ } do
  324. get :branches, on: :member
  325. end
  326. resources :compare, only: [:index, :create]
  327. resources :network, only: [:show], constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ }
  328. resources :graphs, only: [:show], constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ } do
  329. member do
  330. get :commits
  331. end
  332. end
  333. get '/compare/:from...:to' => 'compare#show', :as => 'compare',
  334. :constraints => { from: /.+/, to: /.+/ }
  335. resources :snippets, constraints: { id: /\d+/ } do
  336. member do
  337. get 'raw'
  338. end
  339. end
  340. resources :wikis, only: [:show, :edit, :destroy, :create], constraints: { id: /[a-zA-Z.0-9_\-\/]+/ } do
  341. collection do
  342. get :pages
  343. put ':id' => 'wikis#update'
  344. get :git_access
  345. end
  346. member do
  347. get 'history'
  348. end
  349. end
  350. resource :repository, only: [:show, :create] do
  351. member do
  352. get 'archive', constraints: { format: Gitlab::Regex.archive_formats_regex }
  353. end
  354. end
  355. resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
  356. member do
  357. get :test
  358. end
  359. end
  360. resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do
  361. member do
  362. put :enable
  363. put :disable
  364. end
  365. end
  366. resource :fork, only: [:new, :create]
  367. resource :import, only: [:new, :create, :show]
  368. resources :refs, only: [] do
  369. collection do
  370. get 'switch'
  371. end
  372. member do
  373. # tree viewer logs
  374. get 'logs_tree', constraints: { id: Gitlab::Regex.git_reference_regex }
  375. get 'logs_tree/*path' => 'refs#logs_tree', as: :logs_file, constraints: {
  376. id: Gitlab::Regex.git_reference_regex,
  377. path: /.*/
  378. }
  379. end
  380. end
  381. resources :merge_requests, constraints: { id: /\d+/ }, except: [:destroy] do
  382. member do
  383. get :diffs
  384. get :commits
  385. post :automerge
  386. get :automerge_check
  387. get :ci_status
  388. post :toggle_subscription
  389. end
  390. collection do
  391. get :branch_from
  392. get :branch_to
  393. get :update_branches
  394. end
  395. end
  396. resources :branches, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
  397. resources :tags, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
  398. resources :protected_branches, only: [:index, :create, :update, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
  399. resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
  400. member do
  401. get :test
  402. end
  403. end
  404. resources :milestones, constraints: { id: /\d+/ } do
  405. member do
  406. put :sort_issues
  407. put :sort_merge_requests
  408. end
  409. end
  410. resources :labels, constraints: { id: /\d+/ } do
  411. collection do
  412. post :generate
  413. end
  414. end
  415. resources :issues, constraints: { id: /\d+/ }, except: [:destroy] do
  416. member do
  417. post :toggle_subscription
  418. end
  419. collection do
  420. post :bulk_update
  421. end
  422. end
  423. resources :project_members, except: [:new, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ } do
  424. collection do
  425. delete :leave
  426. # Used for import team
  427. # from another project
  428. get :import
  429. post :apply_import
  430. end
  431. member do
  432. post :resend_invite
  433. end
  434. end
  435. resources :notes, only: [:index, :create, :destroy, :update], constraints: { id: /\d+/ } do
  436. member do
  437. delete :delete_attachment
  438. end
  439. end
  440. resources :uploads, only: [:create] do
  441. collection do
  442. get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
  443. end
  444. end
  445. end
  446. end
  447. end
  448. get ':id' => 'namespaces#show', constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }
  449. end