2015-01-27 18:09:56 +00:00
|
|
|
async = require("async")
|
2015-02-02 11:15:04 +00:00
|
|
|
_ = require("underscore")
|
2015-01-27 18:09:56 +00:00
|
|
|
settings = require("settings-sharelatex")
|
|
|
|
|
2015-05-27 19:57:54 +00:00
|
|
|
module.exports = SubscriptionDomainHandler =
|
2015-01-27 18:09:56 +00:00
|
|
|
|
2015-05-22 12:57:15 +00:00
|
|
|
|
2016-02-05 14:13:38 +00:00
|
|
|
getLicenceUserCanJoin: (user)->
|
2015-05-27 19:57:54 +00:00
|
|
|
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
|
2016-02-05 14:13:38 +00:00
|
|
|
return licence
|
2015-05-22 12:57:15 +00:00
|
|
|
|
|
|
|
rejectInvitationToGroup: (user, subscription, callback)->
|
|
|
|
removeUserFromGroup(subscription.admin_id, user._id, callback)
|
|
|
|
|
|
|
|
getDomainLicencePage: (user)->
|
2015-05-27 19:57:54 +00:00
|
|
|
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
|
2015-05-22 12:57:15 +00:00
|
|
|
if licence?.verifyEmail
|
|
|
|
return "/user/subscription/#{licence.subscription_id}/group/invited"
|
|
|
|
else
|
|
|
|
return undefined
|
|
|
|
|
2015-01-27 18:09:56 +00:00
|
|
|
_findDomainLicence: (email)->
|
|
|
|
licence = _.find settings.domainLicences, (licence)->
|
|
|
|
_.find licence.domains, (domain)->
|
2016-02-03 16:07:44 +00:00
|
|
|
regex = "[@\.]#{domain}"
|
|
|
|
return email.match(regex)
|
2015-01-27 18:09:56 +00:00
|
|
|
|
|
|
|
return licence
|
|
|
|
|
2015-05-22 12:57:15 +00:00
|
|
|
findDomainLicenceBySubscriptionId: (subscription_id)->
|
|
|
|
licence = _.find settings.domainLicences, (licence)->
|
|
|
|
licence?.subscription_id == subscription_id
|
|
|
|
return licence
|