EditorRouter.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* eslint-disable
  2. max-len,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  10. */
  11. const EditorHttpController = require('./EditorHttpController')
  12. const AuthenticationController = require('../Authentication/AuthenticationController')
  13. const AuthorizationMiddleware = require('../Authorization/AuthorizationMiddleware')
  14. const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware')
  15. module.exports = {
  16. apply(webRouter, apiRouter) {
  17. webRouter.post(
  18. '/project/:Project_id/doc',
  19. AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  20. RateLimiterMiddleware.rateLimit({
  21. endpointName: 'add-doc-to-project',
  22. params: ['Project_id'],
  23. maxRequests: 30,
  24. timeInterval: 60
  25. }),
  26. EditorHttpController.addDoc
  27. )
  28. webRouter.post(
  29. '/project/:Project_id/folder',
  30. AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  31. RateLimiterMiddleware.rateLimit({
  32. endpointName: 'add-folder-to-project',
  33. params: ['Project_id'],
  34. maxRequests: 60,
  35. timeInterval: 60
  36. }),
  37. EditorHttpController.addFolder
  38. )
  39. webRouter.post(
  40. '/project/:Project_id/:entity_type/:entity_id/rename',
  41. AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  42. EditorHttpController.renameEntity
  43. )
  44. webRouter.post(
  45. '/project/:Project_id/:entity_type/:entity_id/move',
  46. AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  47. EditorHttpController.moveEntity
  48. )
  49. webRouter.delete(
  50. '/project/:Project_id/file/:entity_id',
  51. AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  52. EditorHttpController.deleteFile
  53. )
  54. webRouter.delete(
  55. '/project/:Project_id/doc/:entity_id',
  56. AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  57. EditorHttpController.deleteDoc
  58. )
  59. webRouter.delete(
  60. '/project/:Project_id/folder/:entity_id',
  61. AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  62. EditorHttpController.deleteFolder
  63. )
  64. // Called by the real-time API to load up the current project state.
  65. // This is a post request because it's more than just a getting of data. We take actions
  66. // whenever a user joins a project, like updating the deleted status.
  67. return apiRouter.post(
  68. '/project/:Project_id/join',
  69. AuthenticationController.httpAuth,
  70. RateLimiterMiddleware.rateLimit({
  71. endpointName: 'join-project',
  72. params: ['Project_id'],
  73. maxRequests: 30,
  74. timeInterval: 60
  75. }),
  76. EditorHttpController.joinProject
  77. )
  78. }
  79. }