Campus as owner of media, playlists and devices #159

Closed
opened 2026-11-13 14:35:39 +00:00 by vivy · 6 comments
Owner

What

A campus (e.g. AM, HE) owns its objects: media, playlists, devices, device groups, IP rules. A user sees and changes only the campuses they are granted (one, several, or all). One server serves all campuses (plan/operations/deployment.md, GRI-1876).

Done when

  • Every media, playlist and device row belongs to exactly one campus; existing rows move to a default campus in the migration.
  • Every list/read/write endpoint filters by the caller's campuses; a direct id of another campus answers 404, not 403.
  • A playlist can only use media of its own campus (or a later "shared" campus — open question on GRI-1960).
  • Tests for reads, writes and direct-id access across campuses (extends #46).

Relation

Scope for #44 (permissions) and the campus settings issue. Before the one-campus production test (GRI-1960).

## What A **campus** (e.g. AM, HE) owns its objects: media, playlists, devices, device groups, IP rules. A user sees and changes only the campuses they are granted (one, several, or all). One server serves all campuses (`plan/operations/deployment.md`, GRI-1876). ## Done when - Every media, playlist and device row belongs to exactly one campus; existing rows move to a default campus in the migration. - Every list/read/write endpoint filters by the caller's campuses; a direct id of another campus answers 404, not 403. - A playlist can only use media of its own campus (or a later "shared" campus — open question on GRI-1960). - Tests for reads, writes and direct-id access across campuses (extends #46). ## Relation Scope for #44 (permissions) and the campus settings issue. Before the one-campus production test (GRI-1960).
Author
Owner

Product owner decision (GRI-1960, 2026-11-13):

  • Campuses are AM, HE, JO, NO (short names of real campuses).
  • An object belongs to exactly one campus, or to all. Never to two or three. This is to keep it simple.
  • Rollout: one whole campus moves from Xibo to Scryglass first. If that goes well, the other campus directors are asked to switch.

What this means for the design:

  • Each media item, playlist, device (and later schedule) has campus_id that is nullable: NULL = all campuses. No join table, no multi-campus.
  • The campus list is data, not code (a campus table, seeded or created in the panel). AM/HE/JO/NO are the first rows, not constants (GRI-1884: no hard-coding).
  • A user's scope (#44) is: one campus, or all. Same shape.
  • Existing rows migrate to NULL (all), so nothing disappears on upgrade.

Released to @aetherforge. Next after this: #44 / #52.

**Product owner decision (GRI-1960, 2026-11-13):** - Campuses are **AM, HE, JO, NO** (short names of real campuses). - An object belongs to **exactly one campus, or to all**. Never to two or three. This is to keep it simple. - Rollout: one whole campus moves from Xibo to Scryglass first. If that goes well, the other campus directors are asked to switch. What this means for the design: - Each media item, playlist, device (and later schedule) has `campus_id` that is **nullable**: `NULL` = all campuses. No join table, no multi-campus. - The campus list is **data, not code** (a `campus` table, seeded or created in the panel). AM/HE/JO/NO are the first rows, not constants (GRI-1884: no hard-coding). - A user's scope (#44) is: one campus, or all. Same shape. - Existing rows migrate to `NULL` (all), so nothing disappears on upgrade. Released to @aetherforge. Next after this: #44 / #52.
Member

Implemented the data model: a campus table seeded with AM, HE, JO, NO (data per GRI-1884, not code), and a nullable campus_id on media, playlists, devices and ip_rules (NULL = every campus, per the product owner's decision on GRI-1960). A playlist can only take media of its own campus or shared media, and the reverse holds too — a shared playlist cannot take one campus's exclusive media. A device auto-approved through a campus-scoped IP rule inherits that campus; an admin can assign one by hand via PATCH /devices/{id}. GET /api/v1/campuses lists the seeded rows. Device groups are untouched — no such table exists yet (Phase 2, not persisted).

Known gap, left for #44: caller-side scoping (listing only the campuses a user is granted, and 404-not-403 on a direct id of another campus) needs a user-campus scope that does not exist yet — Phase 4 permissions are not built (auth/mod.rs: "being signed in is the only thing CurrentUser proves"). The product owner's own comment sequences #44 after this issue, so I built the data model #44 will need rather than silently narrowing this issue's acceptance criteria to pass.

Verified locally: cargo test --workspace --all-targets --locked, cargo clippy --workspace --all-targets --locked -- -D warnings, cargo fmt --all --check, and the branch's git-hooks gates, all green. New tests cover the campus seed list, campus_id round-trips on media/playlist/device/ip-rule, unknown-campus-id rejection, and the full playlist/media compatibility matrix (own campus, shared media, shared playlist + campus media, cross-campus media).

PR: #162 (CI running — will report the verdict here).

Implemented the data model: a `campus` table seeded with AM, HE, JO, NO (data per GRI-1884, not code), and a nullable `campus_id` on `media`, `playlists`, `devices` and `ip_rules` (`NULL` = every campus, per the product owner's decision on GRI-1960). A playlist can only take media of its own campus or shared media, and the reverse holds too — a shared playlist cannot take one campus's exclusive media. A device auto-approved through a campus-scoped IP rule inherits that campus; an admin can assign one by hand via `PATCH /devices/{id}`. `GET /api/v1/campuses` lists the seeded rows. Device groups are untouched — no such table exists yet (Phase 2, not persisted). Known gap, left for #44: caller-side scoping (listing only the campuses a user is granted, and 404-not-403 on a direct id of another campus) needs a user-campus scope that does not exist yet — Phase 4 permissions are not built (`auth/mod.rs`: "being signed in is the only thing `CurrentUser` proves"). The product owner's own comment sequences #44 after this issue, so I built the data model #44 will need rather than silently narrowing this issue's acceptance criteria to pass. Verified locally: `cargo test --workspace --all-targets --locked`, `cargo clippy --workspace --all-targets --locked -- -D warnings`, `cargo fmt --all --check`, and the branch's git-hooks gates, all green. New tests cover the campus seed list, `campus_id` round-trips on media/playlist/device/ip-rule, unknown-campus-id rejection, and the full playlist/media compatibility matrix (own campus, shared media, shared playlist + campus media, cross-campus media). PR: https://git.grimoirix.org/Grimoirix/grimoire-of-digital-signage/pulls/162 (CI running — will report the verdict here).
Member

CI on PR #162 (commit bdaf38a8): the aggregate CI / CI gate passed — clippy, cargo deny (licenses/bans), fmt, cargo test, frontend-web, repository boundary, and the pre-push hook all green.

One sub-job, cargo deny advisories, is failing — but it's pre-existing and unrelated to this change: this PR touches no Cargo.toml/Cargo.lock (verified via git diff origin/dev...HEAD --stat), and running cargo deny check advisories locally shows the same failure comes from the client crate's GTK/webkit transitive dependency tree, which this PR never touches. Ready for review/merge on that basis.

CI on PR #162 (commit `bdaf38a8`): the aggregate `CI / CI` gate passed — clippy, cargo deny (licenses/bans), fmt, cargo test, frontend-web, repository boundary, and the pre-push hook all green. One sub-job, `cargo deny advisories`, is failing — but it's pre-existing and unrelated to this change: this PR touches no `Cargo.toml`/`Cargo.lock` (verified via `git diff origin/dev...HEAD --stat`), and running `cargo deny check advisories` locally shows the same failure comes from the `client` crate's GTK/webkit transitive dependency tree, which this PR never touches. Ready for review/merge on that basis.
Author
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.
Author
Owner

Correction. My change request on PR #162 said the PR was not merged. That was wrong: I merged it myself at 18:25:51 UTC, four seconds before I posted the request (merge commit 33253b2). So dev now holds 0005_campus.sql with the AM/HE/JO/NO seed. It is not in main, so no release has it.

The rework requested on #162 is still wanted, but now as a follow-up branch from dev, under this issue:

  1. Remove the INSERT INTO campus from 0005_campus.sql, and the comment line that names the four campuses. Edit 0005 in place rather than adding a 0006 that deletes rows: nothing outside dev has run it, and a cleanup migration would keep the school's campus names in the shipped code for ever. Any local/CI database that already ran 0005 must be recreated (sqlx checksum mismatch) — say so in the PR.
  2. POST, PATCH, DELETE /api/v1/campuses for admins. Duplicate code → 409. Delete of a campus still referenced by media, a playlist, a device or an IP rule → 409.
  3. AM/HE/JO/NO only as test fixtures; each test creates what it needs. Add a test that a fresh database lists no campuses.
**Correction.** My change request on PR #162 said the PR was not merged. That was wrong: I merged it myself at 18:25:51 UTC, four seconds before I posted the request (merge commit `33253b2`). So `dev` now holds `0005_campus.sql` **with** the AM/HE/JO/NO seed. It is not in `main`, so no release has it. The rework requested on #162 is still wanted, but now as a follow-up branch from `dev`, under this issue: 1. Remove the `INSERT INTO campus` from `0005_campus.sql`, and the comment line that names the four campuses. Edit 0005 in place rather than adding a 0006 that deletes rows: nothing outside `dev` has run it, and a cleanup migration would keep the school's campus names in the shipped code for ever. Any local/CI database that already ran 0005 must be recreated (sqlx checksum mismatch) — say so in the PR. 2. `POST`, `PATCH`, `DELETE /api/v1/campuses` for admins. Duplicate code → 409. Delete of a campus still referenced by media, a playlist, a device or an IP rule → 409. 3. AM/HE/JO/NO only as test fixtures; each test creates what it needs. Add a test that a fresh database lists no campuses.
vivy closed this issue 2026-11-13 20:41:55 +00:00
Author
Owner

Done: merged into dev with #162.

Done: merged into dev with #162.
Sign in to join this conversation.
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#159
No description provided.