2019-05-29 05:21:06 -04:00
|
|
|
const SubscriptionGroupHandler = require('./SubscriptionGroupHandler')
|
2020-08-19 05:11:32 -04:00
|
|
|
const OError = require('@overleaf/o-error')
|
2021-11-10 08:40:18 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2019-05-29 05:21:06 -04:00
|
|
|
const SubscriptionLocator = require('./SubscriptionLocator')
|
2021-07-28 04:51:20 -04:00
|
|
|
const SessionManager = require('../Authentication/SessionManager')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2022-05-12 06:27:31 -04:00
|
|
|
function removeUserFromGroup(req, res, next) {
|
|
|
|
const subscription = req.entity
|
|
|
|
const userToRemoveId = req.params.user_id
|
2022-05-16 08:38:18 -04:00
|
|
|
logger.debug(
|
2022-05-12 06:27:31 -04:00
|
|
|
{ subscriptionId: subscription._id, userToRemove_id: userToRemoveId },
|
|
|
|
'removing user from group subscription'
|
|
|
|
)
|
|
|
|
SubscriptionGroupHandler.removeUserFromGroup(
|
|
|
|
subscription._id,
|
|
|
|
userToRemoveId,
|
|
|
|
function (error) {
|
|
|
|
if (error) {
|
|
|
|
OError.tag(error, 'error removing user from group', {
|
|
|
|
subscriptionId: subscription._id,
|
|
|
|
userToRemove_id: userToRemoveId,
|
|
|
|
})
|
|
|
|
return next(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
2022-05-12 06:27:31 -04:00
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2019-11-19 09:19:08 -05:00
|
|
|
|
2022-05-12 06:27:31 -04:00
|
|
|
function removeSelfFromGroup(req, res, next) {
|
|
|
|
const subscriptionId = req.query.subscriptionId
|
|
|
|
const userToRemoveId = SessionManager.getLoggedInUserId(req.session)
|
|
|
|
SubscriptionLocator.getSubscription(
|
|
|
|
subscriptionId,
|
|
|
|
function (error, subscription) {
|
|
|
|
if (error) {
|
|
|
|
return next(error)
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
2022-05-12 06:27:31 -04:00
|
|
|
|
|
|
|
SubscriptionGroupHandler.removeUserFromGroup(
|
|
|
|
subscription._id,
|
|
|
|
userToRemoveId,
|
|
|
|
function (error) {
|
|
|
|
if (error) {
|
|
|
|
logger.err(
|
|
|
|
{ err: error, userToRemove_id: userToRemoveId, subscriptionId },
|
|
|
|
'error removing self from group'
|
|
|
|
)
|
|
|
|
return res.sendStatus(500)
|
|
|
|
}
|
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
removeUserFromGroup,
|
|
|
|
removeSelfFromGroup,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|