mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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')
|
logger.error({ err }, 'error getting subscription admin email')
|
||||||
}
|
}
|
||||||
|
|
||||||
const memberOfSSOEnabledGroups = []
|
let memberOfSSOEnabledGroups = []
|
||||||
try {
|
try {
|
||||||
const memberOfGroups =
|
memberOfSSOEnabledGroups = (
|
||||||
await SubscriptionLocator.promises.getMemberSubscriptions(user._id)
|
await Modules.promises.hooks.fire(
|
||||||
for (const group of memberOfGroups) {
|
'getUserGroupsSSOEnrollmentStatus',
|
||||||
const hasSSOEnabled = (
|
user._id,
|
||||||
await Modules.promises.hooks.fire('hasGroupSSOEnabled', group)
|
{ teamName: 1 },
|
||||||
)?.[0]
|
['email']
|
||||||
if (hasSSOEnabled) {
|
)
|
||||||
const groupId = group._id.toString()
|
)?.[0]
|
||||||
memberOfSSOEnabledGroups.push({
|
memberOfSSOEnabledGroups = memberOfSSOEnabledGroups.map(group => {
|
||||||
groupId,
|
return {
|
||||||
linked: user.enrollment?.sso?.some(
|
groupId: group._id.toString(),
|
||||||
sso => sso.groupId.toString() === groupId
|
linked: group.linked,
|
||||||
),
|
groupName: group.teamName,
|
||||||
groupName: group.teamName,
|
adminEmail: group.admin_id?.email,
|
||||||
adminEmail: group.admin_id?.email,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
{ err: error },
|
{ err: error },
|
||||||
|
|
|
@ -365,33 +365,19 @@ describe('UserPagesController', function () {
|
||||||
admin_id: {
|
admin_id: {
|
||||||
email: 'admin.email@ssolove.com',
|
email: 'admin.email@ssolove.com',
|
||||||
},
|
},
|
||||||
|
linked: true,
|
||||||
}
|
}
|
||||||
const group2 = {
|
const group2 = {
|
||||||
_id: 'def456def456',
|
_id: 'def456def456',
|
||||||
admin_id: {
|
admin_id: {
|
||||||
email: 'someone.else@noname.co.uk',
|
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
|
this.Modules.promises.hooks.fire
|
||||||
.withArgs('hasGroupSSOEnabled', group1)
|
.withArgs('getUserGroupsSSOEnrollmentStatus')
|
||||||
.resolves([true])
|
.resolves([[group1, group2]])
|
||||||
this.Modules.promises.hooks.fire
|
|
||||||
.withArgs('hasGroupSSOEnabled', group2)
|
|
||||||
.resolves([true])
|
|
||||||
this.Modules.promises.hooks.fire
|
|
||||||
.withArgs('hasGroupSSOEnabled', group3)
|
|
||||||
.resolves([false])
|
|
||||||
|
|
||||||
this.res.callback = () => {
|
this.res.callback = () => {
|
||||||
expect(
|
expect(
|
||||||
|
|
Loading…
Reference in a new issue