fix: oidc module - map() call on undefined; fix unrelate() usage (#5781)

pull/5791/head
Andrei Senchuk 2 years ago committed by GitHub
parent 98e199a009
commit e6bbf9d088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,13 +32,13 @@ module.exports = {
if (conf.mapGroups) { if (conf.mapGroups) {
const groups = _.get(profile, '_json.' + conf.groupsClaim) const groups = _.get(profile, '_json.' + conf.groupsClaim)
if (groups && _.isArray(groups)) { if (groups && _.isArray(groups)) {
const currentGroups = (await user.$relatedQuery('groups').select('groups.id')).groups.map(g => g.id) const currentGroups = (await user.$relatedQuery('groups').select('groups.id')).map(g => g.id)
const expectedGroups = Object.values(WIKI.auth.groups).filter(g => groups.includes(g.name)).map(g => g.id) const expectedGroups = Object.values(WIKI.auth.groups).filter(g => groups.includes(g.name)).map(g => g.id)
for (const groupId of _.difference(expectedGroups, currentGroups)) { for (const groupId of _.difference(expectedGroups, currentGroups)) {
await user.$relatedQuery('groups').relate(groupId) await user.$relatedQuery('groups').relate(groupId)
} }
for (const groupId of _.difference(currentGroups, expectedGroups)) { for (const groupId of _.difference(currentGroups, expectedGroups)) {
await user.$relatedQuery('groups').unrelate(groupId) await user.$relatedQuery('groups').unrelate().where('groupId', groupId)
} }
} }
} }

Loading…
Cancel
Save