Merge pull request #16550 from overleaf/ab-unlink-sso-user-leaves-group
[web] Unlink group SSO when user leaves/is removed from group GitOrigin-RevId: a4515f8b6f0f0012fc4d9f47b11e6f711743c2ec
This commit is contained in:
committed by
Copybot
parent
bc86ada5be
commit
73349a1b1d
@@ -3,65 +3,58 @@ const SubscriptionUpdater = require('./SubscriptionUpdater')
|
||||
const SubscriptionLocator = require('./SubscriptionLocator')
|
||||
const { Subscription } = require('../../models/Subscription')
|
||||
|
||||
const SubscriptionGroupHandler = {
|
||||
removeUserFromGroup(subscriptionId, userIdToRemove, callback) {
|
||||
SubscriptionUpdater.removeUserFromGroup(
|
||||
subscriptionId,
|
||||
userIdToRemove,
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
replaceUserReferencesInGroups(oldId, newId, callback) {
|
||||
Subscription.updateOne(
|
||||
{ admin_id: oldId },
|
||||
{ admin_id: newId },
|
||||
function (error) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
|
||||
replaceInArray(
|
||||
Subscription,
|
||||
'manager_ids',
|
||||
oldId,
|
||||
newId,
|
||||
function (error) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
|
||||
replaceInArray(Subscription, 'member_ids', oldId, newId, callback)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
isUserPartOfGroup(userId, subscriptionId, callback) {
|
||||
SubscriptionLocator.getSubscriptionByMemberIdAndId(
|
||||
userId,
|
||||
subscriptionId,
|
||||
function (err, subscription) {
|
||||
let partOfGroup
|
||||
if (subscription) {
|
||||
partOfGroup = true
|
||||
} else {
|
||||
partOfGroup = false
|
||||
}
|
||||
callback(err, partOfGroup)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
getTotalConfirmedUsersInGroup(subscriptionId, callback) {
|
||||
SubscriptionLocator.getSubscription(subscriptionId, (err, subscription) =>
|
||||
callback(err, subscription?.member_ids?.length)
|
||||
)
|
||||
},
|
||||
function removeUserFromGroup(subscriptionId, userIdToRemove, callback) {
|
||||
SubscriptionUpdater.removeUserFromGroup(
|
||||
subscriptionId,
|
||||
userIdToRemove,
|
||||
callback
|
||||
)
|
||||
}
|
||||
|
||||
function replaceInArray(model, property, oldValue, newValue, callback) {
|
||||
function replaceUserReferencesInGroups(oldId, newId, callback) {
|
||||
Subscription.updateOne(
|
||||
{ admin_id: oldId },
|
||||
{ admin_id: newId },
|
||||
function (error) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
|
||||
_replaceInArray(
|
||||
Subscription,
|
||||
'manager_ids',
|
||||
oldId,
|
||||
newId,
|
||||
function (error) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
|
||||
_replaceInArray(Subscription, 'member_ids', oldId, newId, callback)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function isUserPartOfGroup(userId, subscriptionId, callback) {
|
||||
SubscriptionLocator.getSubscriptionByMemberIdAndId(
|
||||
userId,
|
||||
subscriptionId,
|
||||
function (err, subscription) {
|
||||
const partOfGroup = !!subscription
|
||||
callback(err, partOfGroup)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function getTotalConfirmedUsersInGroup(subscriptionId, callback) {
|
||||
SubscriptionLocator.getSubscription(subscriptionId, (err, subscription) =>
|
||||
callback(err, subscription?.member_ids?.length)
|
||||
)
|
||||
}
|
||||
|
||||
function _replaceInArray(model, property, oldValue, newValue, callback) {
|
||||
// Mongo won't let us pull and addToSet in the same query, so do it in
|
||||
// two. Note we need to add first, since the query is based on the old user.
|
||||
const query = {}
|
||||
@@ -81,11 +74,15 @@ function replaceInArray(model, property, oldValue, newValue, callback) {
|
||||
})
|
||||
}
|
||||
|
||||
SubscriptionGroupHandler.promises = {
|
||||
getTotalConfirmedUsersInGroup: promisify(
|
||||
SubscriptionGroupHandler.getTotalConfirmedUsersInGroup
|
||||
),
|
||||
isUserPartOfGroup: promisify(SubscriptionGroupHandler.isUserPartOfGroup),
|
||||
module.exports = {
|
||||
removeUserFromGroup,
|
||||
replaceUserReferencesInGroups,
|
||||
getTotalConfirmedUsersInGroup,
|
||||
isUserPartOfGroup,
|
||||
promises: {
|
||||
removeUserFromGroup: promisify(removeUserFromGroup),
|
||||
replaceUserReferencesInGroups: promisify(replaceUserReferencesInGroups),
|
||||
getTotalConfirmedUsersInGroup: promisify(getTotalConfirmedUsersInGroup),
|
||||
isUserPartOfGroup: promisify(isUserPartOfGroup),
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = SubscriptionGroupHandler
|
||||
|
||||
Reference in New Issue
Block a user