diff --git a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js index 78998e3cee..b3d352225b 100644 --- a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js +++ b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js @@ -103,7 +103,7 @@ async function enqueue(group, method, job) { return } try { - const response = request({ + const response = await request({ uri: `${tpdsWorkerUrl}/enqueue/web_to_tpds_http_requests`, json: { group, job, method }, method: 'post', @@ -123,16 +123,18 @@ async function getProjectUsersIds(projectId) { projectId ) // filter list to only return users with dropbox linked - const users = await UserGetter.getUsers( + // skip the first user id, which is always returned + const dropboxUsers = await UserGetter.getUsers( { - _id: { $in: projectUserIds }, + _id: { $in: projectUserIds.slice(1) }, 'dropbox.access_token.uid': { $ne: null } }, { _id: 1 } ) - return users.map(user => user._id) + const dropboxUserIds = dropboxUsers.map(user => user._id) + return [projectUserIds[0], ...dropboxUserIds] } async function moveEntity(options) { diff --git a/services/web/app/src/Features/User/UserGetter.js b/services/web/app/src/Features/User/UserGetter.js index 9f5e5fe401..e9ef82972f 100644 --- a/services/web/app/src/Features/User/UserGetter.js +++ b/services/web/app/src/Features/User/UserGetter.js @@ -15,10 +15,12 @@ const UserGetter = { callback = projection projection = {} } - normalizeQuery(query, (err, query) => { - if (err) return callback(err) + try { + query = normalizeQuery(query) db.users.findOne(query, projection, callback) - }) + } catch (err) { + callback(err) + } }, getUserEmail(userId, callback) { @@ -129,10 +131,12 @@ const UserGetter = { }, getUsers(query, projection, callback) { - normalizeQuery(query, (err, query) => { - if (err) return callback(err) + try { + query = normalizeQuery(query) db.users.find(query, projection, callback) - }) + } catch (err) { + callback(err) + } }, // check for duplicate email address. This is also enforced at the DB level @@ -146,23 +150,19 @@ const UserGetter = { } } -function normalizeQuery(query, callback) { +function normalizeQuery(query) { if (!query) { - return callback(new Error('no query provided')) + throw new Error('no query provided') } - try { - if (typeof query === 'string') { - callback(null, { _id: ObjectId(query) }) - } else if (query instanceof ObjectId) { - callback(null, { _id: query }) - } else if (Array.isArray(query)) { - const userIds = query.map(u => ObjectId(u.toString())) - callback(null, { _id: { $in: userIds } }) - } else { - callback(null, query) - } - } catch (err) { - callback(err, null) + if (typeof query === 'string') { + return { _id: ObjectId(query) } + } else if (query instanceof ObjectId) { + return { _id: query } + } else if (Array.isArray(query)) { + const userIds = query.map(u => ObjectId(u.toString())) + return { _id: { $in: userIds } } + } else { + return query } } diff --git a/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js b/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js index e157f29307..4ea30c2a7d 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js +++ b/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js @@ -51,7 +51,7 @@ describe('TpdsUpdateSender', function() { } } const getUsers = sinon.stub().resolves( - memberIds.map(userId => { + memberIds.slice(1).map(userId => { return { _id: userId } }) ) @@ -145,11 +145,7 @@ describe('TpdsUpdateSender', function() { this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( { _id: { - $in: [ - 'user_id_here', - 'collaberator_ref_1_here', - 'read_only_ref_1_id_here' - ] + $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here'] }, 'dropbox.access_token.uid': { $ne: null } }, @@ -203,11 +199,7 @@ describe('TpdsUpdateSender', function() { this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( { _id: { - $in: [ - 'user_id_here', - 'collaberator_ref_1_here', - 'read_only_ref_1_id_here' - ] + $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here'] }, 'dropbox.access_token.uid': { $ne: null } }, @@ -254,11 +246,7 @@ describe('TpdsUpdateSender', function() { this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( { _id: { - $in: [ - 'user_id_here', - 'collaberator_ref_1_here', - 'read_only_ref_1_id_here' - ] + $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here'] }, 'dropbox.access_token.uid': { $ne: null } }, @@ -308,11 +296,7 @@ describe('TpdsUpdateSender', function() { this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( { _id: { - $in: [ - 'user_id_here', - 'collaberator_ref_1_here', - 'read_only_ref_1_id_here' - ] + $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here'] }, 'dropbox.access_token.uid': { $ne: null } }, @@ -361,11 +345,7 @@ describe('TpdsUpdateSender', function() { this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( { _id: { - $in: [ - 'user_id_here', - 'collaberator_ref_1_here', - 'read_only_ref_1_id_here' - ] + $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here'] }, 'dropbox.access_token.uid': { $ne: null } },