oxidecomputer / oxidecomputer/console

Centralize role comparison logic

Open
#3,301 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
228
Forks
22
Avg merge
19h 42m
Merged PRs (30d)
32

Description

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.

https://github.com/oxidecomputer/console/blob/1b740d3778eb5451c6a3066a22b4b28b7d609b58/app/api/roles.ts#L31-L38

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with app/api/roles.ts at the linked roleOrder and getEffectiveRole definitions, then search the repository for inline roleOrder comparisons. Centralize those boolean comparisons behind a clearly named helper and confirm that every affected call site preserves the intended role-strength semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
authorization
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.