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
|
|
|
|
return "/user/subscription/#{licence.subscription_id}/group/invited"
|
|
|
|
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
|