Merge pull request #905 from sharelatex/as-project-intelligent-redirect

Intelligently redirect to v1 if no v2 project found
This commit is contained in:
Alasdair Smith
2018-09-17 09:40:52 +01:00
committed by GitHub
5 changed files with 77 additions and 8 deletions
@@ -415,3 +415,13 @@ describe 'TokenAccess', ->
try_content_access(@other2, @project_id, (response, body) =>
expect(body.privilegeLevel).to.equal false
, done)
describe 'unimported v1 project', ->
it 'should redirect to v1', (done) ->
unimportedV1Token = '123abc'
try_read_and_write_token_access(@owner, unimportedV1Token, (response, body) =>
expect(response.statusCode).to.equal 302
expect(response.headers.location).to.equal(
'http://overleaf.test:5000/123abc'
)
, done)
@@ -105,3 +105,6 @@ module.exports =
path: (params) -> "/universities/list/#{params.id}"
'/institutions/domains': { baseUrl: v1Api.url, path: '/university/domains' }
'/proxy/missing/baseUrl': path: '/foo/bar'
overleaf:
host: "http://overleaf.test:5000"
@@ -30,6 +30,10 @@ describe "TokenAccessController", ->
'../Authentication/AuthenticationController': @AuthenticationController = {}
'./TokenAccessHandler': @TokenAccessHandler = {}
'logger-sharelatex': {log: sinon.stub(), err: sinon.stub()}
'settings-sharelatex': {
overleaf:
host: 'http://overleaf.test:5000'
}
@AuthenticationController.getLoggedInUserId = sinon.stub().returns(@userId.toString())
@@ -231,6 +235,27 @@ describe "TokenAccessController", ->
@AuthenticationController.getLoggedInUserId =
sinon.stub().returns(@userId.toString())
describe 'when project does not exist', ->
beforeEach ->
@req = new MockRequest()
@req.url = '/123abc'
@res = new MockResponse()
@res.redirect = sinon.stub()
@next = sinon.stub()
@req.params['read_and_write_token'] = '123abc'
@TokenAccessHandler.findProjectWithReadAndWriteToken = sinon.stub()
.callsArgWith(1, null, null)
@TokenAccessHandler.findProjectWithHigherAccess =
sinon.stub()
.callsArgWith(2, null, @project, false)
@TokenAccessController.readAndWriteToken @req, @res, @next
it 'should redirect to v1', (done) ->
expect(@res.redirect.callCount).to.equal 1
expect(@res.redirect.firstCall.args[0])
.to.equal 'http://overleaf.test:5000/123abc'
done()
describe 'when token access is off, but user has higher access anyway', ->
beforeEach ->
@req = new MockRequest()
@@ -242,7 +267,7 @@ describe "TokenAccessController", ->
.callsArgWith(1, null, null)
@TokenAccessHandler.findProjectWithHigherAccess =
sinon.stub()
.callsArgWith(2, null, @project)
.callsArgWith(2, null, @project, true)
@TokenAccessHandler.addReadAndWriteUserToProject = sinon.stub()
.callsArgWith(2, null)
@ProjectController.loadEditor = sinon.stub()
@@ -291,7 +316,7 @@ describe "TokenAccessController", ->
.callsArgWith(1, null, null)
@TokenAccessHandler.findProjectWithHigherAccess =
sinon.stub()
.callsArgWith(2, null, null)
.callsArgWith(2, null, null, true)
@TokenAccessHandler.addReadAndWriteUserToProject = sinon.stub()
.callsArgWith(2, null)
@ProjectController.loadEditor = sinon.stub()
@@ -479,6 +504,27 @@ describe "TokenAccessController", ->
describe 'when findProject does not find a project', ->
beforeEach ->
describe 'when project does not exist', ->
beforeEach ->
@req = new MockRequest()
@req.url = '/123abc'
@res = new MockResponse()
@res.redirect = sinon.stub()
@next = sinon.stub()
@req.params['read_and_write_token'] = '123abc'
@TokenAccessHandler.findProjectWithReadOnlyToken = sinon.stub()
.callsArgWith(1, null, null)
@TokenAccessHandler.findProjectWithHigherAccess =
sinon.stub()
.callsArgWith(2, null, @project, false)
@TokenAccessController.readOnlyToken @req, @res, @next
it 'should return a ProjectNotTokenAccessError', (done) ->
expect(@res.redirect.callCount).to.equal 1
expect(@res.redirect.firstCall.args[0])
.to.equal 'http://overleaf.test:5000/123abc'
done()
describe 'when token access is off, but user has higher access anyway', ->
beforeEach ->
@req = new MockRequest()
@@ -490,7 +536,7 @@ describe "TokenAccessController", ->
.callsArgWith(1, null, null)
@TokenAccessHandler.findProjectWithHigherAccess =
sinon.stub()
.callsArgWith(2, null, @project)
.callsArgWith(2, null, @project, true)
@TokenAccessHandler.addReadAndWriteUserToProject = sinon.stub()
.callsArgWith(2, null)
@ProjectController.loadEditor = sinon.stub()
@@ -538,7 +584,7 @@ describe "TokenAccessController", ->
.callsArgWith(1, null, null)
@TokenAccessHandler.findProjectWithHigherAccess =
sinon.stub()
.callsArgWith(2, null, null)
.callsArgWith(2, null, null, true)
@TokenAccessHandler.addReadOnlyUserToProject = sinon.stub()
.callsArgWith(2, null)
@ProjectController.loadEditor = sinon.stub()