roleOrder gives each role a number where lower = stronger (admin is 0). That makes direct comparisons on it read backwards: roleOrder[a] <= roleOrder[b] means "a is at least as strong as b", the opposite of what the <= looks like it's saying.
|
// This is a record only to ensure that all RoleKey are covered. weird order |
|
// on purpose so allRoles test can confirm sorting works |
|
export const roleOrder: Record<RoleKey, number> = { |
|
collaborator: 1, |
|
admin: 0, |
|
viewer: 3, |
|
limited_collaborator: 2, |
|
} |
We do role strength comparison using roleOrder inline at several call sites. I don't think call sites should be doing the order comparison directly. We already have getEffectiveRole (strongest of a list); the boolean comparisons want a helper with a name clear enough that it would be hard to use backwards — roleIsAtLeast(a, b) or a compareRoles comparator.
roleOrdergives each role a number where lower = stronger (admin is 0). That makes direct comparisons on it read backwards:roleOrder[a] <= roleOrder[b]means "a is at least as strong as b", the opposite of what the<=looks like it's saying.console/app/api/roles.ts
Lines 31 to 38 in 1b740d3
We do role strength comparison using
roleOrderinline at several call sites. I don't think call sites should be doing the order comparison directly. We already havegetEffectiveRole(strongest of a list); the boolean comparisons want a helper with a name clear enough that it would be hard to use backwards —roleIsAtLeast(a, b)or acompareRolescomparator.