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")
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
2018-05-31 11:15:47 -04:00
|
|
|
return "/user/subscription/domain/join"
|
2015-05-22 08:57:15 -04:00
|
|
|
else
|
|
|
|
return undefined
|
|
|
|
|
2015-01-27 13:09:56 -05:00
|
|
|
_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
|