Respond to PR feedback.

This commit is contained in:
Sam Rose 2024-03-05 09:23:48 +00:00
parent dd8fb23b52
commit fced2f3696
No known key found for this signature in database
2 changed files with 15 additions and 14 deletions

View File

@ -184,7 +184,7 @@ export async function getRole(
return cloneDeep(BUILTIN_ROLES.PUBLIC)
}
// only throw an error if there is no role at all
if (!role || Object.keys(role).length === 0) {
if (Object.keys(role || {}).length === 0) {
throw err
}
}

View File

@ -35,20 +35,21 @@ async function updateRolesOnUserTable(
) {
const table = await sdk.tables.getTable(InternalTables.USER_METADATA)
const constraints = table.schema.roleId?.constraints
if (constraints) {
const updatedRoleId =
roleVersion === roles.RoleIDVersion.NAME
? roles.getExternalRoleID(roleId, roleVersion)
: roleId
const indexOfRoleId = constraints.inclusion!.indexOf(updatedRoleId)
const remove = updateOption === UpdateRolesOptions.REMOVED
if (remove && indexOfRoleId !== -1) {
constraints.inclusion!.splice(indexOfRoleId, 1)
} else if (!remove && indexOfRoleId === -1) {
constraints.inclusion!.push(updatedRoleId)
}
await db.put(table)
if (!constraints) {
return
}
const updatedRoleId =
roleVersion === roles.RoleIDVersion.NAME
? roles.getExternalRoleID(roleId, roleVersion)
: roleId
const indexOfRoleId = constraints.inclusion!.indexOf(updatedRoleId)
const remove = updateOption === UpdateRolesOptions.REMOVED
if (remove && indexOfRoleId !== -1) {
constraints.inclusion!.splice(indexOfRoleId, 1)
} else if (!remove && indexOfRoleId === -1) {
constraints.inclusion!.push(updatedRoleId)
}
await db.put(table)
}
export async function fetch(ctx: UserCtx<void, FetchRolesResponse>) {