2018-05-31 11:15:47 -04:00
|
|
|
SubscriptionGroupHandler = require("./SubscriptionGroupHandler")
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
SubscriptionLocator = require("./SubscriptionLocator")
|
|
|
|
ErrorsController = require("../Errors/ErrorController")
|
|
|
|
SubscriptionDomainHandler = require("./SubscriptionDomainHandler")
|
|
|
|
AuthenticationController = require('../Authentication/AuthenticationController')
|
|
|
|
TeamInvitesHandler = require('./TeamInvitesHandler')
|
|
|
|
|
|
|
|
async = require("async")
|
|
|
|
|
|
|
|
module.exports =
|
|
|
|
join: (req, res)->
|
|
|
|
user = AuthenticationController.getSessionUser(req)
|
|
|
|
licence = SubscriptionDomainHandler.getLicenceUserCanJoin(user)
|
|
|
|
|
|
|
|
if !licence?
|
|
|
|
return ErrorsController.notFound(req, res)
|
|
|
|
|
|
|
|
jobs =
|
|
|
|
partOfGroup: (cb)->
|
2018-08-31 06:23:44 -04:00
|
|
|
SubscriptionGroupHandler.isUserPartOfGroup user._id, licence.group_subscription_id, cb
|
2018-05-31 11:15:47 -04:00
|
|
|
subscription: (cb)->
|
2018-08-31 06:23:44 -04:00
|
|
|
SubscriptionLocator.getUsersSubscription user._id, cb
|
2018-05-31 11:15:47 -04:00
|
|
|
|
|
|
|
async.series jobs, (err, results)->
|
|
|
|
{ partOfGroup, subscription } = results
|
|
|
|
if partOfGroup
|
|
|
|
return res.redirect("/user/subscription/custom_account")
|
|
|
|
else
|
|
|
|
res.render "subscriptions/domain/join",
|
|
|
|
title: "Group Invitation"
|
|
|
|
group_subscription_id: licence.group_subscription_id
|
|
|
|
licenceName: licence.name
|
|
|
|
has_personal_subscription: subscription?
|
|
|
|
|
2018-06-06 07:49:02 -04:00
|
|
|
createInvite: (req, res, next)->
|
2018-05-31 11:15:47 -04:00
|
|
|
user = AuthenticationController.getSessionUser(req)
|
|
|
|
licence = SubscriptionDomainHandler.getLicenceUserCanJoin(user)
|
|
|
|
|
|
|
|
if !licence?
|
|
|
|
return ErrorsController.notFound(req, res)
|
|
|
|
|
|
|
|
TeamInvitesHandler.createDomainInvite user, licence, (err) ->
|
|
|
|
if err?
|
2018-06-06 07:49:02 -04:00
|
|
|
next(err)
|
2018-05-31 11:15:47 -04:00
|
|
|
else
|
|
|
|
res.sendStatus 200
|