Przeglądaj źródła

Merge pull request #1916 from overleaf/ta-join-project-404

Return 404 on JoinProject When Project Is Not Found

GitOrigin-RevId: cd87ce6e2564fd4a80faa66e8b22edec7b0c783c
Brian Gough 7 lat temu
rodzic
commit
cf940cc835

+ 2 - 1
services/web/app/src/Features/Editor/EditorHttpController.js

@@ -28,6 +28,7 @@ const CollaboratorsInviteHandler = require('../Collaborators/CollaboratorsInvite
 const PrivilegeLevels = require('../Authorization/PrivilegeLevels')
 const TokenAccessHandler = require('../TokenAccess/TokenAccessHandler')
 const AuthenticationController = require('../Authentication/AuthenticationController')
+const Errors = require('../Errors/Errors')
 
 module.exports = EditorHttpController = {
   joinProject(req, res, next) {
@@ -73,7 +74,7 @@ module.exports = EditorHttpController = {
         return callback(error)
       }
       if (project == null) {
-        return callback(new Error('not found'))
+        return callback(new Errors.NotFoundError('project not found'))
       }
       return CollaboratorsHandler.getInvitedMembersWithPrivilegeLevels(
         project_id,

+ 21 - 1
services/web/test/unit/src/Editor/EditorHttpControllerTests.js

@@ -16,6 +16,7 @@ const modulePath = require('path').join(
   __dirname,
   '../../../../app/src/Features/Editor/EditorHttpController'
 )
+const Errors = require('../../../../app/src/Features/Errors/Errors')
 
 describe('EditorHttpController', function() {
   beforeEach(function() {
@@ -37,7 +38,8 @@ describe('EditorHttpController', function() {
         '../Collaborators/CollaboratorsHandler': (this.CollaboratorsHandler = {}),
         '../Collaborators/CollaboratorsInviteHandler': (this.CollaboratorsInviteHandler = {}),
         '../TokenAccess/TokenAccessHandler': (this.TokenAccessHandler = {}),
-        '../Authentication/AuthenticationController': (this.AuthenticationController = {})
+        '../Authentication/AuthenticationController': (this.AuthenticationController = {}),
+        '../Errors/Errors': Errors
       }
     })
 
@@ -186,6 +188,24 @@ describe('EditorHttpController', function() {
         .callsArgWith(2, null, this.user))
     })
 
+    describe('when project is not found', function() {
+      beforeEach(function() {
+        this.ProjectGetter.getProjectWithoutDocLines.yields(null, null)
+        return this.EditorHttpController._buildJoinProjectView(
+          this.req,
+          this.project_id,
+          this.user_id,
+          this.callback
+        )
+      })
+
+      it('should handle return not found error', function() {
+        let args = this.callback.lastCall.args
+        args.length.should.equal(1)
+        args[0].should.be.instanceof(Errors.NotFoundError)
+      })
+    })
+
     describe('when authorized', function() {
       beforeEach(function() {
         this.AuthorizationManager.getPrivilegeLevelForProject = sinon