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

59 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2018-05-31 10:54:50 +00:00
settings = require "settings-sharelatex"
logger = require("logger-sharelatex")
TeamInvitesHandler = require('./TeamInvitesHandler')
AuthenticationController = require("../Authentication/AuthenticationController")
SubscriptionLocator = require("./SubscriptionLocator")
2018-05-30 12:06:27 +00:00
ErrorController = require("../Errors/ErrorController")
2018-06-11 14:22:42 +00:00
EmailHelper = require("../Helpers/EmailHelper")
module.exports =
createInvite: (req, res, next) ->
2018-05-31 10:54:50 +00:00
teamManagerId = AuthenticationController.getLoggedInUserId(req)
2018-06-11 14:22:42 +00:00
email = EmailHelper.parseEmail(req.body.email)
if !email?
return res.sendStatus(400)
2018-06-07 14:35:18 +00: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 12:06:27 +00: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 15:42:09 +00:00
if !invite
2018-05-30 12:06:27 +00: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 12:06:27 +00:00
2018-05-31 10:54:50 +00: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 14:05:04 +00:00
res.sendStatus 204
revokeInvite: (req, res) ->
2018-06-11 14:22:42 +00:00
email = EmailHelper.parseEmail(req.params.email)
2018-05-31 10:54:50 +00:00
teamManagerId = AuthenticationController.getLoggedInUserId(req)
2018-06-11 14:22:42 +00:00
if !email?
return res.sendStatus(400)
2018-05-31 10:54:50 +00:00
TeamInvitesHandler.revokeInvite teamManagerId, email, (err, results) ->
return next(err) if err?
2018-05-31 10:54:50 +00:00
res.sendStatus 204