mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 10:43:00 +00:00
Merge pull request #636 from sharelatex/ta-add-emails-filter
Add Filter to Query on Emails Attribute
This commit is contained in:
commit
e6568a26e7
2 changed files with 15 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue