From d6350c963e35ffbc1c3d3735ce566edc3ef9102d Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 24 Sep 2018 18:31:07 +0100 Subject: [PATCH] Remove projectExists flag from higher access check Now that find project by read and read/write token methods check whether the project exists, it is not neccessary to check whether the project exists in the higher access check. Therefore it has been removed --- .../TokenAccess/TokenAccessController.coffee | 7 +------ .../TokenAccess/TokenAccessHandler.coffee | 15 +++++++-------- .../TokenAccess/TokenAccessControllerTests.coffee | 10 +++++----- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/services/web/app/coffee/Features/TokenAccess/TokenAccessController.coffee b/services/web/app/coffee/Features/TokenAccess/TokenAccessController.coffee index 6c169b0bac..d5d704703d 100644 --- a/services/web/app/coffee/Features/TokenAccess/TokenAccessController.coffee +++ b/services/web/app/coffee/Features/TokenAccess/TokenAccessController.coffee @@ -12,16 +12,11 @@ module.exports = TokenAccessController = return ProjectController.loadEditor(req, res, next) _tryHigherAccess: (token, userId, req, res, next) -> - TokenAccessHandler.findProjectWithHigherAccess token, userId, (err, project, projectExists) -> + TokenAccessHandler.findProjectWithHigherAccess token, userId, (err, project) -> if err? logger.err {err, token, userId}, "[TokenAccess] error finding project with higher access" return next(err) - if !projectExists and settings.overleaf - logger.log {token, userId}, - "[TokenAccess] no project found for this token" - # Project does not exist, but may be unimported - try it on v1 - return res.redirect(settings.overleaf.host + req.url) if !project? logger.log {token, userId}, "[TokenAccess] no project with higher access found for this user and token" diff --git a/services/web/app/coffee/Features/TokenAccess/TokenAccessHandler.coffee b/services/web/app/coffee/Features/TokenAccess/TokenAccessHandler.coffee index 41b7ed0ead..d2dedca76e 100644 --- a/services/web/app/coffee/Features/TokenAccess/TokenAccessHandler.coffee +++ b/services/web/app/coffee/Features/TokenAccess/TokenAccessHandler.coffee @@ -17,9 +17,9 @@ module.exports = TokenAccessHandler = if err? return callback(err) if !project? - return callback(null, null, false) + return callback(null, null, false) # Project doesn't exist, so we handle differently if project.publicAccesLevel != PublicAccessLevels.TOKEN_BASED - return callback(null, null, true) + return callback(null, null, true) # Project does exist, but it isn't token based return callback(null, project, true) findProjectWithReadAndWriteToken: (token, callback=(err, project, projectExists)->) -> @@ -29,12 +29,12 @@ module.exports = TokenAccessHandler = if err? return callback(err) if !project? - return callback(null, null, false) + return callback(null, null, false) # Project doesn't exist, so we handle differently if project.publicAccesLevel != PublicAccessLevels.TOKEN_BASED - return callback(null, null, true) + return callback(null, null, true) # Project does exist, but it isn't token based return callback(null, project, true) - findProjectWithHigherAccess: (token, userId, callback=(err, project, projectExists)->) -> + findProjectWithHigherAccess: (token, userId, callback=(err, project)->) -> Project.findOne { $or: [ {'tokens.readAndWrite': token}, @@ -44,15 +44,14 @@ module.exports = TokenAccessHandler = if err? return callback(err) if !project? - return callback(null, null, false) # Project doesn't exist, so we handle differently + return callback(null, null) projectId = project._id CollaboratorsHandler.isUserInvitedMemberOfProject userId, projectId, (err, isMember) -> if err? return callback(err) callback( null, - if isMember == true then project else null, - true # Project does exist, but user doesn't have access + if isMember == true then project else null ) addReadOnlyUserToProject: (userId, projectId, callback=(err)->) -> diff --git a/services/web/test/unit/coffee/TokenAccess/TokenAccessControllerTests.coffee b/services/web/test/unit/coffee/TokenAccess/TokenAccessControllerTests.coffee index 6a5f79151f..97312ab415 100644 --- a/services/web/test/unit/coffee/TokenAccess/TokenAccessControllerTests.coffee +++ b/services/web/test/unit/coffee/TokenAccess/TokenAccessControllerTests.coffee @@ -247,7 +247,7 @@ describe "TokenAccessController", -> .callsArgWith(1, null, null, false) @TokenAccessHandler.findProjectWithHigherAccess = sinon.stub() - .callsArgWith(2, null, @project, false) + .callsArgWith(2, null, @project) @TokenAccessController.readAndWriteToken @req, @res, @next it 'should redirect to v1', (done) -> @@ -269,7 +269,7 @@ describe "TokenAccessController", -> .callsArgWith(1, null, null, true) @TokenAccessHandler.findProjectWithHigherAccess = sinon.stub() - .callsArgWith(2, null, @project, true) + .callsArgWith(2, null, @project) @TokenAccessHandler.addReadAndWriteUserToProject = sinon.stub() .callsArgWith(2, null) @ProjectController.loadEditor = sinon.stub() @@ -318,7 +318,7 @@ describe "TokenAccessController", -> .callsArgWith(1, null, null, true) @TokenAccessHandler.findProjectWithHigherAccess = sinon.stub() - .callsArgWith(2, null, null, true) + .callsArgWith(2, null, null) @TokenAccessHandler.addReadAndWriteUserToProject = sinon.stub() .callsArgWith(2, null) @ProjectController.loadEditor = sinon.stub() @@ -514,7 +514,7 @@ describe "TokenAccessController", -> .callsArgWith(1, null, null, true) @TokenAccessHandler.findProjectWithHigherAccess = sinon.stub() - .callsArgWith(2, null, @project, true) + .callsArgWith(2, null, @project) @TokenAccessHandler.addReadAndWriteUserToProject = sinon.stub() .callsArgWith(2, null) @ProjectController.loadEditor = sinon.stub() @@ -562,7 +562,7 @@ describe "TokenAccessController", -> .callsArgWith(1, null, null, true) @TokenAccessHandler.findProjectWithHigherAccess = sinon.stub() - .callsArgWith(2, null, null, true) + .callsArgWith(2, null, null) @TokenAccessHandler.addReadOnlyUserToProject = sinon.stub() .callsArgWith(2, null) @ProjectController.loadEditor = sinon.stub()