Merge pull request #26513 from overleaf/msm-fix-sso-disable-managed-group

[web] Fix disable managed users clears SSO enrollment

GitOrigin-RevId: 75742840b5cee98a203ad11e9213e2e31cf18985
This commit is contained in:
Miguel Serrano
2025-07-11 09:14:21 +02:00
committed by Copybot
parent a0fc3ba9a4
commit 703dde783b
2 changed files with 27 additions and 0 deletions

View File

@@ -88,6 +88,10 @@ class PromisifiedSubscription {
await Modules.promises.hooks.fire('enableManagedUsers', this._id)
}
async disableManagedUsers() {
await Modules.promises.hooks.fire('disableManagedUsers', this._id)
}
async enableFeatureSSO() {
await SubscriptionModel.findOneAndUpdate(
{ _id: new ObjectId(this._id) },

View File

@@ -187,6 +187,29 @@ export async function linkGroupMember(
return userHelper
}
export async function checkUserHasSSOLinked(userId, groupId) {
const internalProviderId = getProviderId(groupId)
const user = await UserGetter.promises.getUser(
{ _id: userId },
{ samlIdentifiers: 1, enrollment: 1 }
)
const { enrollment, samlIdentifiers } = user
const linkedToGroupSSO = samlIdentifiers.some(
identifier => identifier.providerId === internalProviderId
)
if (!linkedToGroupSSO) {
throw new Error('user saml identifiers are not linked to subscription')
}
const userIsEnrolledInSSO = enrollment.sso.some(
sso => sso.groupId.toString() === groupId.toString()
)
if (!userIsEnrolledInSSO) {
throw new Error('user is not enrolled in subscription')
}
}
export async function setConfigAndEnableSSO(
subscriptionHelper,
adminEmailPassword,