2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
max-len,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const SubscriptionGroupHandler = require('./SubscriptionGroupHandler')
|
2020-08-19 05:11:32 -04:00
|
|
|
const OError = require('@overleaf/o-error')
|
2019-05-29 05:21:06 -04:00
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
const SubscriptionLocator = require('./SubscriptionLocator')
|
|
|
|
const AuthenticationController = require('../Authentication/AuthenticationController')
|
|
|
|
const _ = require('underscore')
|
|
|
|
const async = require('async')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
removeUserFromGroup(req, res, next) {
|
|
|
|
const subscription = req.entity
|
|
|
|
const userToRemove_id = req.params.user_id
|
|
|
|
logger.log(
|
|
|
|
{ subscriptionId: subscription._id, userToRemove_id },
|
|
|
|
'removing user from group subscription'
|
|
|
|
)
|
|
|
|
return SubscriptionGroupHandler.removeUserFromGroup(
|
|
|
|
subscription._id,
|
|
|
|
userToRemove_id,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (err) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
2020-08-19 05:11:32 -04:00
|
|
|
OError.tag(err, 'error removing user from group', {
|
|
|
|
subscriptionId: subscription._id,
|
2021-04-27 03:52:58 -04:00
|
|
|
userToRemove_id,
|
2020-08-19 05:11:32 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
return next(err)
|
|
|
|
}
|
2020-05-06 06:02:16 -04:00
|
|
|
return res.sendStatus(200)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
removeSelfFromGroup(req, res, next) {
|
2020-08-12 10:17:15 -04:00
|
|
|
const subscriptionId = req.query.subscriptionId
|
2019-05-29 05:21:06 -04:00
|
|
|
const userToRemove_id = AuthenticationController.getLoggedInUserId(req)
|
2021-04-14 09:17:21 -04:00
|
|
|
return SubscriptionLocator.getSubscription(
|
|
|
|
subscriptionId,
|
|
|
|
function (error, subscription) {
|
|
|
|
if (error != null) {
|
|
|
|
return next(error)
|
|
|
|
}
|
2019-11-19 09:19:08 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return SubscriptionGroupHandler.removeUserFromGroup(
|
|
|
|
subscription._id,
|
|
|
|
userToRemove_id,
|
|
|
|
function (err) {
|
|
|
|
if (err != null) {
|
|
|
|
logger.err(
|
|
|
|
{ err, userToRemove_id, subscriptionId },
|
|
|
|
'error removing self from group'
|
|
|
|
)
|
|
|
|
return res.sendStatus(500)
|
|
|
|
}
|
|
|
|
return res.sendStatus(200)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|