Skip to content

Commit

Permalink
Allow admin to be set from SSO group
Browse files Browse the repository at this point in the history
fixes #4085
  • Loading branch information
hardillb committed Jul 22, 2024
1 parent 951e100 commit 36e2493
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions forge/ee/lib/sso/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ module.exports.init = async function (app) {
if (!Array.isArray(groupAssertions)) {
groupAssertions = [groupAssertions]
}
let adminGroup = false
const desiredTeamMemberships = {}
groupAssertions.forEach(ga => {
// Parse the group name - format: 'ff-SLUG-ROLE'
Expand All @@ -321,10 +322,24 @@ module.exports.init = async function (app) {
// ensure we keep the highest level of access
desiredTeamMemberships[teamSlug] = Math.max(desiredTeamMemberships[teamSlug] || 0, teamRole)
}
} else if (teamRole === Roles.Admin) {
adminGroup = true
}
}
})

if (user.admin && !adminGroup) {
if (!Object.hasOwn(desiredTeamMemberships, 'admin')) {
app.auditLog.User.user.updatedUser(0, null, [{ key: 'admin', old: true, new: false }], user)
user.admin = false
await user.save()
}
} else if (adminGroup && !user.admin) {
app.auditLog.User.user.updatedUser(0, null, [{ key: 'admin', old: false, new: true }], user)
user.admin = true
await user.save()
}

// Get the existing memberships and generate a slug->membership object (existingMemberships)
const existingMemberships = {}
;((await user.getTeamMemberships(true)) || []).forEach(membership => {
Expand Down Expand Up @@ -355,8 +370,6 @@ module.exports.init = async function (app) {
// This team is in the desired list
if (desiredTeamMemberships[teamSlug] !== membership.role) {
// Role has changed - update membership
// console.log(`changing role in team ${teamSlug} from ${membership.role} to ${desiredTeamMemberships[teamSlug]}`)

const updates = new app.auditLog.formatters.UpdatesCollection()
const oldRole = app.auditLog.formatters.roleObject(membership.role)
const role = app.auditLog.formatters.roleObject(desiredTeamMemberships[teamSlug])
Expand Down

0 comments on commit 36e2493

Please sign in to comment.