SubscriptionDomainAllocator.coffee 649 B

123456789101112131415161718192021222324
  1. async = require("async")
  2. _ = require("underscore")
  3. settings = require("settings-sharelatex")
  4. SubscriptionGroupHandler = require("./SubscriptionGroupHandler")
  5. _s = require("underscore.string")
  6. module.exports = SubscriptionDomainAllocator =
  7. autoAllocate: (user, callback = ->)->
  8. licence = SubscriptionDomainAllocator._findDomainLicence(user.email)
  9. if licence?
  10. SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback
  11. else
  12. callback()
  13. _findDomainLicence: (email)->
  14. licence = _.find settings.domainLicences, (licence)->
  15. _.find licence.domains, (domain)->
  16. _s.endsWith email, domain
  17. return licence