2014-02-12 05:23:40 -05:00
|
|
|
SubscriptionGroupHandler = require("./SubscriptionGroupHandler")
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
SubscriptionLocator = require("./SubscriptionLocator")
|
|
|
|
|
2015-05-27 15:50:16 -04:00
|
|
|
ErrorsController = require("../Errors/ErrorController")
|
2015-05-22 08:57:15 -04:00
|
|
|
settings = require("settings-sharelatex")
|
2015-05-27 15:50:16 -04:00
|
|
|
|
2015-05-27 15:57:54 -04:00
|
|
|
SubscriptionDomainHandler = require("./SubscriptionDomainHandler")
|
2015-05-27 10:50:28 -04:00
|
|
|
_ = require("underscore")
|
2015-05-22 08:57:15 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
module.exports =
|
|
|
|
|
|
|
|
addUserToGroup: (req, res)->
|
|
|
|
adminUserId = req.session.user._id
|
|
|
|
newEmail = req.body.email
|
|
|
|
logger.log adminUserId:adminUserId, newEmail:newEmail, "adding user to group subscription"
|
|
|
|
SubscriptionGroupHandler.addUserToGroup adminUserId, newEmail, (err, user)->
|
|
|
|
result =
|
|
|
|
user:user
|
|
|
|
if err and err.limitReached
|
|
|
|
result.limitReached = true
|
|
|
|
res.json(result)
|
|
|
|
|
|
|
|
removeUserFromGroup: (req, res)->
|
|
|
|
adminUserId = req.session.user._id
|
|
|
|
userToRemove_id = req.params.user_id
|
|
|
|
logger.log adminUserId:adminUserId, userToRemove_id:userToRemove_id, "removing user from group subscription"
|
|
|
|
SubscriptionGroupHandler.removeUserFromGroup adminUserId, userToRemove_id, ->
|
|
|
|
res.send()
|
|
|
|
|
|
|
|
renderSubscriptionGroupAdminPage: (req, res)->
|
|
|
|
user_id = req.session.user._id
|
|
|
|
SubscriptionLocator.getUsersSubscription user_id, (err, subscription)->
|
|
|
|
if !subscription.groupPlan
|
|
|
|
return res.redirect("/")
|
|
|
|
SubscriptionGroupHandler.getPopulatedListOfMembers user_id, (err, users)->
|
|
|
|
res.render "subscriptions/group_admin",
|
2014-08-01 08:47:14 -04:00
|
|
|
title: 'group_admin'
|
2014-02-12 05:23:40 -05:00
|
|
|
users: users
|
|
|
|
subscription: subscription
|
2015-05-22 08:57:15 -04:00
|
|
|
|
|
|
|
renderGroupInvitePage: (req, res)->
|
|
|
|
subscription_id = req.params.subscription_id
|
2015-05-27 11:33:47 -04:00
|
|
|
user_id = req.session.user._id
|
2015-05-27 15:57:54 -04:00
|
|
|
licence = SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)
|
2015-05-27 15:50:16 -04:00
|
|
|
if !licence?
|
|
|
|
return ErrorsController.notFound(req, res)
|
2015-05-27 11:33:47 -04:00
|
|
|
SubscriptionGroupHandler.isUserPartOfGroup user_id, licence.subscription_id, (err, partOfGroup)->
|
|
|
|
if partOfGroup
|
2015-05-27 10:50:28 -04:00
|
|
|
return res.redirect("/user/subscription/custom_account")
|
2015-05-27 11:33:47 -04:00
|
|
|
else
|
|
|
|
res.render "subscriptions/group/invite",
|
|
|
|
title: "Group Invitation"
|
|
|
|
subscription_id:subscription_id
|
|
|
|
licenceName:licence.name
|
2015-05-22 08:57:15 -04:00
|
|
|
|
|
|
|
beginJoinGroup: (req, res)->
|
|
|
|
subscription_id = req.params.subscription_id
|
|
|
|
user_id = req.session.user._id
|
2015-05-27 15:57:54 -04:00
|
|
|
licence = SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)
|
2015-05-22 08:57:15 -04:00
|
|
|
if !licence?
|
2015-05-27 15:50:16 -04:00
|
|
|
return ErrorsController.notFound(req, res)
|
|
|
|
SubscriptionGroupHandler.sendVerificationEmail subscription_id, licence.name, req.session.user.email, (err)->
|
|
|
|
if err?
|
|
|
|
res.send 500
|
|
|
|
else
|
2015-05-22 08:57:15 -04:00
|
|
|
res.send 200
|
|
|
|
|
|
|
|
completeJoin: (req, res)->
|
|
|
|
subscription_id = req.params.subscription_id
|
2015-05-27 15:57:54 -04:00
|
|
|
if !SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)?
|
2015-05-27 15:50:16 -04:00
|
|
|
return ErrorsController.notFound(req, res)
|
|
|
|
SubscriptionGroupHandler.processGroupVerification req.session.user.email, subscription_id, req.query.token, (err)->
|
2015-06-01 07:43:42 -04:00
|
|
|
if err? and err == "token_not_found"
|
|
|
|
res.redirect "/user/subscription/#{subscription_id}/group/invited?expired=true"
|
|
|
|
else if err?
|
2015-05-27 15:50:16 -04:00
|
|
|
res.send 500
|
|
|
|
else
|
|
|
|
res.redirect "/user/subscription/#{subscription_id}/group/successful-join"
|
2015-05-22 08:57:15 -04:00
|
|
|
|
2015-05-26 10:25:46 -04:00
|
|
|
renderSuccessfulJoinPage: (req, res)->
|
|
|
|
subscription_id = req.params.subscription_id
|
2015-05-27 15:57:54 -04:00
|
|
|
licence = SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)
|
|
|
|
if !SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)?
|
2015-05-27 15:50:16 -04:00
|
|
|
return ErrorsController.notFound(req, res)
|
2015-05-26 10:25:46 -04:00
|
|
|
res.render "subscriptions/group/successful_join",
|
|
|
|
title: "Sucessfully joined group"
|
|
|
|
licenceName:licence.name
|
2015-05-22 08:57:15 -04:00
|
|
|
|
2015-05-28 15:54:41 -04:00
|
|
|
exportGroupCsv: (req, res)->
|
|
|
|
user_id = req.session.user._id
|
|
|
|
logger.log user_id: user_id, "exporting group csv"
|
|
|
|
SubscriptionLocator.getUsersSubscription user_id, (err, subscription)->
|
|
|
|
if !subscription.groupPlan
|
|
|
|
return res.redirect("/")
|
|
|
|
SubscriptionGroupHandler.getPopulatedListOfMembers user_id, (err, users)->
|
|
|
|
groupCsv = ""
|
|
|
|
for user in users
|
|
|
|
groupCsv += user.email + "\n"
|
|
|
|
res.header(
|
|
|
|
"Content-Disposition",
|
|
|
|
"attachment; filename=Group.csv"
|
|
|
|
)
|
|
|
|
res.contentType('text/csv')
|
|
|
|
res.send(groupCsv)
|