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
|
|
|
|
|
|
|
module.exports = SubscriptionDomainAllocator =
|
|
|
|
|
|
|
|
autoAllocate: (user, callback = ->)->
|
|
|
|
licence = SubscriptionDomainAllocator._findDomainLicence(user.email)
|
|
|
|
if licence?
|
|
|
|
SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback
|
|
|
|
else
|
|
|
|
callback()
|
|
|
|
|
|
|
|
|
|
|
|
_findDomainLicence: (email)->
|
|
|
|
licence = _.find settings.domainLicences, (licence)->
|
|
|
|
_.find licence.domains, (domain)->
|
2015-02-02 06:15:04 -05:00
|
|
|
_s.endsWith email, domain
|
2015-01-27 13:09:56 -05:00
|
|
|
|
|
|
|
return licence
|
|
|
|
|
|
|
|
|