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-02-18 10:06:21 +00:00
|
|
|
_populateGroupLicenceInvite: (user, callback)->
|
2016-02-17 16:24:09 +00:00
|
|
|
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
|
2016-02-18 10:06:21 +00:00
|
|
|
if !licence?
|
2016-02-17 16:24:09 +00:00
|
|
|
return callback()
|
2016-02-18 10:06:21 +00:00
|
|
|
|
|
|
|
SubscriptionGroupHandler.isUserPartOfGroup user._id, licence.subscription_id, (err, alreadyPartOfGroup)->
|
2016-02-18 11:43:43 +00:00
|
|
|
if err?
|
2016-02-18 10:06:21 +00:00
|
|
|
return callback(err)
|
2016-02-18 11:43:43 +00: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 10:06:21 +00:00
|
|
|
else
|
|
|
|
NotificationsBuilder.groupPlan(user, licence).create(callback)
|
|
|
|
|
|
|
|
setupLoginData: (user, callback = ->)->
|
2016-02-18 10:16:50 +00:00
|
|
|
@_populateGroupLicenceInvite user, callback
|
2016-02-18 10:06:21 +00:00
|
|
|
|