2016-02-17 16:24:09 +00:00
|
|
|
SubscriptionDomainHandler = require("../Subscription/SubscriptionDomainHandler")
|
|
|
|
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
2016-02-18 10:06:21 +00:00
|
|
|
SubscriptionGroupHandler = require("../Subscription/SubscriptionGroupHandler")
|
2016-02-18 11:43:43 +00:00
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
|
2016-02-17 16:24:09 +00:00
|
|
|
|
2016-02-18 10:06:21 +00:00
|
|
|
module.exports = UserHandler =
|
2016-02-17 16:24:09 +00:00
|
|
|
|
2016-06-13 12:38:30 +00:00
|
|
|
populateGroupLicenceInvite: (user, callback = ->)->
|
2017-06-08 11:12:08 +00:00
|
|
|
SubscriptionGroupHandler.convertEmailInvitesToMemberships user.email, user._id, (err) ->
|
|
|
|
return callback(err) if err?
|
2016-02-18 10:06:21 +00:00
|
|
|
|
2017-06-08 11:12:08 +00:00
|
|
|
logger.log user_id:user._id, "populating any potential group licence invites"
|
|
|
|
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
|
|
|
|
if !licence?
|
2016-02-18 11:43:43 +00:00
|
|
|
return callback()
|
2017-06-08 11:12:08 +00:00
|
|
|
|
|
|
|
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)
|
2016-02-18 10:06:21 +00:00
|
|
|
|
|
|
|
setupLoginData: (user, callback = ->)->
|
2016-03-13 22:24:39 +00:00
|
|
|
@populateGroupLicenceInvite user, callback
|
2016-02-18 10:06:21 +00:00
|
|
|
|