1-anon-upload.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --- UploadsRouter.js
  2. +++ UploadsRouter.js
  3. @@ -1,13 +1,3 @@
  4. -/* eslint-disable
  5. - no-unused-vars,
  6. -*/
  7. -// TODO: This file was created by bulk-decaffeinate.
  8. -// Fix any style issues and re-enable lint.
  9. -/*
  10. - * decaffeinate suggestions:
  11. - * DS102: Remove unnecessary code created because of implicit returns
  12. - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. - */
  14. const AuthorizationMiddleware = require('../Authorization/AuthorizationMiddleware')
  15. const AuthenticationController = require('../Authentication/AuthenticationController')
  16. const ProjectUploadController = require('./ProjectUploadController')
  17. @@ -28,18 +18,30 @@ module.exports = {
  18. ProjectUploadController.uploadProject
  19. )
  20. - return webRouter.post(
  21. - '/Project/:Project_id/upload',
  22. - RateLimiterMiddleware.rateLimit({
  23. - endpointName: 'file-upload',
  24. - params: ['Project_id'],
  25. - maxRequests: 200,
  26. - timeInterval: 60 * 30
  27. - }),
  28. - AuthenticationController.requireLogin(),
  29. - AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  30. - ProjectUploadController.multerMiddleware,
  31. - ProjectUploadController.uploadFile
  32. - )
  33. + const fileUploadEndpoint = '/Project/:Project_id/upload'
  34. + const fileUploadRateLimit = RateLimiterMiddleware.rateLimit({
  35. + endpointName: 'file-upload',
  36. + params: ['Project_id'],
  37. + maxRequests: 200,
  38. + timeInterval: 60 * 30
  39. + })
  40. + if (Settings.allowAnonymousReadAndWriteSharing) {
  41. + webRouter.post(
  42. + fileUploadEndpoint,
  43. + fileUploadRateLimit,
  44. + AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  45. + ProjectUploadController.multerMiddleware,
  46. + ProjectUploadController.uploadFile
  47. + )
  48. + } else {
  49. + webRouter.post(
  50. + fileUploadEndpoint,
  51. + fileUploadRateLimit,
  52. + AuthenticationController.requireLogin(),
  53. + AuthorizationMiddleware.ensureUserCanWriteProjectContent,
  54. + ProjectUploadController.multerMiddleware,
  55. + ProjectUploadController.uploadFile
  56. + )
  57. + }
  58. }
  59. }