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

54 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-06-07 10:35:18 -04:00
TeamInvitesHandler.createInvite teamManagerId, email, (err, invite) ->
return next(err) if err?
inviteView = { user:
{ email: invite.email, sentAt: invite.sentAt, invite: 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) ->
return next(err) if err?
2018-05-31 11:42:09 -04:00
if !invite
2018-05-30 08:06:27 -04:00
return ErrorController.notFound(req, res, next)
SubscriptionLocator.getUsersSubscription userId, (err, personalSubscription) ->
return next(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) ->
return next(err) if err?
2018-06-07 10:05:04 -04:00
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) ->
return next(err) if err?
2018-05-31 06:54:50 -04:00
res.sendStatus 204