mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
e9e429d339
[web] Decaf cleanup SubscriptionGroupController GitOrigin-RevId: eb407c52e77db50481356c342fc685f30145fc23
62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
const SubscriptionGroupHandler = require('./SubscriptionGroupHandler')
|
|
const OError = require('@overleaf/o-error')
|
|
const logger = require('@overleaf/logger')
|
|
const SubscriptionLocator = require('./SubscriptionLocator')
|
|
const SessionManager = require('../Authentication/SessionManager')
|
|
|
|
function removeUserFromGroup(req, res, next) {
|
|
const subscription = req.entity
|
|
const userToRemoveId = req.params.user_id
|
|
logger.log(
|
|
{ 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)
|
|
}
|
|
|
|
res.sendStatus(200)
|
|
}
|
|
)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
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,
|
|
}
|