mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Invite users in the invited_emails array
We'll remove that attribute soon, but for the time being we want users to still be able to join the team.
This commit is contained in:
parent
6fb6119ca8
commit
e753ef3af5
7 changed files with 63 additions and 14 deletions
|
@ -30,3 +30,6 @@ module.exports =
|
|||
|
||||
getGroupSubscriptionsMemberOf: (user_id, callback)->
|
||||
Subscription.find {member_ids: user_id}, {_id:1, planCode:1}, callback
|
||||
|
||||
getGroupsWithEmailInvite: (email, callback) ->
|
||||
Subscription.find { invited_emails: email }, callback
|
|
@ -63,6 +63,17 @@ module.exports = TeamInvitesHandler =
|
|||
|
||||
removeInviteFromTeam(teamSubscription.id, email, callback)
|
||||
|
||||
# Legacy method to allow a user to receive a confirmation email if their
|
||||
# email is in Subscription.invited_emails when they join. We'll remove this
|
||||
# after a short while.
|
||||
createTeamInvitesForLegacyInvitedEmail: (email, callback) ->
|
||||
SubscriptionLocator.getGroupsWithEmailInvite email, (err, teams) ->
|
||||
return callback(err) if err?
|
||||
|
||||
async.map teams,
|
||||
(team, cb) -> TeamInvitesHandler.createManagerInvite(team.admin_id, email, cb)
|
||||
, callback
|
||||
|
||||
createInvite = (subscription, email, inviterName, callback) ->
|
||||
logger.log {subscriptionId: subscription.id, email, inviterName}, "Creating invite"
|
||||
checkIfInviteIsPossible subscription, email, (error, possible, reason) ->
|
||||
|
|
|
@ -110,9 +110,9 @@ module.exports = UserController =
|
|||
logger.err err:err, user_id:user_id, "error getting user for email update"
|
||||
return res.send 500
|
||||
AuthenticationController.setInSessionUser(req, {email: user.email, first_name: user.first_name, last_name: user.last_name})
|
||||
UserHandler.notifyDomainLicence user, (err)-> #need to refresh this in the background
|
||||
UserHandler.populateTeamInvites user, (err)-> #need to refresh this in the background
|
||||
if err?
|
||||
logger.err err:err, "error notifyDomainLicence"
|
||||
logger.err err:err, "error populateTeamInvites"
|
||||
res.sendStatus(200)
|
||||
|
||||
logout : (req, res)->
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
SubscriptionDomainHandler = require("../Subscription/SubscriptionDomainHandler")
|
||||
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
||||
SubscriptionGroupHandler = require("../Subscription/SubscriptionGroupHandler")
|
||||
TeamInvitesHandler = require("../Subscription/TeamInvitesHandler")
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
|
||||
module.exports = UserHandler =
|
||||
|
||||
populateTeamInvites: (user, callback) ->
|
||||
UserHandler.notifyDomainLicence user, (err) ->
|
||||
return callback(err) if err?
|
||||
TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail(user.email, callback)
|
||||
|
||||
notifyDomainLicence: (user, callback = ->)->
|
||||
logger.log user_id:user._id, "notiying user about a potential domain licence"
|
||||
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
|
||||
|
@ -22,8 +28,4 @@ module.exports = UserHandler =
|
|||
NotificationsBuilder.groupPlan(user, licence).create(callback)
|
||||
|
||||
setupLoginData: (user, callback = ->)->
|
||||
@notifyDomainLicence user, callback
|
||||
|
||||
# Backwards compatibility: this is called from the public-registration module
|
||||
populateGroupLicenceInvite: (user, callback = ->)->
|
||||
@notifyDomainLicence user, callback
|
||||
@populateTeamInvites user, callback
|
||||
|
|
|
@ -184,11 +184,28 @@ describe "TeamInvitesHandler", ->
|
|||
).should.eq true
|
||||
done()
|
||||
|
||||
describe "createTeamInvitesForLegacyInvitedEmail", (done) ->
|
||||
beforeEach ->
|
||||
@subscription.invited_emails = ["eddard@stark.com", "robert@stark.com"]
|
||||
@TeamInvitesHandler.createManagerInvite = sinon.stub().yields(null)
|
||||
@SubscriptionLocator.getGroupsWithEmailInvite = sinon.stub().yields(null, [@subscription])
|
||||
|
||||
it "sends an invitation email to addresses in the legacy invited_emails field", (done) ->
|
||||
@TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail "eddard@stark.com", (err, invite) =>
|
||||
expect(err).not.to.exist
|
||||
|
||||
@TeamInvitesHandler.createManagerInvite.calledWith(
|
||||
@subscription.admin_id,
|
||||
"eddard@stark.com"
|
||||
).should.eq true
|
||||
|
||||
@TeamInvitesHandler.createManagerInvite.callCount.should.eq 1
|
||||
|
||||
done()
|
||||
describe "validation", ->
|
||||
it "doesn't create an invite if the team limit has been reached", (done) ->
|
||||
@LimitationsManager.teamHasReachedMemberLimit = sinon.stub().returns(true)
|
||||
@TeamInvitesHandler.createManagerInvite @manager.id, "John.Snow@nightwatch.com", (err, invite) =>
|
||||
console.log('err, invite', err, invite)
|
||||
expect(err).to.deep.equal(limitReached: true)
|
||||
done()
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ describe "UserController", ->
|
|||
@settings =
|
||||
siteUrl: "sharelatex.example.com"
|
||||
@UserHandler =
|
||||
notifyDomainLicence: sinon.stub().callsArgWith(1)
|
||||
populateTeamInvites: sinon.stub().callsArgWith(1)
|
||||
@UserSessionsManager =
|
||||
trackSession: sinon.stub()
|
||||
untrackSession: sinon.stub()
|
||||
|
@ -267,12 +267,12 @@ describe "UserController", ->
|
|||
done()
|
||||
@UserController.updateUserSettings @req, @res
|
||||
|
||||
it "should call notifyDomainLicence", (done)->
|
||||
it "should call populateTeamInvites", (done)->
|
||||
@req.body.email = @newEmail.toUpperCase()
|
||||
@UserUpdater.changeEmailAddress.callsArgWith(2)
|
||||
@res.sendStatus = (code)=>
|
||||
code.should.equal 200
|
||||
@UserHandler.notifyDomainLicence.calledWith(@user).should.equal true
|
||||
@UserHandler.populateTeamInvites.calledWith(@user).should.equal true
|
||||
done()
|
||||
@UserController.updateUserSettings @req, @res
|
||||
|
||||
|
|
|
@ -23,17 +23,33 @@ describe "UserHandler", ->
|
|||
@NotificationsBuilder =
|
||||
groupPlan:sinon.stub().returns({create:@createStub})
|
||||
|
||||
@TeamInvitesHandler =
|
||||
createTeamInvitesForLegacyInvitedEmail: sinon.stub().yields()
|
||||
|
||||
@UserHandler = SandboxedModule.require modulePath, requires:
|
||||
"logger-sharelatex": @logger = { log: sinon.stub() }
|
||||
"../Notifications/NotificationsBuilder":@NotificationsBuilder
|
||||
"../Subscription/SubscriptionDomainHandler":@SubscriptionDomainHandler
|
||||
"../Subscription/SubscriptionGroupHandler":@SubscriptionGroupHandler
|
||||
"../Subscription/TeamInvitesHandler": @TeamInvitesHandler
|
||||
|
||||
describe "populateTeamInvites", ->
|
||||
beforeEach (done)->
|
||||
@UserHandler.notifyDomainLicence = sinon.stub().yields()
|
||||
@UserHandler.populateTeamInvites @user, done
|
||||
|
||||
it "notifies the user about domain licences zzzzz", ->
|
||||
@UserHandler.notifyDomainLicence.calledWith(@user).should.eq true
|
||||
|
||||
it "notifies the user about legacy team invites", ->
|
||||
@TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
|
||||
.calledWith(@user.email).should.eq true
|
||||
|
||||
describe "notifyDomainLicence", ->
|
||||
describe "no licence", ->
|
||||
beforeEach (done)->
|
||||
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns()
|
||||
@UserHandler.notifyDomainLicence @user, done
|
||||
@UserHandler.populateTeamInvites @user, done
|
||||
|
||||
it "should not call NotificationsBuilder", (done)->
|
||||
@NotificationsBuilder.groupPlan.called.should.equal false
|
||||
|
@ -47,7 +63,7 @@ describe "UserHandler", ->
|
|||
beforeEach (done)->
|
||||
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
|
||||
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, false)
|
||||
@UserHandler.notifyDomainLicence @user, done
|
||||
@UserHandler.populateTeamInvites @user, done
|
||||
|
||||
it "should create notifcation", (done)->
|
||||
@NotificationsBuilder.groupPlan.calledWith(@user, @licence).should.equal true
|
||||
|
@ -57,7 +73,7 @@ describe "UserHandler", ->
|
|||
beforeEach (done)->
|
||||
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
|
||||
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, true)
|
||||
@UserHandler.notifyDomainLicence @user, done
|
||||
@UserHandler.populateTeamInvites @user, done
|
||||
|
||||
it "should create notifcation", (done)->
|
||||
@NotificationsBuilder.groupPlan.called.should.equal false
|
||||
|
|
Loading…
Reference in a new issue