Merge pull request #636 from sharelatex/ta-add-emails-filter

Add Filter to Query on Emails Attribute
This commit is contained in:
Timothée Alby 2018-06-06 16:21:48 +02:00 committed by GitHub
commit e6568a26e7
2 changed files with 15 additions and 2 deletions

View file

@ -37,7 +37,9 @@ module.exports = UserGetter =
if arguments.length == 2
callback = projection
projection = {}
db.users.findOne 'emails.email': email, projection, (error, user) =>
# $exists: true MUST be set to use the partial index
query = emails: { $exists: true }, 'emails.email': email
db.users.findOne query, projection, (error, user) =>
return callback(error, user) if error? or user?
# While multiple emails are being rolled out, check for the main email as

View file

@ -60,12 +60,23 @@ describe "UserGetter", ->
describe "getUserByAnyEmail", ->
it "query user for any email", (done)->
email = 'hello@world.com'
expectedQuery =
emails: { $exists: true }
'emails.email': email
projection = emails: 1
@UserGetter.getUserByAnyEmail " #{email} ", projection, (error, user) =>
@findOne.calledWith('emails.email': email, projection).should.equal true
@findOne.calledWith(expectedQuery, projection).should.equal true
user.should.deep.equal @fakeUser
done()
it "query contains $exists:true so partial index is used", (done)->
expectedQuery =
emails: { $exists: true }
'emails.email': ''
@UserGetter.getUserByAnyEmail '', {}, (error, user) =>
@findOne.calledWith(expectedQuery, {}).should.equal true
done()
it "checks main email as well", (done)->
@findOne.callsArgWith(2, null, null)
email = 'hello@world.com'