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
c5530163f5
commit
813289f5de
6 changed files with 22 additions and 22 deletions
|
@ -27,7 +27,7 @@ module.exports = CollaboratorsInviteController =
|
||||||
_checkShouldInviteEmail: (email, callback=(err, shouldAllowInvite)->) ->
|
_checkShouldInviteEmail: (email, callback=(err, shouldAllowInvite)->) ->
|
||||||
if Settings.restrictInvitesToExistingAccounts == true
|
if Settings.restrictInvitesToExistingAccounts == true
|
||||||
logger.log {email}, "checking if user exists with this email"
|
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?
|
return callback(err) if err?
|
||||||
userExists = user? and user?._id?
|
userExists = user? and user?._id?
|
||||||
callback(null, userExists)
|
callback(null, userExists)
|
||||||
|
|
|
@ -32,7 +32,7 @@ module.exports = CollaboratorsInviteHandler =
|
||||||
|
|
||||||
_trySendInviteNotification: (projectId, sendingUser, invite, callback=(err)->) ->
|
_trySendInviteNotification: (projectId, sendingUser, invite, callback=(err)->) ->
|
||||||
email = invite.email
|
email = invite.email
|
||||||
UserGetter.getUserByMainEmail email, {_id: 1}, (err, existingUser) ->
|
UserGetter.getUserByAnyEmail email, {_id: 1}, (err, existingUser) ->
|
||||||
if err?
|
if err?
|
||||||
logger.err {projectId, email}, "error checking if user exists"
|
logger.err {projectId, email}, "error checking if user exists"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
|
|
@ -21,7 +21,7 @@ module.exports = SubscriptionGroupHandler =
|
||||||
if limitReached
|
if limitReached
|
||||||
logger.err adminUserId:adminUserId, newEmail:newEmail, "group subscription limit reached not adding user to group"
|
logger.err adminUserId:adminUserId, newEmail:newEmail, "group subscription limit reached not adding user to group"
|
||||||
return callback(limitReached:limitReached)
|
return callback(limitReached:limitReached)
|
||||||
UserGetter.getUserByMainEmail newEmail, (err, user)->
|
UserGetter.getUserByAnyEmail newEmail, (err, user)->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
if user?
|
if user?
|
||||||
SubscriptionUpdater.addUserToGroup adminUserId, user._id, (err)->
|
SubscriptionUpdater.addUserToGroup adminUserId, user._id, (err)->
|
||||||
|
|
|
@ -25,7 +25,7 @@ describe "CollaboratorsInviteController", ->
|
||||||
|
|
||||||
@LimitationsManager = {}
|
@LimitationsManager = {}
|
||||||
@UserGetter =
|
@UserGetter =
|
||||||
getUserByMainEmail: sinon.stub()
|
getUserByAnyEmail: sinon.stub()
|
||||||
getUser: sinon.stub()
|
getUser: sinon.stub()
|
||||||
|
|
||||||
@CollaboratorsInviteController = SandboxedModule.require modulePath, requires:
|
@CollaboratorsInviteController = SandboxedModule.require modulePath, requires:
|
||||||
|
@ -716,7 +716,7 @@ describe "CollaboratorsInviteController", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@user = {_id: ObjectId().toString()}
|
@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) ->
|
it 'should callback with `true`', (done) ->
|
||||||
@call (err, shouldAllow) =>
|
@call (err, shouldAllow) =>
|
||||||
|
@ -728,7 +728,7 @@ describe "CollaboratorsInviteController", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@user = null
|
@user = null
|
||||||
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, null, @user)
|
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, null, @user)
|
||||||
|
|
||||||
it 'should callback with `false`', (done) ->
|
it 'should callback with `false`', (done) ->
|
||||||
@call (err, shouldAllow) =>
|
@call (err, shouldAllow) =>
|
||||||
|
@ -738,15 +738,15 @@ describe "CollaboratorsInviteController", ->
|
||||||
|
|
||||||
it 'should have called getUser', (done) ->
|
it 'should have called getUser', (done) ->
|
||||||
@call (err, shouldAllow) =>
|
@call (err, shouldAllow) =>
|
||||||
@UserGetter.getUserByMainEmail.callCount.should.equal 1
|
@UserGetter.getUserByAnyEmail.callCount.should.equal 1
|
||||||
@UserGetter.getUserByMainEmail.calledWith(@email, {_id: 1}).should.equal true
|
@UserGetter.getUserByAnyEmail.calledWith(@email, {_id: 1}).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'when getUser produces an error', ->
|
describe 'when getUser produces an error', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@user = null
|
@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) ->
|
it 'should callback with an error', (done) ->
|
||||||
@call (err, shouldAllow) =>
|
@call (err, shouldAllow) =>
|
||||||
|
|
|
@ -605,7 +605,7 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
_id: ObjectId()
|
_id: ObjectId()
|
||||||
first_name: "jim"
|
first_name: "jim"
|
||||||
@existingUser = {_id: ObjectId()}
|
@existingUser = {_id: ObjectId()}
|
||||||
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, null, @existingUser)
|
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, null, @existingUser)
|
||||||
@fakeProject =
|
@fakeProject =
|
||||||
_id: @project_id
|
_id: @project_id
|
||||||
name: "some project"
|
name: "some project"
|
||||||
|
@ -626,8 +626,8 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
|
|
||||||
it 'should call getUser', (done) ->
|
it 'should call getUser', (done) ->
|
||||||
@call (err) =>
|
@call (err) =>
|
||||||
@UserGetter.getUserByMainEmail.callCount.should.equal 1
|
@UserGetter.getUserByAnyEmail.callCount.should.equal 1
|
||||||
@UserGetter.getUserByMainEmail.calledWith(@invite.email).should.equal true
|
@UserGetter.getUserByAnyEmail.calledWith(@invite.email).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should call getProject', (done) ->
|
it 'should call getProject', (done) ->
|
||||||
|
@ -671,7 +671,7 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
describe 'when the user does not exist', ->
|
describe 'when the user does not exist', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@UserGetter.getUserByMainEmail = sinon.stub().callsArgWith(2, null, null)
|
@UserGetter.getUserByAnyEmail = sinon.stub().callsArgWith(2, null, null)
|
||||||
|
|
||||||
it 'should not produce an error', (done) ->
|
it 'should not produce an error', (done) ->
|
||||||
@call (err) =>
|
@call (err) =>
|
||||||
|
@ -680,8 +680,8 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
|
|
||||||
it 'should call getUser', (done) ->
|
it 'should call getUser', (done) ->
|
||||||
@call (err) =>
|
@call (err) =>
|
||||||
@UserGetter.getUserByMainEmail.callCount.should.equal 1
|
@UserGetter.getUserByAnyEmail.callCount.should.equal 1
|
||||||
@UserGetter.getUserByMainEmail.calledWith(@invite.email).should.equal true
|
@UserGetter.getUserByAnyEmail.calledWith(@invite.email).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should not call getProject', (done) ->
|
it 'should not call getProject', (done) ->
|
||||||
|
@ -698,7 +698,7 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
describe 'when the getUser produces an error', ->
|
describe 'when the getUser produces an error', ->
|
||||||
|
|
||||||
beforeEach ->
|
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) ->
|
it 'should produce an error', (done) ->
|
||||||
@call (err) =>
|
@call (err) =>
|
||||||
|
@ -707,8 +707,8 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
|
|
||||||
it 'should call getUser', (done) ->
|
it 'should call getUser', (done) ->
|
||||||
@call (err) =>
|
@call (err) =>
|
||||||
@UserGetter.getUserByMainEmail.callCount.should.equal 1
|
@UserGetter.getUserByAnyEmail.callCount.should.equal 1
|
||||||
@UserGetter.getUserByMainEmail.calledWith(@invite.email).should.equal true
|
@UserGetter.getUserByAnyEmail.calledWith(@invite.email).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should not call getProject', (done) ->
|
it 'should not call getProject', (done) ->
|
||||||
|
|
|
@ -32,7 +32,7 @@ describe "SubscriptionGroupHandler", ->
|
||||||
|
|
||||||
@UserGetter =
|
@UserGetter =
|
||||||
getUser: sinon.stub()
|
getUser: sinon.stub()
|
||||||
getUserByMainEmail: sinon.stub()
|
getUserByAnyEmail: sinon.stub()
|
||||||
|
|
||||||
@LimitationsManager =
|
@LimitationsManager =
|
||||||
hasGroupMembersLimitReached: sinon.stub()
|
hasGroupMembersLimitReached: sinon.stub()
|
||||||
|
@ -71,11 +71,11 @@ describe "SubscriptionGroupHandler", ->
|
||||||
describe "addUserToGroup", ->
|
describe "addUserToGroup", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false, @subscription)
|
@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)->
|
it "should find the user", (done)->
|
||||||
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
|
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
|
||||||
@UserGetter.getUserByMainEmail.calledWith(@newEmail).should.equal true
|
@UserGetter.getUserByAnyEmail.calledWith(@newEmail).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should add the user to the group", (done)->
|
it "should add the user to the group", (done)->
|
||||||
|
@ -102,7 +102,7 @@ describe "SubscriptionGroupHandler", ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should add an email invite if no user is found", (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)=>
|
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
|
||||||
@SubscriptionUpdater.addEmailInviteToGroup.calledWith(@adminUser_id, @newEmail).should.equal true
|
@SubscriptionUpdater.addEmailInviteToGroup.calledWith(@adminUser_id, @newEmail).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
Loading…
Reference in a new issue