Merge pull request #13485 from overleaf/msm-share-modal-fetch-tokens
[web] Fetch share tokens instead of sending via websocket GitOrigin-RevId: f97bb91ca3ceb410fe860bf1c7802d8157d9f8b4
This commit is contained in:
@@ -50,6 +50,9 @@ describe('CollaboratorsController', function () {
|
||||
transferOwnership: sinon.stub().resolves(),
|
||||
},
|
||||
}
|
||||
this.TokenAccessHandler = {
|
||||
getRequestToken: sinon.stub().returns('access-token'),
|
||||
}
|
||||
|
||||
this.CollaboratorsController = SandboxedModule.require(MODULE_PATH, {
|
||||
requires: {
|
||||
@@ -61,6 +64,7 @@ describe('CollaboratorsController', function () {
|
||||
'../../Features/Errors/HttpErrorHandler': this.HttpErrorHandler,
|
||||
'../Tags/TagsHandler': this.TagsHandler,
|
||||
'../Authentication/SessionManager': this.SessionManager,
|
||||
'../TokenAccess/TokenAccessHandler': this.TokenAccessHandler,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -30,6 +30,11 @@ describe('CollaboratorsGetter', function () {
|
||||
tokenAccessReadAndWrite_refs: [this.readWriteTokenRef],
|
||||
tokenAccessReadOnly_refs: [this.readOnlyTokenRef],
|
||||
publicAccesLevel: 'tokenBased',
|
||||
tokens: {
|
||||
readOnly: 'ro',
|
||||
readAndWrite: 'rw',
|
||||
readAndWritePrefix: 'pre',
|
||||
},
|
||||
}
|
||||
|
||||
this.UserGetter = {
|
||||
@@ -359,4 +364,60 @@ describe('CollaboratorsGetter', function () {
|
||||
expect(isMember).to.be.false
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPublicShareTokens', function () {
|
||||
const userMock = ObjectId()
|
||||
|
||||
it('should return null when the project is not found', async function () {
|
||||
this.ProjectMock.expects('findOne').chain('exec').resolves(undefined)
|
||||
const tokens =
|
||||
await this.CollaboratorsGetter.promises.getPublicShareTokens(
|
||||
userMock,
|
||||
this.project._id
|
||||
)
|
||||
expect(tokens).to.be.null
|
||||
})
|
||||
|
||||
it('should return an empty object when the user is not owner or read-only collaborator', async function () {
|
||||
this.ProjectMock.expects('findOne').chain('exec').resolves(this.project)
|
||||
const tokens =
|
||||
await this.CollaboratorsGetter.promises.getPublicShareTokens(
|
||||
userMock,
|
||||
this.project._id
|
||||
)
|
||||
expect(tokens).to.deep.equal({})
|
||||
})
|
||||
|
||||
describe('when the user is a read-only token collaborator', function () {
|
||||
it('should return the read-only token', async function () {
|
||||
this.ProjectMock.expects('findOne')
|
||||
.chain('exec')
|
||||
.resolves({ hasTokenReadOnlyAccess: true, ...this.project })
|
||||
|
||||
const tokens =
|
||||
await this.CollaboratorsGetter.promises.getPublicShareTokens(
|
||||
userMock,
|
||||
this.project._id
|
||||
)
|
||||
expect(tokens).to.deep.equal({ readOnly: tokens.readOnly })
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the user is the owner of the project', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectMock.expects('findOne')
|
||||
.chain('exec')
|
||||
.resolves({ isOwner: true, ...this.project })
|
||||
})
|
||||
|
||||
it('should return all the tokens', async function () {
|
||||
const tokens =
|
||||
await this.CollaboratorsGetter.promises.getPublicShareTokens(
|
||||
userMock,
|
||||
this.project._id
|
||||
)
|
||||
expect(tokens).to.deep.equal(tokens)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -873,7 +873,7 @@ describe('EditorController', function () {
|
||||
this.newAccessLevel = 'private'
|
||||
this.ProjectDetailsHandler.ensureTokensArePresent = sinon
|
||||
.stub()
|
||||
.yields(null, this.tokens)
|
||||
.yields()
|
||||
return this.EditorController.setPublicAccessLevel(
|
||||
this.project_id,
|
||||
this.newAccessLevel,
|
||||
@@ -898,14 +898,6 @@ describe('EditorController', function () {
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not broadcast a token change', function () {
|
||||
return this.EditorRealTimeController.emitToRoom
|
||||
.calledWith(this.project_id, 'project:tokens:changed', {
|
||||
tokens: this.tokens,
|
||||
})
|
||||
.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when setting to tokenBased', function () {
|
||||
@@ -914,7 +906,7 @@ describe('EditorController', function () {
|
||||
this.tokens = { readOnly: 'aaa', readAndWrite: '42bbb' }
|
||||
this.ProjectDetailsHandler.ensureTokensArePresent = sinon
|
||||
.stub()
|
||||
.yields(null, this.tokens)
|
||||
.yields()
|
||||
return this.EditorController.setPublicAccessLevel(
|
||||
this.project_id,
|
||||
this.newAccessLevel,
|
||||
@@ -939,14 +931,6 @@ describe('EditorController', function () {
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should broadcast the token change too', function () {
|
||||
return this.EditorRealTimeController.emitToRoom
|
||||
.calledWith(this.project_id, 'project:tokens:changed', {
|
||||
tokens: this.tokens,
|
||||
})
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -113,7 +113,6 @@ describe('EditorHttpController', function () {
|
||||
this.Metrics = { inc: sinon.stub() }
|
||||
this.TokenAccessHandler = {
|
||||
getRequestToken: sinon.stub().returns(this.token),
|
||||
protectTokens: sinon.stub(),
|
||||
}
|
||||
this.SessionManager = {
|
||||
getLoggedInUserId: sinon.stub().returns(this.user._id),
|
||||
|
||||
@@ -90,7 +90,6 @@ describe('ProjectController', function () {
|
||||
}
|
||||
this.TokenAccessHandler = {
|
||||
getRequestToken: sinon.stub().returns(this.token),
|
||||
protectTokens: sinon.stub(),
|
||||
}
|
||||
this.CollaboratorsGetter = {
|
||||
userIsTokenMember: sinon.stub().callsArgWith(2, null, false),
|
||||
|
||||
@@ -511,13 +511,6 @@ describe('ProjectDetailsHandler', function () {
|
||||
await this.handler.promises.ensureTokensArePresent(this.project._id)
|
||||
expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should produce the tokens without error', async function () {
|
||||
const tokens = await this.handler.promises.ensureTokensArePresent(
|
||||
this.project._id
|
||||
)
|
||||
expect(tokens).to.deep.equal(this.project.tokens)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when tokens are missing', function () {
|
||||
@@ -566,17 +559,6 @@ describe('ProjectDetailsHandler', function () {
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should produce the tokens without error', async function () {
|
||||
const tokens = await this.handler.promises.ensureTokensArePresent(
|
||||
this.project._id
|
||||
)
|
||||
expect(tokens).to.deep.equal({
|
||||
readOnly: this.readOnlyToken,
|
||||
readAndWrite: this.readAndWriteToken,
|
||||
readAndWritePrefix: this.readAndWriteTokenPrefix,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -513,37 +513,6 @@ describe('TokenAccessHandler', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('protectTokens', function () {
|
||||
beforeEach(function () {
|
||||
return (this.project = {
|
||||
tokens: {
|
||||
readAndWrite: 'rw',
|
||||
readOnly: 'ro',
|
||||
readAndWritePrefix: 'pre',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('should hide write token from read-only user', function () {
|
||||
this.TokenAccessHandler.protectTokens(this.project, 'readOnly')
|
||||
expect(this.project.tokens.readAndWrite).to.equal('')
|
||||
expect(this.project.tokens.readAndWritePrefix).to.equal('')
|
||||
return expect(this.project.tokens.readOnly).to.equal('ro')
|
||||
})
|
||||
|
||||
it('should hide read token from read-write user', function () {
|
||||
this.TokenAccessHandler.protectTokens(this.project, 'readAndWrite')
|
||||
expect(this.project.tokens.readAndWrite).to.equal('rw')
|
||||
return expect(this.project.tokens.readOnly).to.equal('')
|
||||
})
|
||||
|
||||
it('should leave tokens in place for owner', function () {
|
||||
this.TokenAccessHandler.protectTokens(this.project, 'owner')
|
||||
expect(this.project.tokens.readAndWrite).to.equal('rw')
|
||||
return expect(this.project.tokens.readOnly).to.equal('ro')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getDocPublishedInfo', function () {
|
||||
beforeEach(function () {
|
||||
return (this.callback = sinon.stub())
|
||||
|
||||
Reference in New Issue
Block a user