Choose a better method name

This method is now only notifying users about a potential domain
licence
This commit is contained in:
Alberto Fernández Capel 2018-06-01 11:28:06 +01:00
parent 385fec1914
commit 9b18e58b68
4 changed files with 25 additions and 45 deletions

View file

@ -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.populateGroupLicenceInvite user, (err)-> #need to refresh this in the background
UserHandler.notifyDomainLicence user, (err)-> #need to refresh this in the background
if err?
logger.err err:err, "error populateGroupLicenceInvite"
logger.err err:err, "error notifyDomainLicence"
res.sendStatus(200)
logout : (req, res)->

View file

@ -6,24 +6,20 @@ logger = require("logger-sharelatex")
module.exports = UserHandler =
populateGroupLicenceInvite: (user, callback = ->)->
SubscriptionGroupHandler.convertEmailInvitesToMemberships user.email, user._id, (err) ->
return callback(err) if err?
notifyDomainLicence: (user, callback = ->)->
logger.log user_id:user._id, "notiying user about a potential domain licence"
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
if !licence?
return callback()
logger.log user_id:user._id, "populating any potential group licence invites"
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
if !licence?
SubscriptionGroupHandler.isUserPartOfGroup user._id, licence.subscription_id, (err, alreadyPartOfGroup)->
if err?
return callback(err)
else if alreadyPartOfGroup
logger.log user_id:user._id, "user already part of team, not creating notifcation for them"
return callback()
SubscriptionGroupHandler.isUserPartOfGroup user._id, licence.subscription_id, (err, alreadyPartOfGroup)->
if err?
return callback(err)
else if alreadyPartOfGroup
logger.log user_id:user._id, "user already part of group, not creating notifcation for them"
return callback()
else
NotificationsBuilder.groupPlan(user, licence).create(callback)
else
NotificationsBuilder.groupPlan(user, licence).create(callback)
setupLoginData: (user, callback = ->)->
@populateGroupLicenceInvite user, callback
@notifyDomainLicence user, callback

View file

@ -55,7 +55,7 @@ describe "UserController", ->
@settings =
siteUrl: "sharelatex.example.com"
@UserHandler =
populateGroupLicenceInvite:sinon.stub().callsArgWith(1)
notifyDomainLicence: 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 populateGroupLicenceInvite", (done)->
it "should call notifyDomainLicence", (done)->
@req.body.email = @newEmail.toUpperCase()
@UserUpdater.changeEmailAddress.callsArgWith(2)
@res.sendStatus = (code)=>
code.should.equal 200
@UserHandler.populateGroupLicenceInvite.calledWith(@user).should.equal true
@UserHandler.notifyDomainLicence.calledWith(@user).should.equal true
done()
@UserController.updateUserSettings @req, @res

View file

@ -7,21 +7,20 @@ SandboxedModule = require('sandboxed-module')
describe "UserHandler", ->
beforeEach ->
@user =
@user =
_id:"12390i"
email: "bob@bob.com"
remove: sinon.stub().callsArgWith(0)
@licence =
@licence =
subscription_id: 12323434
@SubscriptionDomainHandler =
getLicenceUserCanJoin: sinon.stub()
@SubscriptionGroupHandler =
isUserPartOfGroup:sinon.stub()
convertEmailInvitesToMemberships: sinon.stub().callsArgWith(2)
@createStub = sinon.stub().callsArgWith(0)
@NotificationsBuilder =
@NotificationsBuilder =
groupPlan:sinon.stub().returns({create:@createStub})
@UserHandler = SandboxedModule.require modulePath, requires:
@ -30,16 +29,11 @@ describe "UserHandler", ->
"../Subscription/SubscriptionDomainHandler":@SubscriptionDomainHandler
"../Subscription/SubscriptionGroupHandler":@SubscriptionGroupHandler
describe "populateGroupLicenceInvite", ->
describe "notifyDomainLicence", ->
describe "no licence", ->
beforeEach (done)->
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns()
@UserHandler.populateGroupLicenceInvite @user, done
it "should call convertEmailInvitesToMemberships", ->
@SubscriptionGroupHandler.convertEmailInvitesToMemberships
.calledWith(@user.email, @user._id)
.should.equal true
@UserHandler.notifyDomainLicence @user, done
it "should not call NotificationsBuilder", (done)->
@NotificationsBuilder.groupPlan.called.should.equal false
@ -53,28 +47,18 @@ describe "UserHandler", ->
beforeEach (done)->
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, false)
@UserHandler.populateGroupLicenceInvite @user, done
@UserHandler.notifyDomainLicence @user, done
it "should create notifcation", (done)->
@NotificationsBuilder.groupPlan.calledWith(@user, @licence).should.equal true
done()
it "should call convertEmailInvitesToMemberships", ->
@SubscriptionGroupHandler.convertEmailInvitesToMemberships
.calledWith(@user.email, @user._id)
.should.equal true
describe "with matching licence user is already in", ->
beforeEach (done)->
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, true)
@UserHandler.populateGroupLicenceInvite @user, done
@UserHandler.notifyDomainLicence @user, done
it "should create notifcation", (done)->
@NotificationsBuilder.groupPlan.called.should.equal false
done()
it "should call convertEmailInvitesToMemberships", ->
@SubscriptionGroupHandler.convertEmailInvitesToMemberships
.calledWith(@user.email, @user._id)
.should.equal true