always send update for project owner, pr fixes

GitOrigin-RevId: a58ecfb13c25df02ccf79c189903b5a6fcddd835
This commit is contained in:
Ersun Warncke 2020-06-11 09:55:52 -04:00 committed by Copybot
parent 5e84d95291
commit d3a30929f7
3 changed files with 33 additions and 51 deletions

View file

@ -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) {

View file

@ -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) })
return { _id: ObjectId(query) }
} else if (query instanceof ObjectId) {
callback(null, { _id: query })
return { _id: query }
} else if (Array.isArray(query)) {
const userIds = query.map(u => ObjectId(u.toString()))
callback(null, { _id: { $in: userIds } })
return { _id: { $in: userIds } }
} else {
callback(null, query)
}
} catch (err) {
callback(err, null)
return query
}
}

View file

@ -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 }
},