Skip to content

Design: configurable permissions module (role × permission × scope × when × where) #804

Open

Description

@mbhewitt

Epic: #731 · Foundation: #237 · Design agreed with Chipper in #census on 2026-10-17. This issue is the single design to review before any code.

Goal

Replace the hard-coded Admin / SuperAdmin checks with configurable, server-enforced permissions. Any role can be given any set of permissions from an Admin page, with no code change. Day one behaves exactly like today.

Model

A user may do something if any of their roles has a grant that matches all of:

Part Values
Permission page/table × view / add / update / delete, plus named extras (cancel, reschedule, check-in, overrides…), from the catalog in #731
Relationship to the person/shift acted on self · on my shift · in my department · everyone
Subject filter (optional) holds role(s) X · signed up for position(s) Y · excluding role(s) Z
When any · a named window (event-level or shift-level)
Where any · on-playa · off-playa

Hard rules that no grant can override:

  • Nobody sees or edits their own review.
  • Lead-on-lead reviews are denied unless a grant says otherwise.
  • At least one Admin always keeps the permissions page (lockout guard).

Department = the existing op_shift_category.department (DataEntry, OutReach, Sampling, SetupStrike, Special, Tech, Training). No new table.

Data (new tables, following the #620 SCD2 direction, no actor columns)

  • op_role_grant: role_id, permission, relationship, subject_role_ids, subject_position_ids, exclude_role_ids, window_key, place. One row = one grant. Several rows on the same role are OR'd together.
  • op_time_window: key, anchor (shift_start · shift_end · an op_dates date), minutes_before, minutes_after. Seeded with today's constants:
    • shift_future (until start − 1h)
    • shift_during (start − 1h → end + 2h)
    • walkup_checkin (start ± 30 min)
    • shift_past
  • op_role_auto_grant: role_id, trigger (position_assigned · training_complete · …), trigger_ref_id, lasts (shift · event_year · until_removed). This replaces the hard-coded training → role writes.
  • Position sign-up rule: op_position_type.signup_mode (open · role · assign_only), plus op_position_role (position_type_id, role_id) so a position can accept a set of roles. Today's single role_id migrates into it.
  • Pseudo-roles become rows in op_roles (role_src='system'): Guest off-playa, Guest on-playa, Authenticated Volunteer.
  • Permission catalog lives in code, not a table: a permission only means something once code checks it.

Enforcement

  • can(session | null, permission, { subjectShiftboardId?, timePositionId?, shiftTimesId? }) in lib/authz.ts. It loads the user's roles and grants once per request, then answers yes/no.
  • Every API route wraps with withPermission("shift_types:update") (or calls can() for object-level checks). This replaces withSuperAdmin, withWriteGuard, isAdmin and isOwnerOrAdmin.
  • The client receives the evaluated permission list with the session and hides UI from it. The client is never the lock.
  • Read-only mode and the existing check-in window logic keep working: they become a window and an override instead of special cases.

Setup page (Admin by default)

/roles/[roleId]/permissions shows one grid per role: rows = permissions, columns = scope / when / where. New roles start empty (baseline only). It also holds the role's auto-grant rules. Assignment of people to roles stays where it is today.

Day-one seed (reproduces today)

Role Seeded grants
Guest off-playa home, filtered shift list (#800), contact, training
Guest on-playa + walk-up check-in in walkup_checkin
Authenticated Volunteer own profile/account/schedule, sign up / remove self, shift list
Shift Lead as today (gates lead positions, profile display)
Admin (absorbs SuperAdmin) today's Admin + SuperAdmin powers
New, empty until configured: Volunteer Coordinator; area leads (Gate Sampling, Airport Sampling, Setup, Strike, Data Entry, Lab Host, Art Tour; reusing the existing Census Gate/Airport Sampling Lead and Census Data Entry Lead roles); Census Lab Host; IT Tech (Chipper: "sort of an administrator", to be configured) —
Core Crew, Staff, qualifications, flags, training completions no grants (still usable as subject filters / sign-up roles)

⚠️ Merging SuperAdmin into Admin widens access for the ~21 Admins who aren't SuperAdmins unless the Admin list is trimmed first. Trim Admin to the core group before step 3.

Rollout (off-season, never hot-swapped mid-event)

  1. Close the gap now: add the missing server-side guards on the dates and shift setup routes (Security: admin/super-admin config API endpoints have no server-side authorization #535 follow-up).
  2. Add the tables + can() with seed data. Nothing calls it yet.
  3. Move routes onto withPermission one group at a time, with a test asserting the same allow/deny as before for each.
  4. Ship the setup page (read-only first, then editable).
  5. Add VC / area-lead / Lab Host grants, auto-grant rules and sign-up modes, configured by Chipper on the page.
  6. Later: move flags, training and camp membership out of op_roles (exclude_from_recruitment flag (absorbs #608) #614, Roadmap: replace boolean add/remove/update/delete flags with timestamps + an SCD change log #620).

Open (all are settings, none block the build)

🤖 Generated with Claude Code

Activity

  1. mbhewitt commented on Oct 17, 2026

    @mbhewitt
    OwnerAuthor

    Admin goes away as a catch-all (Chipper, 2026-10-17)

    "I think admin goes away in favor of granting only certain permissions to certain currently considered admin roles"

    This replaces "trim Admin to the core group". The 21 people who are Admin but not SuperAdmin keep the abilities they actually use through their functional roles, not through Admin. Live data on those 21:

    • 20 of 21 already hold Shift Lead (16) and/or Census Lab Host (15)
    • 1 holds neither, so needs a person-by-person decision

    Plan:

    1. Seed Shift Lead and Census Lab Host with the operational slice of today's Admin: check-in, add/remove on shifts, reviews, notes, roster details. Scope, windows and on/off-playa rules apply as the seed decides.
    2. Remove the Admin role from those 21. Each one keeps what they use and loses SAP, roles, settings and shift setup.
    3. A top system role still exists for the 9 current SuperAdmins (name TBD). It holds the permissions page, because someone has to (lockout guard). Everything else it has is just grants like any other role.

    Check before step 2: each of the 20 should actually need what Shift Lead / Lab Host get. A short list for Chipper to eyeball, sent privately (not posted here, it's names).

  2. mbhewitt commented on Oct 17, 2026

    @mbhewitt
    OwnerAuthor

    Decisions (Mew, 2026-10-17)

    "lets leave those as just shift lead and not designate them as particular department leads… the power we give to leads will be by their actual position rather than by role… the people who are currently admins will lose that capability and super admins will just be admins… we will then have various roles for being able to make certain changes to the system, like updating shifts and text etc."

    1. No area lead roles. Lead positions stay gated by the generic Shift Lead role, as today. The old Census Sampling / Construction / OutReach / Data Entry / Training Lead roles are not revived.

    2. Lead powers come from the position, not a role. A grant can be attached to a position as well as a role. Being assigned to Gate Sampling Lead on a shift gives that position's grants for that shift. Example: the Gate Sampling Lead position grants view/check-in/reviews for the samplers and traffic tamers on that shift. This replaces the auto-granted area roles, so there's no role to grant or expire.

    3. Admin → removed from the 21 current non-super Admins. SuperAdmin → becomes Admin (the 9).

    4. Capability roles for system changes: small roles that each carry one slice of setup. Examples:

      The 21 ex-Admins who need something get the specific capability role(s).

    Design changes

    • op_role_grant becomes op_grant with a holder of either role_id or position_type_id. Position grants are always scoped to the shift the person holds that position on.
    • Remove op_role_auto_grant for lead positions. It's still useful for training → role.
    • The "seed Shift Lead / Lab Host with today's operational Admin slice" plan becomes: seed the lead positions with that slice. Lab Host position grants are decided separately.
    • Open: which capability roles to start with, and who among the 21 gets which. Most leads need none once their position carries the shift powers.

    🤖 Generated with Claude Code

  3. mbhewitt commented on Oct 17, 2026

    @mbhewitt
    OwnerAuthor

    Org chart (Mew, 2026-10-17): "we need an org chart… i think peers did something like this"

    What peers has (origin/peers-main, client/src/lib/authz.ts): a hard-coded leadership rank, Admin 3 > Coordinator 2 > Shift Lead 1 > everyone 0. A volunteer's rank is the highest role they hold. You can manage anyone below you, and same rank too for passcode resets (2026-08-30). It's used for kiosk passcode reset and lead read access to a subordinate's page. There is no org chart page.

    Proposal for Census: make it data-driven. A tree of roles and positions (e.g. Admin → Volunteer Coordinator → Shift Lead → Lab Host / Sampler; Gate Sampling Lead → Gate Sampler / Traffic Tamer), one parent per node. "Below me" comes from the tree, and the scope rules use it: reviews (below only, never peer or self), notes, passcode reset. It can also render as a visible page.

    Open (Mew): permissions only, or also a visible "who to ask" chart with names? Should positions be nodes, given that lead powers now come from positions?

  4. mbhewitt commented on Oct 17, 2026

    @mbhewitt
    OwnerAuthor

    Org chart: derive it, don't maintain it (proposal, 2026-10-17)

    Mew: "i am not sure how to set it up so that it is flexible and self organizing."

    Build the chart from data that already exists, so it reorganizes itself as leads are assigned and people sign up:

    1. Shift level: op_position_type.lead already flags lead positions. On a shift, people on lead positions sit above the people on that shift's other positions.
    2. Department level: op_shift_category.department puts every shift, and therefore every lead, under a department.
    3. Top: Admin, plus a Volunteer Coordinator per department. Which department(s) each VC heads is the only manual input.

    2026 check (distinct people, from live signups):

    Dept Leads Volunteers Shifts
    Sampling 14 91 16
    OutReach 6 93 14
    SetupStrike 4 46 26
    DataEntry 5 27 6
    Training 9 5 2
    Tech 5 0 7
    Special 0 18 9

    Special has no leads, so its people roll up to that department's VC or to Admin.
    The scope rules ("below me" for reviews and notes, passcode reset) read the same derived chart. Next step if wanted: a read-only org chart page rendered from live data.

  5. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Revision from Chipper's feedback (2026-10-17): the org chart doesn't drive permissions

    "our structure might be too complex for it… it locks down some things that I wanted to leave open"

    What changes

    1. The org chart is not a permission source. If we build one, it is display only. No VC↔department link feeds can().
    2. Volunteer Coordinator = everyone. VCs can see all volunteer information in every department. Their area of responsibility is just a label.
    3. "In my department" belongs to Shift Lead. A lead sees every volunteer in the department of the lead position they hold, including volunteers who aren't on their current shift.
      • Department = op_shift_category.department of the lead's position. No VC assignment needed, so Special (no VC) works the same way.
    4. Grants can attach to a position, not just a role. Example: if radio checkout moves into the app, anyone signed up for Driver (not a lead) sees the checkout form.
      • op_role_grant gets a nullable position_type_id beside role_id, with exactly one of them set. "Holds position X" means signed up for X in the current event year (or in the shift's window, if the grant has one).
      • This replaces the position_assigned trigger in op_role_auto_grant. That table is left with only training → role.
    5. Membership roles can carry grants. Example: Lab Steward positions are open only to CensusLabCamp, and the same role can be given other permissions because of where those people are camped. The model already allows any role to have grants. This is no longer limited to the "permission-setting" list.

    Open

    • Shift Lead's department view: does it last the whole event year, or only around their lead shifts?

    🤖 Generated with Claude Code

  6. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Lead access timing (Chipper, 2026-10-17)

    Shift Leads keep the Shift Lead role year-round. That status is still useful for off-playa work. Their extra access (department volunteer info and similar) is switched on by date context, not by removing the role and adding it back.

    • Add an event-level window, event_access, anchored on op_dates: from N days before the event to M days after.
    • Shift Lead's department grants use that window. Outside it, leads have the same access as a normal volunteer.
    • The window's dates are editable on the setup page, so changing them needs no code change.
    • Open for Mew / Rescue: how wide the window should be (this year, Admin access was probably granted just before the event).

    🤖 Generated with Claude Code

  7. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Top role: rename, don't merge (Chipper, 2026-10-17)

    This replaces "SuperAdmin merges into Admin" and the "trim Admin first" warning.

    • SuperAdmin is renamed to App Admin (final name is Mew's call). Same holders, same powers.
    • The Admin role is unchanged on day one, so nobody gains access. What Admin can do can be changed on the setup page later.
    • Day-one seed: App Admin gets today's SuperAdmin grants, and Admin gets today's Admin grants.

    🤖 Generated with Claude Code

  8. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Privileges come from roles, never from sign-ups (Chipper, 2026-10-17)

    This replaces the earlier "Shift Lead sees the department of the lead position they hold" and "grants can attach to a position".

    • Being assigned to a position can automatically give a role (op_position_auto_role). Example: assigned to Gate Sampling Lead → gets Census Gate Sampling Lead. The role carries the privileges. The sign-up itself never does.
    • A department grant names its department. Example: Census Sampling Lead → see volunteers in Sampling. A lead who works a different area one year keeps seeing their usual department.
    • VC = a role with "everyone", with no shift involved.
    • The 7 Census X Lead roles become how department access is handed out.
    • Open: if someone is removed from the lead shift, do they keep the auto-given role? The default is yes (it stays until it's removed by hand).

    Implemented in #806.

    🤖 Generated with Claude Code

  9. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Leads: position-based access (Mew, 2026-10-18)

    "i disagree with using the role based access over position based access for leads, whether or not someone can be assigned to a lead shift is a different question."

    • Lead access comes from the lead position held this season. Example grant: position Gate Sampling Lead → see volunteers in Sampling.
    • Role grants remain for things that aren't tied to a shift (VCs, area roles). A grant targets either a position or a role.
    • Who may be assigned to a lead position (role gates, auto-roles, auto-enroll) stays in Positions: give roles on assignment, auto-enroll in lead training, 'no sign-up' positions #807.
    • feat(authz): permission grant tables + can(), unused (#804 step 2) #806 updated: grantee_type now includes position, with a unit test and 4 cases run against a scratch MySQL database (lead sees own department · another department → no · removed from lead shift → no · plain volunteer → no).
    • Still open: Chipper's case of a lead who leads a different area for a year. With position-based access, they see the area they're leading this year. If they also need their usual area, give them that area's role as well.

    🤖 Generated with Claude Code

  10. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Chipper 2026-10-18, requirements for the grants admin UI and design:

    • If the 'who' list mixes roles and positions, label each entry clearly (e.g. 'Role: …' vs 'Position: …'). List all roles first, then positions. Many names exist as both.
    • Position-based access needs explicit timing. In feat(authz): permission grant tables + can(), unused (#804 step 2) #806 today, 'holds the position' means an active, non-removed signup in the op_ tables, which hold one season. So access lasts all season and doesn't end when the shift ends. Last year's positions don't carry over. If op_ tables ever hold multiple seasons, add a year filter.
    • Precedence / deny: Chipper asked whether grants need a rank. Current design is allow-only (rows OR together), so order never matters. Add deny plus ranking only when a concrete case needs it.
  11. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Mew's proposed role hierarchy (2026-10-18):

    • App Admin: full control of everything; later also setups and deploys.
    • Scheduler: most of what SuperAdmin does today.
    • Volunteer Coordinator: can assign anyone to any shift regardless of rules, on and off playa (≈ today's Admin); can look up any volunteer; might be assigned to a department.
    • Lead (the position, not a role): full control of the shift they're on (add/remove, check-in, notes); can look up volunteers on that shift and see their former shift notes.
    • Volunteer Assistant: can reset any volunteer's passcode.

    Revised #806 trim: keep the position grantee and the shift relationship (needed for Lead). Drop the department relationship (VC department scoping is a 'might') and date-anchored windows.

    Open questions to Mew (my suggestion in brackets):

    1. SAPs: Scheduler or App Admin? [App Admin]
    2. Lead control window [1h before start → 24h after end]
    3. Lead adds: within normal rules or override? [within rules; VCs override]
    4. Volunteer Assistant lookup scope [name search only]
  12. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Chipper (2026-10-18): leads must be able to find volunteers not on their shift, so they can add walk-ups. On-playa today, the add dialog already lists every volunteer for a shift in progress.

    Proposed split:

    • volunteers:find: name-only search (playa/world name, no contact info).
      • Leads during their lead window
      • Volunteer Assistant (passcode resets)
      • VCs and up
    • Full volunteer details and past notes: Leads only for volunteers on their shift (a walk-up qualifies once added). VCs and up for everyone.
  13. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Mew (2026-10-18): only VCs (and up) get full volunteer details. Shift leads need 'a lot of latitude to make the shift reality'.

    Updated Lead model (scope = the shift they're leading, during the lead window):

    • name-only find for any volunteer
    • add anyone, overriding slot and role rules (my reading of 'latitude'; awaiting confirmation)
    • remove, check in, write notes
    • see past shift notes for people on their shift
    • no contact info

    Still open: who owns SAPs, and the lead window (suggested: 1h before start → 24h after end).

  14. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Contact data actually held in op_volunteers on prod (2026-10-18):

    • email: 285 of 286
    • camp location: 156
    • legal first/last name: 5
    • phone / emergency_contact: all empty (migration 013)

    Chipper's point: a lead who can add anyone to their shift could then see that person's details, so hiding them from leads is mostly a speed bump. Mew to decide: either leads see email and location for people on their shift, or those fields stay VC-only.

  15. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Mew (2026-10-18): preserve on-playa tablet flexibility. Facts from the current code (pages/api/shifts/[timeId]/volunteers/index.ts):

    Open question for Mew: widen signed-out tablet abilities during the shift window (add walk-ups, comments)? That would be grant rows only, but the route's device-cookie gate must be kept as a prerequisite.

  16. mbhewitt commented on Oct 18, 2026

    @mbhewitt
    OwnerAuthor

    Correction to my previous comment (Mew caught it). For a signed-in non-admin on playa (on-playa build, or a provisioned tablet):

    The #806 seed already matches the server.

  17. mbhewitt commented on Oct 30, 2026

    @mbhewitt
    OwnerAuthor

    Multi-event requirement (Chipper, 2026-10-30), from Love Burn + Fern Burn conversations (see #530)

    Other events would need separation between departments: people should be able to see only certain departments, not the whole event.

    How this fits the current design here:

    • "in my department" scope already exists for Shift Lead. The extra need is a department-restricted coordinator/admin, i.e. a VC (or admin) scoped to one or more departments.
    • That conflicts with the current decision "Volunteer Coordinator = everyone" for Census. Suggest making it per-tenant config: Census keeps VC = everyone; a multi-department event can scope VCs/admins to their departments.
    • Open question: should regular volunteers also see only some departments' shifts (e.g. department-only/invite-only shift lists), or is it just admin/lead visibility of volunteer info?

    Chipper: "Separation between departments is a big one. With the ability to only see certain departments. I think we get that through the new roles permissions configuration."

  18. added
    needs: Mew
    on Oct 30, 2026
  19. mbhewitt commented on Nov 13, 2026

    @mbhewitt
    OwnerAuthor

    Review visibility requirements, from #census on 2026-11-13 (no review content here):

    • Own reviews: volunteers should NOT be able to see reviews about themselves. Shiftboard lets them; we shouldn't. (Chipper)
    • Leadership reviews: reviews of leads/leadership are more sensitive and shouldn't be shared broadly. Nor should anyone's own reviews be shared with them. (Chipper)
    • Leadership-fit scouting: Chipper and Rescue have intentionally pulled reviews into the leadership channel to spot volunteers who may be a good fit for leadership. That should stay possible for the right roles. (Chipper)
    • Interim rule: the bot keeps reviews out of #census for now, per Mew. Chipper thinks that's too strict long-term.

    So we need two things: a scoped permission to view reviews (who reviewed, about whom, by leadership level), and a rule for which surfaces reviews are allowed to appear in (app vs. Discord).

  20. mbhewitt commented on Nov 13, 2026

    @mbhewitt
    OwnerAuthor

    Mew (2026-11-13): #census is primarily a development channel and may include people who aren't authorized to see reviews. Reviews should be viewed through the app, not Discord. So the app's review views need to cover the leadership-fit scouting use case (above), gated by the review-view permission.

  21. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Mew (2026-11-27, #851 conflict 7): needs more discussion. Open question: does a new Leadership role replace today's Admin (#731 Part C), or does SuperAdmin become App Admin with Admin unchanged on day one (#804)? Don't build either part until this is settled.

  22. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Folding in #595 (Mew 2026-11-27, #851 conflict 13: superseded by the roles discussion). Carried over from #595: (1) who can grant Admin; (2) for actions the server already blocks for Admins (role-definition create/edit/delete), should the Roles screen hide those buttons or show them disabled?

  23. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Folding in #596 (Mew 2026-11-27, #851: roll into the roles discussion). Its open sub-decisions: A) Settings hidden on-playa plus an off-playa tester role; B) remove shift-lead/lab-host power to edit shift times or a position's role; C) disable-idle-logout for super-admins only; D) allow hiding Admin/Super admin on the account page; E) time-scope admins' forced roster changes (event-time only, past-looking). Details on #596.

  24. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Folding in #237 (Roles and permissions foundation, January 2026; Mew 2026-11-27, #851). Its scope (configurable permissions instead of hardcoded ones: who can check in, role-restricted signup, roster visibility, PII access) is this ticket's scope.

  25. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Mew (2026-11-27, #851): the permissions meeting (Mew, Chipper, Rescue) still needs to happen. I'll add a written proposal to the permissions framing doc first, so the meeting can react to it.

  26. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Folding in #128 (Mew 2026-11-27, #851): admins can be added to shifts and look like regular volunteers. Should they be hidden or marked? Include this in the permissions discussion.

  27. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Proposal for the permissions meeting is posted as a Drive comment on the framing doc (2026-11-27). Summary: App Admin = today's SuperAdmin; Volunteer Coordinator replaces Admin, after a one-by-one review; no separate Leadership role; drop Scheduler and Volunteer Assistant for now. Leads see name and camp, not email, and review during the lead window. Past notes are VC-only. Volunteers can self-drop until the shift starts. Screens hide what the server forbids. #596 E vs "always": keep always, and log the change. Recommendations only; the meeting decides.

  28. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Folding in #597 (Mew 2026-11-27): op_roles.display controls both whether a role shows on account pages and whether it's offered in the position setup picker. The permissions design should split these.

  29. mbhewitt commented on Nov 27, 2026

    @mbhewitt
    OwnerAuthor

    Folding in #444 (Mew 2026-11-27): the configurable signup-rules engine (warn / block / Discord ping / checklist + custom copy). Today's rules live in components/api/shiftAddRules.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: Mew

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions