overleaf/services/web/app/coffee/Features/Subscription/TeamInvitesController.coffee

57 lines
1.7 KiB
CoffeeScript
Raw Normal View History

2018-05-31 06:54:50 -04:00
settings = require "settings-sharelatex"
logger = require("logger-sharelatex")
TeamInvitesHandler = require('./TeamInvitesHandler')
AuthenticationController = require("../Authentication/AuthenticationController")
SubscriptionLocator = require("./SubscriptionLocator")
2018-05-30 08:06:27 -04:00
ErrorController = require("../Errors/ErrorController")
module.exports =
createInvite: (req, res, next) ->
2018-05-31 06:54:50 -04:00
teamManagerId = AuthenticationController.getLoggedInUserId(req)
email = req.body.email
2018-05-31 06:54:50 -04:00
TeamInvitesHandler.createInvite teamManagerId, email, (err, invite) ->
next(err) if err?
inviteView = { user:
{ email: invite.email, sentAt: invite.sentAt, holdingAccount: true }
}
res.json inviteView
2018-05-30 08:06:27 -04:00
viewInvite: (req, res, next) ->
token = req.params.token
userId = AuthenticationController.getLoggedInUserId(req)
TeamInvitesHandler.getInvite token, (err, invite, teamSubscription) ->
next(err) if err?
2018-05-30 08:06:27 -04:00
unless invite?
return ErrorController.notFound(req, res, next)
SubscriptionLocator.getUsersSubscription userId, (err, personalSubscription) ->
return callback(err) if err?
res.render "subscriptions/team/invite",
inviterName: invite.inviterName
inviteToken: invite.token
hasPersonalSubscription: personalSubscription?
appName: settings.appName
2018-05-30 08:06:27 -04:00
2018-05-31 06:54:50 -04:00
acceptInvite: (req, res, next) ->
token = req.params.token
userId = AuthenticationController.getLoggedInUserId(req)
TeamInvitesHandler.acceptInvite token, userId, (err, results) ->
next(err) if err?
res.sendStatus 204
revokeInvite: (req, res) ->
2018-05-31 06:54:50 -04:00
email = req.params.email
teamManagerId = AuthenticationController.getLoggedInUserId(req)
TeamInvitesHandler.revokeInvite teamManagerId, email, (err, results) ->
next(err) if err?
res.sendStatus 204