GRI-1970: users, roles and campus-scoped permissions #168

Merged
vivy merged 8 commits from feature/GRI-1970-campus-permissions into dev 2026-11-13 22:38:08 +00:00
Member

What

Users, a small fixed role set (admin / campus editor), and campus-scoped access, enforced at the auth extractor so a handler never has to check permissions itself.

  • migrations/0006_users_groups_and_permissions.sql: users (each with an optional campus_id), user groups (roles) and their permission grants.
  • users.rs, user_groups.rs: CRUD for both, gated on users.manage. An admin's own group can't be demoted by its sole admin; an admin can't delete their own account; creating an admin with a campus_id is rejected (an admin sees every campus by definition).
  • auth/store.rs, auth/extractor.rs: load a user's permissions and campus_id on session lookup. AuthUser::may checks the permission; AuthUser::may_access checks whether a resource's own campus_id is in scope for this user — None means every campus, same convention campus.rs uses elsewhere.
  • shared::Permission::parse: the inverse of serialisation, so a grant row the running code no longer recognises is None rather than silently becoming the wrong permission.

Done when

Per the product owner's decision on this issue (2026-11-13) and the chief of staff's release note, the scope narrowed from the original device-group wording to campus-scoped access with a small role set: a campus editor scoped to campus A cannot see or reach a device in campus B, and non-admin management (users, settings) is refused. Covered by permissions_integration.rs.

Testing

scripts/local-gates.sh --rust-only: every gate passed (hooks, fmt, clippy, full test suite including the DB-backed integration suites, cargo deny, doc tests).

Closes #44.

## What Users, a small fixed role set (admin / campus editor), and campus-scoped access, enforced at the auth extractor so a handler never has to check permissions itself. - `migrations/0006_users_groups_and_permissions.sql`: users (each with an optional `campus_id`), user groups (roles) and their permission grants. - `users.rs`, `user_groups.rs`: CRUD for both, gated on `users.manage`. An admin's own group can't be demoted by its sole admin; an admin can't delete their own account; creating an admin with a `campus_id` is rejected (an admin sees every campus by definition). - `auth/store.rs`, `auth/extractor.rs`: load a user's permissions and `campus_id` on session lookup. `AuthUser::may` checks the permission; `AuthUser::may_access` checks whether a resource's own `campus_id` is in scope for this user — `None` means every campus, same convention `campus.rs` uses elsewhere. - `shared::Permission::parse`: the inverse of serialisation, so a grant row the running code no longer recognises is `None` rather than silently becoming the wrong permission. ## Done when Per the product owner's decision on this issue (2026-11-13) and the chief of staff's release note, the scope narrowed from the original device-group wording to campus-scoped access with a small role set: a campus editor scoped to campus A cannot see or reach a device in campus B, and non-admin management (users, settings) is refused. Covered by `permissions_integration.rs`. ## Testing `scripts/local-gates.sh --rust-only`: every gate passed (hooks, fmt, clippy, full test suite including the DB-backed integration suites, cargo deny, doc tests). Closes #44.
GRI-1970: cargo fmt
Some checks failed
CI / the pre-push hook (pull_request) Successful in 1m7s
CI / cargo fmt (pull_request) Successful in 1m16s
CI / cargo clippy (pull_request) Successful in 4m9s
CI / cargo deny (pull_request) Successful in 3m8s
CI / cargo deny advisories (pull_request) Failing after 4m13s
CI / repository boundary (pull_request) Successful in 1m19s
CI / cargo test (pull_request) Failing after 10m12s
CI / frontend-web (pull_request) Failing after 18m30s
CI / CI (pull_request) Has been cancelled
CI / Notify gate failed (pull_request) Has been cancelled
f13a4462b0
GRI-1971's permission_scoping_acceptance_integration.rs assumed a
users.role stand-in column; the real #44 migration uses
user_groups/group_permissions/user_group_members instead. Updates
insert_scoped_user and the lookup helper only, per the file's own
documented extension point -- no assertion changed.
GRI-1970: require admin for campus create/update/delete
Some checks failed
CI / the pre-push hook (pull_request) Successful in 49s
CI / cargo fmt (pull_request) Successful in 46s
CI / cargo deny advisories (pull_request) Failing after 1m47s
CI / cargo deny (pull_request) Successful in 1m52s
CI / cargo clippy (pull_request) Successful in 2m34s
CI / cargo test (pull_request) Failing after 2m53s
CI / repository boundary (pull_request) Successful in 52s
CI / frontend-web (pull_request) Successful in 1m35s
CI / CI (pull_request) Failing after 27s
CI / Notify gate failed (pull_request) Successful in 29s
76ce85d287
GRI-1970: permissions_integration.rs must create its own campuses
Some checks failed
CI / cargo fmt (pull_request) Successful in 48s
CI / the pre-push hook (pull_request) Successful in 49s
CI / cargo deny (pull_request) Successful in 1m30s
CI / cargo deny advisories (pull_request) Failing after 1m30s
CI / cargo clippy (pull_request) Successful in 2m47s
CI / repository boundary (pull_request) Successful in 1m26s
CI / cargo test (pull_request) Successful in 4m3s
CI / frontend-web (pull_request) Successful in 2m25s
CI / Notify gate failed (pull_request) Has been skipped
CI / CI (pull_request) Successful in 33s
d44cd3a7f7
Migration 0005 seeds no campus rows (GRI-1884: the campus list is data,
not code). The test file read campuses 'AM'/'HE' through the admin
session but never created them, so three tests panicked with
'campus AM is seeded' in CI. Create each one through POST
/api/v1/campuses first, the same way every other integration test file
in this crate already does.
vivy merged commit f7328b6422 into dev 2026-11-13 22:38:08 +00:00
vivy deleted branch feature/GRI-1970-campus-permissions 2026-11-13 22:38:09 +00:00
Author
Member

CI is green: cargo test, frontend-web, clippy, fmt, repo-boundary and the pre-push hook all pass on d44cd3a7. The one standalone red job, cargo deny advisories, is RUSTSEC-2024-0429 in glib, pre-existing and unrelated to this change (Cargo.lock untouched here) — not part of the overall CI verdict, which fj ci reports as passed.

This PR adds new auth/users/permissions/campus-scoping code (auth/store.rs, auth/extractor.rs, users.rs, user_groups.rs, migration 0006), so per process it needs a security review before merge. Handing to the security checker now.

CI is green: cargo test, frontend-web, clippy, fmt, repo-boundary and the pre-push hook all pass on d44cd3a7. The one standalone red job, `cargo deny advisories`, is RUSTSEC-2024-0429 in glib, pre-existing and unrelated to this change (Cargo.lock untouched here) — not part of the overall CI verdict, which `fj ci` reports as passed. This PR adds new auth/users/permissions/campus-scoping code (auth/store.rs, auth/extractor.rs, users.rs, user_groups.rs, migration 0006), so per process it needs a security review before merge. Handing to the security checker now.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage!168
No description provided.