mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
use multiple emails when relevant
This commit is contained in:
parent
31827ae6b5
commit
5438a565b9
6 changed files with 23 additions and 23 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -22,7 +22,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)->
|
||||
|
|
|
@ -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) =>
|
||||
|
|
|
@ -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) ->
|
||||
|
|
|
@ -35,7 +35,7 @@ describe "SubscriptionGroupHandler", ->
|
|||
|
||||
@UserGetter =
|
||||
getUser: sinon.stub()
|
||||
getUserByMainEmail: sinon.stub()
|
||||
getUserByAnyEmail: sinon.stub()
|
||||
|
||||
@LimitationsManager =
|
||||
hasGroupMembersLimitReached: sinon.stub()
|
||||
|
@ -78,11 +78,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)->
|
||||
|
@ -109,7 +109,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()
|
||||
|
|
Loading…
Reference in a new issue