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")
|
2018-06-06 07:35:13 -04:00
|
|
|
TeamInvitesHandler = require("../Subscription/TeamInvitesHandler")
|
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
|
|
|
|
2018-06-06 07:35:13 -04:00
|
|
|
populateTeamInvites: (user, callback) ->
|
|
|
|
UserHandler.notifyDomainLicence user, (err) ->
|
|
|
|
return callback(err) if err?
|
|
|
|
TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail(user.email, callback)
|
|
|
|
|
2018-06-01 06:28:06 -04:00
|
|
|
notifyDomainLicence: (user, callback = ->)->
|
|
|
|
logger.log user_id:user._id, "notiying user about a potential domain licence"
|
|
|
|
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
|
|
|
|
if !licence?
|
|
|
|
return callback()
|
2016-02-18 05:06:21 -05:00
|
|
|
|
2018-06-01 06:28:06 -04: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 team, not creating notifcation for them"
|
2016-02-18 06:43:43 -05:00
|
|
|
return callback()
|
2018-06-01 06:28:06 -04:00
|
|
|
else
|
|
|
|
NotificationsBuilder.groupPlan(user, licence).create(callback)
|
2016-02-18 05:06:21 -05:00
|
|
|
|
|
|
|
setupLoginData: (user, callback = ->)->
|
2018-06-06 07:35:13 -04:00
|
|
|
@populateTeamInvites user, callback
|