2014-02-12 05:23:40 -05:00
|
|
|
SubscriptionGroupHandler = require("./SubscriptionGroupHandler")
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
SubscriptionLocator = require("./SubscriptionLocator")
|
2016-09-05 10:58:31 -04:00
|
|
|
AuthenticationController = require('../Authentication/AuthenticationController')
|
2015-05-27 10:50:28 -04:00
|
|
|
_ = require("underscore")
|
2016-03-22 12:59:47 -04:00
|
|
|
async = require("async")
|
2015-05-22 08:57:15 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
module.exports =
|
|
|
|
|
2018-07-11 04:31:57 -04:00
|
|
|
removeUserFromGroup: (req, res, next)->
|
2018-10-25 11:10:02 -04:00
|
|
|
subscription = req.entity
|
2014-02-12 05:23:40 -05:00
|
|
|
userToRemove_id = req.params.user_id
|
2018-10-25 11:10:02 -04:00
|
|
|
logger.log subscriptionId: subscription._id, userToRemove_id:userToRemove_id, "removing user from group subscription"
|
|
|
|
SubscriptionGroupHandler.removeUserFromGroup subscription._id, userToRemove_id, (err)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, adminUserId:adminUserId, userToRemove_id:userToRemove_id, "error removing user from group"
|
|
|
|
return next(err)
|
|
|
|
res.send()
|
2016-09-05 10:58:31 -04:00
|
|
|
|
2018-07-11 04:31:57 -04:00
|
|
|
removeSelfFromGroup: (req, res, next)->
|
2016-02-19 07:27:01 -05:00
|
|
|
adminUserId = req.query.admin_user_id
|
2016-09-05 10:58:31 -04:00
|
|
|
userToRemove_id = AuthenticationController.getLoggedInUserId(req)
|
2018-07-13 06:47:26 -04:00
|
|
|
getManagedSubscription adminUserId, (error, subscription) ->
|
2018-07-11 04:31:57 -04:00
|
|
|
return next(error) if error?
|
|
|
|
logger.log adminUserId:adminUserId, userToRemove_id:userToRemove_id, "removing user from group subscription after self request"
|
|
|
|
SubscriptionGroupHandler.removeUserFromGroup subscription._id, userToRemove_id, (err)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, userToRemove_id:userToRemove_id, adminUserId:adminUserId, "error removing self from group"
|
|
|
|
return res.sendStatus 500
|
|
|
|
res.send()
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-10-11 13:56:14 -04:00
|
|
|
# legacy route
|
2018-10-24 09:50:55 -04:00
|
|
|
redirectToSubscriptionGroupAdminPage: (req, res, next) ->
|
2018-10-11 13:56:14 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
getManagedSubscription user_id, (error, subscription) ->
|
|
|
|
return next(error) if error?
|
|
|
|
if !subscription?.groupPlan
|
|
|
|
return res.redirect("/user/subscription")
|
|
|
|
res.redirect("/manage/groups/#{subscription._id}/members")
|
2018-07-13 06:47:26 -04:00
|
|
|
|
|
|
|
getManagedSubscription = (managerId, callback) ->
|
|
|
|
SubscriptionLocator.findManagedSubscription managerId, (err, subscription)->
|
|
|
|
if subscription?
|
|
|
|
logger.log managerId: managerId, "got managed subscription"
|
|
|
|
else
|
|
|
|
err ||= new Error("No subscription found managed by user #{managerId}")
|
|
|
|
|
|
|
|
return callback(err, subscription)
|