diff --git a/services/web/.vscode/settings.json b/services/web/.vscode/settings.json index 96a1261905..133731e8b3 100644 --- a/services/web/.vscode/settings.json +++ b/services/web/.vscode/settings.json @@ -2,5 +2,6 @@ "files.exclude": { "node_modules": true, "data": true - } + }, + "cSpell.words": ["docstore", "Tpds"] } diff --git a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js index 20f8ff32ec..aceb641995 100644 --- a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js +++ b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js @@ -235,16 +235,11 @@ async function enqueue(group, method, job) { async function getProjectUsersIds(projectId) { // get list of all user ids with access to project. project owner // will always be the first entry in the list. - const [ownerUserId, ...invitedUserIds] = - await CollaboratorsGetter.getInvitedMemberIds(projectId) - // if there are no invited users, always return the owner - if (!invitedUserIds.length) { - return [ownerUserId] - } + const userIds = await CollaboratorsGetter.getInvitedMemberIds(projectId) // filter invited users to only return those with dropbox linked const dropboxUsers = await UserGetter.getUsers( { - _id: { $in: invitedUserIds.map(id => ObjectId(id)) }, + _id: { $in: userIds.map(id => ObjectId(id)) }, 'dropbox.access_token.uid': { $ne: null }, }, { @@ -252,7 +247,7 @@ async function getProjectUsersIds(projectId) { } ) const dropboxUserIds = dropboxUsers.map(user => user._id) - return [ownerUserId, ...dropboxUserIds] + return dropboxUserIds } async function moveEntity(params) { diff --git a/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js b/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js index 279af24a6b..b4886d1c4b 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js +++ b/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js @@ -25,10 +25,10 @@ describe('TpdsUpdateSender', function () { this.fakeUser = { _id: '12390i', } - const memberIds = [userId, collaberatorRef, readOnlyRef] + this.memberIds = [userId, collaberatorRef, readOnlyRef] this.CollaboratorsGetter = { promises: { - getInvitedMemberIds: sinon.stub().resolves(memberIds), + getInvitedMemberIds: sinon.stub().resolves(this.memberIds), }, } this.docstoreUrl = 'docstore.sharelatex.env' @@ -49,11 +49,19 @@ describe('TpdsUpdateSender', function () { }, }, } - const getUsers = sinon.stub().resolves( - memberIds.slice(1).map(userId => { - return { _id: userId } + const getUsers = sinon.stub() + getUsers + .withArgs({ + _id: { + $in: this.memberIds, + }, + 'dropbox.access_token.uid': { $ne: null }, }) - ) + .resolves( + this.memberIds.map(userId => { + return { _id: userId } + }) + ) this.UserGetter = { promises: { getUsers }, } @@ -144,16 +152,6 @@ describe('TpdsUpdateSender', function () { group2.should.equal(readOnlyRef.toString()) job2.headers.sl_all_user_ids.should.equal(JSON.stringify([readOnlyRef])) job2.headers.sl_project_owner_user_id.should.equal(userId.toString()) - - this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( - { - _id: { - $in: [collaberatorRef, readOnlyRef], - }, - 'dropbox.access_token.uid': { $ne: null }, - }, - { _id: 1 } - ) }) it('post doc with stream origin of docstore', async function () { @@ -200,16 +198,6 @@ describe('TpdsUpdateSender', function () { ) group2.should.equal(readOnlyRef.toString()) job2.headers.sl_all_user_ids.should.equal(JSON.stringify([readOnlyRef])) - - this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( - { - _id: { - $in: [collaberatorRef, readOnlyRef], - }, - 'dropbox.access_token.uid': { $ne: null }, - }, - { _id: 1 } - ) }) it('deleting entity', async function () { @@ -252,16 +240,6 @@ describe('TpdsUpdateSender', function () { ) group2.should.equal(readOnlyRef.toString()) job2.headers.sl_all_user_ids.should.equal(JSON.stringify([readOnlyRef])) - - this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( - { - _id: { - $in: [collaberatorRef, readOnlyRef], - }, - 'dropbox.access_token.uid': { $ne: null }, - }, - { _id: 1 } - ) }) it('moving entity', async function () { @@ -304,16 +282,6 @@ describe('TpdsUpdateSender', function () { ) group2.should.equal(readOnlyRef.toString()) job2.headers.sl_all_user_ids.should.equal(JSON.stringify([readOnlyRef])) - - this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( - { - _id: { - $in: [collaberatorRef, readOnlyRef], - }, - 'dropbox.access_token.uid': { $ne: null }, - }, - { _id: 1 } - ) }) it('should be able to rename a project using the move entity func', async function () { @@ -355,16 +323,6 @@ describe('TpdsUpdateSender', function () { ) group2.should.equal(readOnlyRef.toString()) job2.headers.sl_all_user_ids.should.equal(JSON.stringify([readOnlyRef])) - - this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( - { - _id: { - $in: [collaberatorRef, readOnlyRef], - }, - 'dropbox.access_token.uid': { $ne: null }, - }, - { _id: 1 } - ) }) it('pollDropboxForUser', async function () { @@ -398,4 +356,30 @@ describe('TpdsUpdateSender', function () { ) }) }) + + describe('user not linked to dropbox', function () { + beforeEach(function () { + this.UserGetter.promises.getUsers + .withArgs({ + _id: { + $in: this.memberIds, + }, + 'dropbox.access_token.uid': { $ne: null }, + }) + .resolves([]) + }) + }) + + it('does not make request to tpds', async function () { + const fileId = '4545345' + const path = '/some/path/here.jpg' + + await this.TpdsUpdateSender.promises.addFile({ + projectId, + fileId, + path, + projectName, + }) + this.fetch.should.not.have.been.called + }) })