2016-02-17 11:24:09 -05:00
|
|
|
SubscriptionDomainHandler = require("../Subscription/SubscriptionDomainHandler")
|
|
|
|
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
2016-02-18 05:06:21 -05:00
|
|
|
SubscriptionGroupHandler = require("../Subscription/SubscriptionGroupHandler")
|
2016-02-18 06:43:43 -05:00
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
|
2016-02-17 11:24:09 -05:00
|
|
|
|
2016-02-18 05:06:21 -05:00
|
|
|
module.exports = UserHandler =
|
2016-02-17 11:24:09 -05:00
|
|
|
|
2016-06-13 08:38:30 -04:00
|
|
|
populateGroupLicenceInvite: (user, callback = ->)->
|
2016-03-14 06:08:47 -04:00
|
|
|
logger.log user_id:user._id, "populating any potential group licence invites"
|
2016-02-17 11:24:09 -05:00
|
|
|
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
|
2016-02-18 05:06:21 -05:00
|
|
|
if !licence?
|
2016-02-17 11:24:09 -05:00
|
|
|
return callback()
|
2016-02-18 05:06:21 -05:00
|
|
|
|
|
|
|
SubscriptionGroupHandler.isUserPartOfGroup user._id, licence.subscription_id, (err, alreadyPartOfGroup)->
|
2016-02-18 06:43:43 -05:00
|
|
|
if err?
|
2016-02-18 05:06:21 -05:00
|
|
|
return callback(err)
|
2016-02-18 06:43:43 -05:00
|
|
|
else if alreadyPartOfGroup
|
|
|
|
logger.log user_id:user._id, "user already part of group, not creating notifcation for them"
|
|
|
|
return callback()
|
2016-02-18 05:06:21 -05:00
|
|
|
else
|
|
|
|
NotificationsBuilder.groupPlan(user, licence).create(callback)
|
|
|
|
|
|
|
|
setupLoginData: (user, callback = ->)->
|
2016-03-13 18:24:39 -04:00
|
|
|
@populateGroupLicenceInvite user, callback
|
2016-02-18 05:06:21 -05:00
|
|
|
|