use multiple emails when relevant

This commit is contained in:
Tim Alby 2018-05-28 16:09:22 +02:00
parent c5530163f5
commit 813289f5de
6 changed files with 22 additions and 22 deletions

View file

@ -27,7 +27,7 @@ module.exports = CollaboratorsInviteController =
_checkShouldInviteEmail: (email, callback=(err, shouldAllowInvite)->) ->
if Settings.restrictInvitesToExistingAccounts == true
logger.log {email}, "checking if user exists with this email"
UserGetter.getUserByMainEmail email, {_id: 1}, (err, user) ->
UserGetter.getUserByAnyEmail email, {_id: 1}, (err, user) ->
return callback(err) if err?
userExists = user? and user?._id?
callback(null, userExists)

View file

@ -32,7 +32,7 @@ module.exports = CollaboratorsInviteHandler =
_trySendInviteNotification: (projectId, sendingUser, invite, callback=(err)->) ->
email = invite.email
UserGetter.getUserByMainEmail email, {_id: 1}, (err, existingUser) ->
UserGetter.getUserByAnyEmail email, {_id: 1}, (err, existingUser) ->
if err?
logger.err {projectId, email}, "error checking if user exists"
return callback(err)

View file

@ -21,7 +21,7 @@ module.exports = SubscriptionGroupHandler =
if limitReached
logger.err adminUserId:adminUserId, newEmail:newEmail, "group subscription limit reached not adding user to group"
return callback(limitReached:limitReached)
UserGetter.getUserByMainEmail newEmail, (err, user)->
UserGetter.getUserByAnyEmail newEmail, (err, user)->
return callback(err) if err?
if user?
SubscriptionUpdater.addUserToGroup adminUserId, user._id, (err)->

View file

@ -25,7 +25,7 @@ describe "CollaboratorsInviteController", ->
@LimitationsManager = {}
@UserGetter =
getUserByMainEmail: sinon.stub()
getUserByAnyEmail: sinon.stub()
getUser: sinon.stub()
@CollaboratorsInviteController = SandboxedModule.require modulePath, requires:
@ -716,7 +716,7 @@ describe "CollaboratorsInviteController", ->
beforeEach ->
@user = {_id: ObjectId().toString()}
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, null, @user)
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, null, @user)
it 'should callback with `true`', (done) ->
@call (err, shouldAllow) =>
@ -728,7 +728,7 @@ describe "CollaboratorsInviteController", ->
beforeEach ->
@user = null
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, null, @user)
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, null, @user)
it 'should callback with `false`', (done) ->
@call (err, shouldAllow) =>
@ -738,15 +738,15 @@ describe "CollaboratorsInviteController", ->
it 'should have called getUser', (done) ->
@call (err, shouldAllow) =>
@UserGetter.getUserByMainEmail.callCount.should.equal 1
@UserGetter.getUserByMainEmail.calledWith(@email, {_id: 1}).should.equal true
@UserGetter.getUserByAnyEmail.callCount.should.equal 1
@UserGetter.getUserByAnyEmail.calledWith(@email, {_id: 1}).should.equal true
done()
describe 'when getUser produces an error', ->
beforeEach ->
@user = null
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, new Error('woops'))
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, new Error('woops'))
it 'should callback with an error', (done) ->
@call (err, shouldAllow) =>

View file

@ -605,7 +605,7 @@ describe "CollaboratorsInviteHandler", ->
_id: ObjectId()
first_name: "jim"
@existingUser = {_id: ObjectId()}
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, null, @existingUser)
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, null, @existingUser)
@fakeProject =
_id: @project_id
name: "some project"
@ -626,8 +626,8 @@ describe "CollaboratorsInviteHandler", ->
it 'should call getUser', (done) ->
@call (err) =>
@UserGetter.getUserByMainEmail.callCount.should.equal 1
@UserGetter.getUserByMainEmail.calledWith(@invite.email).should.equal true
@UserGetter.getUserByAnyEmail.callCount.should.equal 1
@UserGetter.getUserByAnyEmail.calledWith(@invite.email).should.equal true
done()
it 'should call getProject', (done) ->
@ -671,7 +671,7 @@ describe "CollaboratorsInviteHandler", ->
describe 'when the user does not exist', ->
beforeEach ->
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, null, null)
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, null, null)
it 'should not produce an error', (done) ->
@call (err) =>
@ -680,8 +680,8 @@ describe "CollaboratorsInviteHandler", ->
it 'should call getUser', (done) ->
@call (err) =>
@UserGetter.getUserByMainEmail.callCount.should.equal 1
@UserGetter.getUserByMainEmail.calledWith(@invite.email).should.equal true
@UserGetter.getUserByAnyEmail.callCount.should.equal 1
@UserGetter.getUserByAnyEmail.calledWith(@invite.email).should.equal true
done()
it 'should not call getProject', (done) ->
@ -698,7 +698,7 @@ describe "CollaboratorsInviteHandler", ->
describe 'when the getUser produces an error', ->
beforeEach ->
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, new Error('woops'))
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, new Error('woops'))
it 'should produce an error', (done) ->
@call (err) =>
@ -707,8 +707,8 @@ describe "CollaboratorsInviteHandler", ->
it 'should call getUser', (done) ->
@call (err) =>
@UserGetter.getUserByMainEmail.callCount.should.equal 1
@UserGetter.getUserByMainEmail.calledWith(@invite.email).should.equal true
@UserGetter.getUserByAnyEmail.callCount.should.equal 1
@UserGetter.getUserByAnyEmail.calledWith(@invite.email).should.equal true
done()
it 'should not call getProject', (done) ->

View file

@ -32,7 +32,7 @@ describe "SubscriptionGroupHandler", ->
@UserGetter =
getUser: sinon.stub()
getUserByMainEmail: sinon.stub()
getUserByAnyEmail: sinon.stub()
@LimitationsManager =
hasGroupMembersLimitReached: sinon.stub()
@ -71,11 +71,11 @@ describe "SubscriptionGroupHandler", ->
describe "addUserToGroup", ->
beforeEach ->
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false, @subscription)
@UserGetter.getUserByMainEmail.callsArgWith(1, null, @user)
@UserGetter.getUserByAnyEmail.callsArgWith(1, null, @user)
it "should find the user", (done)->
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
@UserGetter.getUserByMainEmail.calledWith(@newEmail).should.equal true
@UserGetter.getUserByAnyEmail.calledWith(@newEmail).should.equal true
done()
it "should add the user to the group", (done)->
@ -102,7 +102,7 @@ describe "SubscriptionGroupHandler", ->
done()
it "should add an email invite if no user is found", (done) ->
@UserGetter.getUserByMainEmail.callsArgWith(1, null, null)
@UserGetter.getUserByAnyEmail.callsArgWith(1, null, null)
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
@SubscriptionUpdater.addEmailInviteToGroup.calledWith(@adminUser_id, @newEmail).should.equal true
done()