mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #18045 from overleaf/jel-user-settings-sso-groups
[web] Use `getUserGroupsSSOEnrollmentStatus` helper GitOrigin-RevId: 4846d513964a63afb620ee2dbb5b810dd0aa4e60
This commit is contained in:
parent
e443413c12
commit
0b86bc04ad
2 changed files with 21 additions and 37 deletions
|
@ -111,26 +111,24 @@ async function settingsPage(req, res) {
|
|||
logger.error({ err }, 'error getting subscription admin email')
|
||||
}
|
||||
|
||||
const memberOfSSOEnabledGroups = []
|
||||
let memberOfSSOEnabledGroups = []
|
||||
try {
|
||||
const memberOfGroups =
|
||||
await SubscriptionLocator.promises.getMemberSubscriptions(user._id)
|
||||
for (const group of memberOfGroups) {
|
||||
const hasSSOEnabled = (
|
||||
await Modules.promises.hooks.fire('hasGroupSSOEnabled', group)
|
||||
)?.[0]
|
||||
if (hasSSOEnabled) {
|
||||
const groupId = group._id.toString()
|
||||
memberOfSSOEnabledGroups.push({
|
||||
groupId,
|
||||
linked: user.enrollment?.sso?.some(
|
||||
sso => sso.groupId.toString() === groupId
|
||||
),
|
||||
groupName: group.teamName,
|
||||
adminEmail: group.admin_id?.email,
|
||||
})
|
||||
memberOfSSOEnabledGroups = (
|
||||
await Modules.promises.hooks.fire(
|
||||
'getUserGroupsSSOEnrollmentStatus',
|
||||
user._id,
|
||||
{ teamName: 1 },
|
||||
['email']
|
||||
)
|
||||
)?.[0]
|
||||
memberOfSSOEnabledGroups = memberOfSSOEnabledGroups.map(group => {
|
||||
return {
|
||||
groupId: group._id.toString(),
|
||||
linked: group.linked,
|
||||
groupName: group.teamName,
|
||||
adminEmail: group.admin_id?.email,
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
{ err: error },
|
||||
|
|
|
@ -365,33 +365,19 @@ describe('UserPagesController', function () {
|
|||
admin_id: {
|
||||
email: 'admin.email@ssolove.com',
|
||||
},
|
||||
linked: true,
|
||||
}
|
||||
const group2 = {
|
||||
_id: 'def456def456',
|
||||
admin_id: {
|
||||
email: 'someone.else@noname.co.uk',
|
||||
},
|
||||
linked: false,
|
||||
}
|
||||
const group3 = {
|
||||
_id: 'fff999fff999',
|
||||
admin_id: {
|
||||
email: 'foo@bar.baz',
|
||||
},
|
||||
}
|
||||
this.SubscriptionLocator.promises.getMemberSubscriptions.resolves([
|
||||
group1,
|
||||
group2,
|
||||
group3,
|
||||
])
|
||||
|
||||
this.Modules.promises.hooks.fire
|
||||
.withArgs('hasGroupSSOEnabled', group1)
|
||||
.resolves([true])
|
||||
this.Modules.promises.hooks.fire
|
||||
.withArgs('hasGroupSSOEnabled', group2)
|
||||
.resolves([true])
|
||||
this.Modules.promises.hooks.fire
|
||||
.withArgs('hasGroupSSOEnabled', group3)
|
||||
.resolves([false])
|
||||
.withArgs('getUserGroupsSSOEnrollmentStatus')
|
||||
.resolves([[group1, group2]])
|
||||
|
||||
this.res.callback = () => {
|
||||
expect(
|
||||
|
|
Loading…
Reference in a new issue