mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #10995 from overleaf/lg-update-tpds-dropbox-only
Only send updates to tpds if project is linked to dropbox GitOrigin-RevId: 52d8bbfc229b74346dd440f283925a8d6eb6198a
This commit is contained in:
parent
e8495b1236
commit
c6f9da69da
3 changed files with 45 additions and 65 deletions
3
services/web/.vscode/settings.json
vendored
3
services/web/.vscode/settings.json
vendored
|
@ -2,5 +2,6 @@
|
|||
"files.exclude": {
|
||||
"node_modules": true,
|
||||
"data": true
|
||||
}
|
||||
},
|
||||
"cSpell.words": ["docstore", "Tpds"]
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue