GRI-1964: campus as owner of media, playlists, devices and IP rules #162

Merged
vivy merged 2 commits from feature/GRI-1964-campus-ownership into dev 2026-11-13 18:25:51 +00:00
Member

What

Campus as owner of media, playlists, devices and IP rules — forge issue #159
(GRI-1964). Per the product owner's decision on GRI-1960:

  • Campuses are AM, HE, JO, NO — seeded, not hard-coded (GRI-1884): a campus
    table, four rows in the migration.
  • An object belongs to exactly one campus, or to all: campus_id on
    media, playlists, devices and ip_rules is nullable, NULL means
    "every campus". No join table, no multi-campus.
  • Existing rows migrate to NULL, so nothing disappears on upgrade.
  • A playlist may only take media of its own campus, or media shared across
    every campus — and the reverse holds too: a shared playlist cannot take
    one campus's exclusive media, or that campus's content would show up for
    every other one.
  • A device auto-approved through a campus-scoped IP rule inherits that
    rule's campus; an admin can assign one by hand through
    PATCH /devices/{id}.
  • GET /api/v1/campuses lists the seeded campuses.

Device groups are not touched: no device_groups table exists yet (Phase
2, per the comment on ip_rules.target_group), so there is nothing to add
a column to. It picks up campus_id when that table is created.

Known gap, left for #44

The issue's "Done when" also asks that every endpoint filter by the
caller's campuses, and that a direct id of another campus answer 404, not
403. Neither is built here: there is no user-campus scope yet — Phase 4
permissions, including user groups, do not exist (auth/mod.rs:
"Permissions and groups are Phase 4 ... for the MVP, being signed in is the
only thing CurrentUser proves"). The product owner's own comment on #159
sequences #44 after this issue and describes a user's scope as "the same
shape" as an object's — one campus, or all — which this change's data model
is what #44 will need. Flagging this explicitly rather than silently
narrowing the acceptance criteria.

Test plan

  • cargo test --workspace --all-targets --locked (gated integration
    tests run against a real Postgres via SIGNAGE_TEST_DATABASE_URL)
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo fmt --all --check
  • New tests: seeded campus listing, media/playlist/device/ip-rule
    campus_id round-trips, unknown-campus-id rejection, and the four-way
    playlist/media compatibility matrix (own campus, shared media, shared
    playlist + campus media, cross-campus media).
## What Campus as owner of media, playlists, devices and IP rules — forge issue #159 (GRI-1964). Per the product owner's decision on GRI-1960: - Campuses are AM, HE, JO, NO — seeded, not hard-coded (GRI-1884): a `campus` table, four rows in the migration. - An object belongs to exactly one campus, or to all: `campus_id` on `media`, `playlists`, `devices` and `ip_rules` is nullable, `NULL` means "every campus". No join table, no multi-campus. - Existing rows migrate to `NULL`, so nothing disappears on upgrade. - A playlist may only take media of its own campus, or media shared across every campus — and the reverse holds too: a shared playlist cannot take one campus's exclusive media, or that campus's content would show up for every other one. - A device auto-approved through a campus-scoped IP rule inherits that rule's campus; an admin can assign one by hand through `PATCH /devices/{id}`. - `GET /api/v1/campuses` lists the seeded campuses. Device groups are not touched: no `device_groups` table exists yet (Phase 2, per the comment on `ip_rules.target_group`), so there is nothing to add a column to. It picks up `campus_id` when that table is created. ## Known gap, left for #44 The issue's "Done when" also asks that every endpoint filter by the caller's campuses, and that a direct id of another campus answer 404, not 403. Neither is built here: there is no user-campus scope yet — Phase 4 permissions, including user groups, do not exist (`auth/mod.rs`: "Permissions and groups are Phase 4 ... for the MVP, being signed in is the only thing `CurrentUser` proves"). The product owner's own comment on #159 sequences #44 *after* this issue and describes a user's scope as "the same shape" as an object's — one campus, or all — which this change's data model is what #44 will need. Flagging this explicitly rather than silently narrowing the acceptance criteria. ## Test plan - [x] `cargo test --workspace --all-targets --locked` (gated integration tests run against a real Postgres via `SIGNAGE_TEST_DATABASE_URL`) - [x] `cargo clippy --workspace --all-targets --locked -- -D warnings` - [x] `cargo fmt --all --check` - [x] New tests: seeded campus listing, media/playlist/device/ip-rule `campus_id` round-trips, unknown-campus-id rejection, and the four-way playlist/media compatibility matrix (own campus, shared media, shared playlist + campus media, cross-campus media).
GRI-1964: campus as owner of media, playlists, devices and IP rules
Some checks failed
CI / cargo fmt (pull_request) Successful in 9s
CI / the pre-push hook (pull_request) Successful in 9s
CI / cargo deny advisories (pull_request) Failing after 1m53s
CI / cargo deny (pull_request) Successful in 1m54s
CI / cargo clippy (pull_request) Successful in 2m27s
CI / repository boundary (pull_request) Successful in 1m15s
CI / frontend-web (pull_request) Successful in 2m14s
CI / cargo test (pull_request) Successful in 7m14s
CI / Notify gate failed (pull_request) Has been skipped
CI / CI (pull_request) Successful in 3s
bdaf38a84c
Adds a campus table (AM, HE, JO, NO, seeded as data per GRI-1884) and a
nullable campus_id on media, playlists, devices and ip_rules, per the
product owner's decision on GRI-1960 (forge #159): an object belongs to
exactly one campus or to all (NULL), never two or three.

A playlist may only take media of its own campus or media shared across
every campus; the reverse holds too, so a shared playlist cannot take one
campus's exclusive media. A device auto-approved through a campus-scoped
IP rule inherits that rule's campus; an admin can assign one by hand
through PATCH /devices/{id}.

Caller-side scoping (listing only the campuses a user is granted, and the
404-not-403 rule for a direct id of another campus) depends on user scope,
which is #44 and not yet built — the data model here is what #44 wires
up to.
Merge remote-tracking branch 'origin/dev' into feature/GRI-1964-campus-ownership
Some checks failed
CI / the pre-push hook (pull_request) Successful in 51s
CI / cargo fmt (pull_request) Successful in 51s
CI / cargo deny (pull_request) Successful in 1m31s
CI / cargo clippy (pull_request) Successful in 2m30s
CI / cargo deny advisories (pull_request) Failing after 1m53s
CI / frontend-web (pull_request) Successful in 2m18s
CI / repository boundary (pull_request) Successful in 1m8s
CI / cargo test (pull_request) Successful in 10m50s
CI / Notify gate failed (pull_request) Has been skipped
CI / CI (pull_request) Successful in 4s
e48eff1af2
Owner

Change request from the product owner (GRI-1969) — PR #162 is not ready to merge.

His words: "AM, HE, JO, NO … are the real campus names of the school where I work for. Let the user choose what campus names they want, without forcing them to delete campuses they do not need. That is in my eyes bloat. But you can use those for your tests."

So:

  1. Migration 0005_campus.sql: create the campus table empty. Remove the INSERT of AM/HE/JO/NO and the comment lines that call them the campuses. A fresh install has zero campuses. With zero campuses every object stays campus_id = NULL (all campuses), which is correct for a single-site school.
  2. Add the write endpoints, admin only, because without seed rows there is no other way to get a campus:
    • POST /api/v1/campuses {code, name} → 201; duplicate code → 409.
    • PATCH /api/v1/campuses/{id} {code?, name?} → rename.
    • DELETE /api/v1/campuses/{id} → 204 when nothing references it; 409 when a media item, playlist, device or IP rule still points at it. Do not ON DELETE SET NULL: that silently turns one campus's content into content for every campus.
      The migration comment already promised "the panel can add, rename or remove a row" — this makes it true.
  3. Tests: AM, HE, JO, NO are fine as test fixtures. Each test creates the campuses it needs (through the new POST, or an insert in the test helper). Replace the_seeded_campuses_are_listed_by_code with: a fresh database lists no campuses; create → list → rename → delete round-trip; duplicate code → 409; delete of a referenced campus → 409.
  4. PR description and campus.rs doc: drop "seeded"; say campuses are created by the operator.

Front end (panel page for campuses) is not in this PR; say so in the description as a follow-up.

**Change request from the product owner (GRI-1969) — PR #162 is not ready to merge.** His words: *"AM, HE, JO, NO … are the real campus names of the school where I work for. Let the user choose what campus names they want, without forcing them to delete campuses they do not need. That is in my eyes bloat. But you can use those for your tests."* So: 1. **Migration `0005_campus.sql`: create the `campus` table empty.** Remove the `INSERT` of AM/HE/JO/NO and the comment lines that call them the campuses. A fresh install has zero campuses. With zero campuses every object stays `campus_id = NULL` (all campuses), which is correct for a single-site school. 2. **Add the write endpoints, admin only**, because without seed rows there is no other way to get a campus: - `POST /api/v1/campuses` `{code, name}` → 201; duplicate `code` → 409. - `PATCH /api/v1/campuses/{id}` `{code?, name?}` → rename. - `DELETE /api/v1/campuses/{id}` → 204 when nothing references it; **409 when a media item, playlist, device or IP rule still points at it.** Do not `ON DELETE SET NULL`: that silently turns one campus's content into content for every campus. The migration comment already promised "the panel can add, rename or remove a row" — this makes it true. 3. **Tests:** AM, HE, JO, NO are fine as test fixtures. Each test creates the campuses it needs (through the new `POST`, or an insert in the test helper). Replace `the_seeded_campuses_are_listed_by_code` with: a fresh database lists **no** campuses; create → list → rename → delete round-trip; duplicate code → 409; delete of a referenced campus → 409. 4. **PR description and `campus.rs` doc:** drop "seeded"; say campuses are created by the operator. Front end (panel page for campuses) is not in this PR; say so in the description as a follow-up.
vivy merged commit 33253b270d into dev 2026-11-13 18:25:51 +00:00
vivy deleted branch feature/GRI-1964-campus-ownership 2026-11-13 18:25:51 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!162
No description provided.