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 return
} }
try { try {
const response = request({ const response = await request({
uri: `${tpdsWorkerUrl}/enqueue/web_to_tpds_http_requests`, uri: `${tpdsWorkerUrl}/enqueue/web_to_tpds_http_requests`,
json: { group, job, method }, json: { group, job, method },
method: 'post', method: 'post',
@ -123,16 +123,18 @@ async function getProjectUsersIds(projectId) {
projectId projectId
) )
// filter list to only return users with dropbox linked // 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 } 'dropbox.access_token.uid': { $ne: null }
}, },
{ {
_id: 1 _id: 1
} }
) )
return users.map(user => user._id) const dropboxUserIds = dropboxUsers.map(user => user._id)
return [projectUserIds[0], ...dropboxUserIds]
} }
async function moveEntity(options) { async function moveEntity(options) {

View file

@ -15,10 +15,12 @@ const UserGetter = {
callback = projection callback = projection
projection = {} projection = {}
} }
normalizeQuery(query, (err, query) => { try {
if (err) return callback(err) query = normalizeQuery(query)
db.users.findOne(query, projection, callback) db.users.findOne(query, projection, callback)
}) } catch (err) {
callback(err)
}
}, },
getUserEmail(userId, callback) { getUserEmail(userId, callback) {
@ -129,10 +131,12 @@ const UserGetter = {
}, },
getUsers(query, projection, callback) { getUsers(query, projection, callback) {
normalizeQuery(query, (err, query) => { try {
if (err) return callback(err) query = normalizeQuery(query)
db.users.find(query, projection, callback) db.users.find(query, projection, callback)
}) } catch (err) {
callback(err)
}
}, },
// check for duplicate email address. This is also enforced at the DB level // 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) { if (!query) {
return callback(new Error('no query provided')) throw new Error('no query provided')
} }
try { if (typeof query === 'string') {
if (typeof query === 'string') { return { _id: ObjectId(query) }
callback(null, { _id: ObjectId(query) }) } else if (query instanceof ObjectId) {
} else if (query instanceof ObjectId) { return { _id: query }
callback(null, { _id: query }) } else if (Array.isArray(query)) {
} else if (Array.isArray(query)) { const userIds = query.map(u => ObjectId(u.toString()))
const userIds = query.map(u => ObjectId(u.toString())) return { _id: { $in: userIds } }
callback(null, { _id: { $in: userIds } }) } else {
} else { return query
callback(null, query)
}
} catch (err) {
callback(err, null)
} }
} }

View file

@ -51,7 +51,7 @@ describe('TpdsUpdateSender', function() {
} }
} }
const getUsers = sinon.stub().resolves( const getUsers = sinon.stub().resolves(
memberIds.map(userId => { memberIds.slice(1).map(userId => {
return { _id: userId } return { _id: userId }
}) })
) )
@ -145,11 +145,7 @@ describe('TpdsUpdateSender', function() {
this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith(
{ {
_id: { _id: {
$in: [ $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here']
'user_id_here',
'collaberator_ref_1_here',
'read_only_ref_1_id_here'
]
}, },
'dropbox.access_token.uid': { $ne: null } 'dropbox.access_token.uid': { $ne: null }
}, },
@ -203,11 +199,7 @@ describe('TpdsUpdateSender', function() {
this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith(
{ {
_id: { _id: {
$in: [ $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here']
'user_id_here',
'collaberator_ref_1_here',
'read_only_ref_1_id_here'
]
}, },
'dropbox.access_token.uid': { $ne: null } 'dropbox.access_token.uid': { $ne: null }
}, },
@ -254,11 +246,7 @@ describe('TpdsUpdateSender', function() {
this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith(
{ {
_id: { _id: {
$in: [ $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here']
'user_id_here',
'collaberator_ref_1_here',
'read_only_ref_1_id_here'
]
}, },
'dropbox.access_token.uid': { $ne: null } 'dropbox.access_token.uid': { $ne: null }
}, },
@ -308,11 +296,7 @@ describe('TpdsUpdateSender', function() {
this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith(
{ {
_id: { _id: {
$in: [ $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here']
'user_id_here',
'collaberator_ref_1_here',
'read_only_ref_1_id_here'
]
}, },
'dropbox.access_token.uid': { $ne: null } 'dropbox.access_token.uid': { $ne: null }
}, },
@ -361,11 +345,7 @@ describe('TpdsUpdateSender', function() {
this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith( this.UserGetter.promises.getUsers.should.have.been.calledOnce.and.calledWith(
{ {
_id: { _id: {
$in: [ $in: ['collaberator_ref_1_here', 'read_only_ref_1_id_here']
'user_id_here',
'collaberator_ref_1_here',
'read_only_ref_1_id_here'
]
}, },
'dropbox.access_token.uid': { $ne: null } 'dropbox.access_token.uid': { $ne: null }
}, },