mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
5d8b8ff012
Only prompt for group cancellation if group is personal when accepting invite GitOrigin-RevId: 921807b25d64f037859d303e28c40cdc12eb7685
70 lines
2.4 KiB
CoffeeScript
70 lines
2.4 KiB
CoffeeScript
settings = require "settings-sharelatex"
|
|
logger = require("logger-sharelatex")
|
|
TeamInvitesHandler = require('./TeamInvitesHandler')
|
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
|
SubscriptionLocator = require("./SubscriptionLocator")
|
|
ErrorController = require("../Errors/ErrorController")
|
|
EmailHelper = require("../Helpers/EmailHelper")
|
|
|
|
module.exports =
|
|
createInvite: (req, res, next) ->
|
|
teamManagerId = AuthenticationController.getLoggedInUserId(req)
|
|
subscription = req.entity
|
|
email = EmailHelper.parseEmail(req.body.email)
|
|
if !email?
|
|
return res.status(422).json error:
|
|
code: 'invalid_email'
|
|
message: req.i18n.translate('invalid_email')
|
|
|
|
|
|
TeamInvitesHandler.createInvite teamManagerId, subscription, email, (err, invite) ->
|
|
return next(err) if err?
|
|
inviteView = { user:
|
|
{ email: invite.email, sentAt: invite.sentAt, invite: true }
|
|
}
|
|
res.json inviteView
|
|
|
|
viewInvite: (req, res, next) ->
|
|
token = req.params.token
|
|
userId = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
TeamInvitesHandler.getInvite token, (err, invite, teamSubscription) ->
|
|
return next(err) if err?
|
|
|
|
if !invite
|
|
return ErrorController.notFound(req, res, next)
|
|
|
|
SubscriptionLocator.getUsersSubscription userId, (err, personalSubscription) ->
|
|
return next(err) if err?
|
|
|
|
hasIndividualRecurlySubscription =
|
|
personalSubscription? &&
|
|
!personalSubscription.planCode.match(/(free|trial)/)? &&
|
|
personalSubscription.groupPlan == false &&
|
|
personalSubscription.recurlySubscription_id? &&
|
|
personalSubscription.recurlySubscription_id != ""
|
|
|
|
res.render "subscriptions/team/invite",
|
|
inviterName: invite.inviterName
|
|
inviteToken: invite.token
|
|
hasIndividualRecurlySubscription: hasIndividualRecurlySubscription
|
|
appName: settings.appName
|
|
|
|
acceptInvite: (req, res, next) ->
|
|
token = req.params.token
|
|
userId = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
TeamInvitesHandler.acceptInvite token, userId, (err, results) ->
|
|
return next(err) if err?
|
|
res.sendStatus 204
|
|
|
|
revokeInvite: (req, res) ->
|
|
subscription = req.entity
|
|
email = EmailHelper.parseEmail(req.params.email)
|
|
teamManagerId = AuthenticationController.getLoggedInUserId(req)
|
|
if !email?
|
|
return res.sendStatus(400)
|
|
|
|
TeamInvitesHandler.revokeInvite teamManagerId, subscription, email, (err, results) ->
|
|
return next(err) if err?
|
|
res.sendStatus 204
|