2018-05-31 06:54:50 -04:00
|
|
|
settings = require "settings-sharelatex"
|
2018-05-30 06:29:21 -04:00
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
TeamInvitesHandler = require('./TeamInvitesHandler')
|
|
|
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
2018-05-31 11:15:47 -04:00
|
|
|
SubscriptionLocator = require("./SubscriptionLocator")
|
2018-05-30 08:06:27 -04:00
|
|
|
ErrorController = require("../Errors/ErrorController")
|
2018-06-11 10:22:42 -04:00
|
|
|
EmailHelper = require("../Helpers/EmailHelper")
|
2018-05-30 06:29:21 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
createInvite: (req, res, next) ->
|
2018-05-31 06:54:50 -04:00
|
|
|
teamManagerId = AuthenticationController.getLoggedInUserId(req)
|
2018-06-11 10:22:42 -04:00
|
|
|
email = EmailHelper.parseEmail(req.body.email)
|
|
|
|
if !email?
|
|
|
|
return res.sendStatus(400)
|
2018-05-30 06:29:21 -04:00
|
|
|
|
2018-06-07 10:35:18 -04:00
|
|
|
TeamInvitesHandler.createInvite teamManagerId, email, (err, invite) ->
|
2018-06-11 09:20:35 -04:00
|
|
|
return next(err) if err?
|
2018-05-30 06:29:21 -04:00
|
|
|
inviteView = { user:
|
2018-06-07 09:10:01 -04:00
|
|
|
{ email: invite.email, sentAt: invite.sentAt, invite: true }
|
2018-05-30 06:29:21 -04:00
|
|
|
}
|
|
|
|
res.json inviteView
|
|
|
|
|
2018-05-30 08:06:27 -04:00
|
|
|
viewInvite: (req, res, next) ->
|
|
|
|
token = req.params.token
|
|
|
|
userId = AuthenticationController.getLoggedInUserId(req)
|
2018-05-30 06:29:21 -04:00
|
|
|
|
2018-05-31 11:15:47 -04:00
|
|
|
TeamInvitesHandler.getInvite token, (err, invite, teamSubscription) ->
|
2018-06-11 09:20:35 -04:00
|
|
|
return next(err) if err?
|
2018-05-30 06:29:21 -04:00
|
|
|
|
2018-05-31 11:42:09 -04:00
|
|
|
if !invite
|
2018-05-30 08:06:27 -04:00
|
|
|
return ErrorController.notFound(req, res, next)
|
|
|
|
|
2018-05-31 11:15:47 -04:00
|
|
|
SubscriptionLocator.getUsersSubscription userId, (err, personalSubscription) ->
|
2018-06-11 09:20:35 -04:00
|
|
|
return next(err) if err?
|
2018-05-31 11:15:47 -04:00
|
|
|
|
|
|
|
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) ->
|
2018-06-11 09:20:35 -04:00
|
|
|
return next(err) if err?
|
2018-06-07 10:05:04 -04:00
|
|
|
res.sendStatus 204
|
2018-05-30 06:29:21 -04:00
|
|
|
|
|
|
|
revokeInvite: (req, res) ->
|
2018-06-11 10:22:42 -04:00
|
|
|
email = EmailHelper.parseEmail(req.params.email)
|
2018-05-31 06:54:50 -04:00
|
|
|
teamManagerId = AuthenticationController.getLoggedInUserId(req)
|
2018-06-11 10:22:42 -04:00
|
|
|
if !email?
|
|
|
|
return res.sendStatus(400)
|
2018-05-31 06:54:50 -04:00
|
|
|
|
|
|
|
TeamInvitesHandler.revokeInvite teamManagerId, email, (err, results) ->
|
2018-06-11 09:20:35 -04:00
|
|
|
return next(err) if err?
|
2018-05-31 06:54:50 -04:00
|
|
|
res.sendStatus 204
|