2016-02-05 09:13:38 -05:00
|
|
|
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
2015-01-27 13:09:56 -05:00
|
|
|
async = require("async")
|
2015-02-02 06:15:04 -05:00
|
|
|
_ = require("underscore")
|
2015-01-27 13:09:56 -05:00
|
|
|
settings = require("settings-sharelatex")
|
|
|
|
SubscriptionGroupHandler = require("./SubscriptionGroupHandler")
|
2015-02-02 06:15:04 -05:00
|
|
|
_s = require("underscore.string")
|
2015-01-27 13:09:56 -05:00
|
|
|
|
2015-05-27 15:57:54 -04:00
|
|
|
module.exports = SubscriptionDomainHandler =
|
2015-01-27 13:09:56 -05:00
|
|
|
|
2015-05-22 08:57:15 -04:00
|
|
|
|
2016-02-05 09:13:38 -05:00
|
|
|
getLicenceUserCanJoin: (user)->
|
2015-05-27 15:57:54 -04:00
|
|
|
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
|
2016-02-05 09:13:38 -05:00
|
|
|
return licence
|
2015-05-22 08:57:15 -04:00
|
|
|
|
|
|
|
attemptToJoinGroup: (user, callback)->
|
2015-05-27 15:57:54 -04:00
|
|
|
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
|
2015-05-22 08:57:15 -04:00
|
|
|
if licence? and user.emailVerified
|
2016-02-05 09:13:38 -05:00
|
|
|
SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, (err)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, "error adding user to group"
|
|
|
|
return callback(err)
|
|
|
|
NotificationsBuilder.groupPlan(user, licence).read()
|
2015-05-22 08:57:15 -04:00
|
|
|
else
|
|
|
|
callback "user not verified"
|
|
|
|
|
|
|
|
rejectInvitationToGroup: (user, subscription, callback)->
|
|
|
|
removeUserFromGroup(subscription.admin_id, user._id, callback)
|
|
|
|
|
|
|
|
|
|
|
|
getDomainLicencePage: (user)->
|
2015-05-27 15:57:54 -04:00
|
|
|
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
|
2015-05-22 08:57:15 -04:00
|
|
|
if licence?.verifyEmail
|
|
|
|
return "/user/subscription/#{licence.subscription_id}/group/invited"
|
|
|
|
else
|
|
|
|
return undefined
|
|
|
|
|
|
|
|
|
2015-01-27 13:09:56 -05:00
|
|
|
autoAllocate: (user, callback = ->)->
|
2015-05-27 15:57:54 -04:00
|
|
|
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
|
2015-05-22 08:57:15 -04:00
|
|
|
#
|
2015-01-27 13:09:56 -05:00
|
|
|
if licence?
|
|
|
|
SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback
|
|
|
|
else
|
|
|
|
callback()
|
|
|
|
|
|
|
|
|
|
|
|
_findDomainLicence: (email)->
|
|
|
|
licence = _.find settings.domainLicences, (licence)->
|
|
|
|
_.find licence.domains, (domain)->
|
2016-02-03 11:07:44 -05:00
|
|
|
regex = "[@\.]#{domain}"
|
|
|
|
return email.match(regex)
|
2015-01-27 13:09:56 -05:00
|
|
|
|
|
|
|
return licence
|
|
|
|
|
2015-05-22 08:57:15 -04:00
|
|
|
findDomainLicenceBySubscriptionId: (subscription_id)->
|
|
|
|
licence = _.find settings.domainLicences, (licence)->
|
|
|
|
licence?.subscription_id == subscription_id
|
|
|
|
return licence
|
2015-01-27 13:09:56 -05:00
|
|
|
|