Panel: a global admin can add, edit and delete campuses and open a campus's settings #207

Closed
opened 2026-11-15 09:02:06 +00:00 by vivy · 9 comments
Owner

Product owner, 2026-11-15 (GRI-2051): "I don't see a way to add a campus or change settings from a campus from the global admin view."

Today. The server already has the API: GET/POST /api/v1/campuses, PATCH/DELETE /api/v1/campuses/{id} (crates/server/src/campus.rs). The panel only uses listCampuses. /settings shows the global screen to a global admin and CampusSettingsScreen only to a user whose own account has a campus — so a global admin can neither create a campus nor open one campus's settings.

Wanted.

  • Settings → Campuses: list (code, name, number of devices/playlists), Add a campus, rename, delete.
  • Delete that is refused because media, playlists, devices or IP rules still use the campus must say what still uses it, not a bare error.
  • Open a campus → its own settings page (today's CampusSettingsScreen: playback defaults, and later more), reached from the list by a global admin.
  • Campus-scoped users keep seeing only their own campus, as now.

Uses the left sub-menu layout from the navigation issue filed at the same time, if that lands first.

Acceptance. A global admin creates a campus, renames it, sets its playback default, and deletes an empty one, all from the panel. A campus admin cannot see other campuses.

Product owner, 2026-11-15 (GRI-2051): *"I don't see a way to add a campus or change settings from a campus from the global admin view."* **Today.** The server already has the API: `GET/POST /api/v1/campuses`, `PATCH/DELETE /api/v1/campuses/{id}` (`crates/server/src/campus.rs`). The panel only uses `listCampuses`. `/settings` shows the global screen to a global admin and `CampusSettingsScreen` only to a user whose own account has a campus — so a global admin can neither create a campus nor open one campus's settings. **Wanted.** - **Settings → Campuses**: list (code, name, number of devices/playlists), **Add a campus**, rename, delete. - Delete that is refused because media, playlists, devices or IP rules still use the campus must say *what* still uses it, not a bare error. - Open a campus → its own settings page (today's `CampusSettingsScreen`: playback defaults, and later more), reached from the list by a global admin. - Campus-scoped users keep seeing only their own campus, as now. Uses the left sub-menu layout from the navigation issue filed at the same time, if that lands first. **Acceptance.** A global admin creates a campus, renames it, sets its playback default, and deletes an empty one, all from the panel. A campus admin cannot see other campuses.
Author
Owner

Layout: see #210.

Layout: see #210.
Member

Read #207 and the referenced #210 (navigation; still todo, not landed — implementing without its left sub-menu for now, as the issue allows).

Today. crates/server/src/campus.rs already has full CRUD (GET/POST /campuses, PATCH/DELETE /campuses/{id}), admin-gated. The panel only calls listCampuses (frontend-web/src/api/campusApi.ts), and /settings picks CampusSettingsScreen only when the signed-in user has their own campusId, else the global SettingsScreen — which has no campus management UI at all (DashboardScreen.tsx:83-88).

Two small server gaps, both needed for the acceptance criteria:

  1. The list has no counts, so the panel can't show "number of devices/playlists" per campus.
  2. DELETE /campuses/{id}'s 409 campus_in_use is a bare message naming no specifics — the issue requires it say what still uses it.

Proposed contract (wire format stays snake_case, same convention as playback_settings.rs):

  • GET /api/v1/campuses — each item gains two counts:
    { "id": "...", "code": "AM", "name": "Amsterdam", "device_count": 3, "playlist_count": 2 }
    
    Counts via LEFT JOIN/COUNT grouped by campus id, ordered by code (unchanged). POST/PATCH keep returning the bare {id, code, name} row — the panel sets a new campus's counts to 0 locally and leaves counts alone on rename.
  • POST /api/v1/campuses, PATCH /api/v1/campuses/{id} — unchanged (already admin-gated, already validate non-empty code/name, already 409 duplicate_code on a clashing code).
  • DELETE /api/v1/campuses/{id} — on the FK violation, build the message the way media_in_use_error already does for media (media/handlers.rs:761), counting rows in media, playlists, devices, ip_rules with this campus_id instead of re-deriving from the FK error:
    {
      "code": "campus_in_use",
      "message": "still used by 2 media items, 1 playlist and 3 devices",
      "details": { "media": 2, "playlists": 1, "devices": 3, "ip_rules": 0 }
    }
    
    Only non-zero categories appear in the message; details always carries all four so the panel never has to parse the sentence.

Panel.

  • Settings → Campuses: list (code, name, device count, playlist count), Add a campus (code + name), rename, delete with the message above shown verbatim on a 409 campus_in_use.
  • Open a campus from that list → its existing CampusSettingsScreen (playback default today), reached at /settings/campuses/{id} with a way back to the list. A global admin reaches it this way; a campus-scoped user keeps reaching their own campus directly at /settings, unchanged, and sees no list of other campuses.
  • DashboardScreen's /settings branch grows a path check (/settings/campuses and /settings/campuses/{id}, same startsWith style already used for /playlists/*) so a global admin's /settings tree carries the list, the add form and one open campus, while a campus-scoped admin's /settings is exactly what it is today.

Acceptance (unchanged from #207). A global admin creates a campus, renames it, sets its playback default, and deletes an empty one, all from the panel. A campus admin cannot see other campuses. Plus: deleting a campus that is still in use is refused with a message naming what's using it, not a bare error.

Asking astraea for acceptance tests against this contract before I implement it — same as #161/#178, #172/#174. Opening a dedicated forge issue for that now, linked here.

Read #207 and the referenced #210 (navigation; still `todo`, not landed — implementing without its left sub-menu for now, as the issue allows). **Today.** `crates/server/src/campus.rs` already has full CRUD (`GET/POST /campuses`, `PATCH/DELETE /campuses/{id}`), admin-gated. The panel only calls `listCampuses` (`frontend-web/src/api/campusApi.ts`), and `/settings` picks `CampusSettingsScreen` only when the signed-in user has their own `campusId`, else the global `SettingsScreen` — which has no campus management UI at all (`DashboardScreen.tsx:83-88`). Two small server gaps, both needed for the acceptance criteria: 1. The list has no counts, so the panel can't show "number of devices/playlists" per campus. 2. `DELETE /campuses/{id}`'s `409 campus_in_use` is a bare message naming no specifics — the issue requires it say *what* still uses it. **Proposed contract** (wire format stays snake_case, same convention as `playback_settings.rs`): - `GET /api/v1/campuses` — each item gains two counts: ```json { "id": "...", "code": "AM", "name": "Amsterdam", "device_count": 3, "playlist_count": 2 } ``` Counts via `LEFT JOIN`/`COUNT` grouped by campus id, ordered by code (unchanged). `POST`/`PATCH` keep returning the bare `{id, code, name}` row — the panel sets a new campus's counts to 0 locally and leaves counts alone on rename. - `POST /api/v1/campuses`, `PATCH /api/v1/campuses/{id}` — unchanged (already admin-gated, already validate non-empty `code`/`name`, already `409 duplicate_code` on a clashing code). - `DELETE /api/v1/campuses/{id}` — on the FK violation, build the message the way `media_in_use_error` already does for media (`media/handlers.rs:761`), counting rows in `media`, `playlists`, `devices`, `ip_rules` with this `campus_id` instead of re-deriving from the FK error: ```json { "code": "campus_in_use", "message": "still used by 2 media items, 1 playlist and 3 devices", "details": { "media": 2, "playlists": 1, "devices": 3, "ip_rules": 0 } } ``` Only non-zero categories appear in the message; `details` always carries all four so the panel never has to parse the sentence. **Panel.** - `Settings → Campuses`: list (code, name, device count, playlist count), **Add a campus** (code + name), rename, delete with the message above shown verbatim on a `409 campus_in_use`. - Open a campus from that list → its existing `CampusSettingsScreen` (playback default today), reached at `/settings/campuses/{id}` with a way back to the list. A global admin reaches it this way; a campus-scoped user keeps reaching their own campus directly at `/settings`, unchanged, and sees no list of other campuses. - `DashboardScreen`'s `/settings` branch grows a path check (`/settings/campuses` and `/settings/campuses/{id}`, same `startsWith` style already used for `/playlists/*`) so a global admin's `/settings` tree carries the list, the add form and one open campus, while a campus-scoped admin's `/settings` is exactly what it is today. **Acceptance (unchanged from #207).** A global admin creates a campus, renames it, sets its playback default, and deletes an empty one, all from the panel. A campus admin cannot see other campuses. Plus: deleting a campus that is still in use is refused with a message naming what's using it, not a bare error. Asking astraea for acceptance tests against this contract before I implement it — same as #161/#178, #172/#174. Opening a dedicated forge issue for that now, linked here.
Member

Implemented against astraea's acceptance tests on #213 (crates/server/tests/campus_crud_counts_acceptance_integration.rs, PR #216 onto dev).

Server (crates/server/src/campus.rs):

  • GET /api/v1/campuses now returns device_count/playlist_count per campus via a new CampusWithCounts row, still ordered by code; POST/PATCH keep returning the bare {id, code, name}.
  • DELETE .../{id} on conflict now returns 409 campus_in_use with a message naming only the non-zero categories and a details object carrying all four (media/playlists/devices/ip_rules), built the way media_in_use_error is.
  • All 13 of astraea's acceptance tests pass:
    SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \
      cargo test -p server --test campus_crud_counts_acceptance_integration
    # test result: ok. 13 passed; 0 failed
    

Panel (frontend-web):

  • New CampusesScreen at /settings/campuses: lists every campus with its device/playlist counts, add, rename, delete — a refused delete (campus in use) surfaces the server's message naming what still uses it, not a bare error.
  • Opening a campus from that list goes to /settings/campuses/{id}, reusing the existing CampusSettingsScreen (playback default), with a back link.
  • Routed from Settings → Campuses, gated on user.campusId === null (the existing global-admin branch) — a campus-scoped user's /settings routing is unchanged and never reaches the campus list, satisfying "a campus admin cannot see other campuses".
  • npx vitest run: 63/63 pass (7 new, for CampusesScreen: loading/loaded, add, duplicate-code refusal, rename, delete-empty, delete-in-use-refused-with-message, open-link).
  • tsc -b, prettier --check ., oxlint --deny-warnings: all clean.

Loading/empty/error states: loading shows a status message; an empty list shows "No campuses yet."; a load failure shows a retry button; action errors (duplicate code, in-use delete, validation) surface inline via role="alert", mirroring UsersScreen's established pattern.

Full ./scripts/local-gates.sh run in progress on wt-GRI-2075 (branch feature/GRI-2075-panel-campus-admin); will push once it's green.

Implemented against astraea's acceptance tests on #213 (`crates/server/tests/campus_crud_counts_acceptance_integration.rs`, PR #216 onto `dev`). **Server** (`crates/server/src/campus.rs`): - `GET /api/v1/campuses` now returns `device_count`/`playlist_count` per campus via a new `CampusWithCounts` row, still ordered by `code`; `POST`/`PATCH` keep returning the bare `{id, code, name}`. - `DELETE .../{id}` on conflict now returns `409 campus_in_use` with a `message` naming only the non-zero categories and a `details` object carrying all four (`media`/`playlists`/`devices`/`ip_rules`), built the way `media_in_use_error` is. - All 13 of astraea's acceptance tests pass: ``` SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \ cargo test -p server --test campus_crud_counts_acceptance_integration # test result: ok. 13 passed; 0 failed ``` **Panel** (`frontend-web`): - New `CampusesScreen` at `/settings/campuses`: lists every campus with its device/playlist counts, add, rename, delete — a refused delete (campus in use) surfaces the server's message naming what still uses it, not a bare error. - Opening a campus from that list goes to `/settings/campuses/{id}`, reusing the existing `CampusSettingsScreen` (playback default), with a back link. - Routed from Settings → Campuses, gated on `user.campusId === null` (the existing global-admin branch) — a campus-scoped user's `/settings` routing is unchanged and never reaches the campus list, satisfying "a campus admin cannot see other campuses". - `npx vitest run`: 63/63 pass (7 new, for `CampusesScreen`: loading/loaded, add, duplicate-code refusal, rename, delete-empty, delete-in-use-refused-with-message, open-link). - `tsc -b`, `prettier --check .`, `oxlint --deny-warnings`: all clean. Loading/empty/error states: loading shows a status message; an empty list shows "No campuses yet."; a load failure shows a retry button; action errors (duplicate code, in-use delete, validation) surface inline via `role="alert"`, mirroring `UsersScreen`'s established pattern. Full `./scripts/local-gates.sh` run in progress on `wt-GRI-2075` (branch `feature/GRI-2075-panel-campus-admin`); will push once it's green.
Member

Committed the implementation (c697dc9) on feature/GRI-2075-panel-campus-admin: server GET /campuses now returns device/playlist counts, DELETE returns a structured 409 campus_in_use naming what's still using it; panel adds Settings -> Campuses (list/add/rename/delete, opens into CampusSettingsScreen for a global admin). Astraea's acceptance tests (GRI-2080) are on this branch and all 13 passed locally. Running ./scripts/local-gates.sh in the background now; will push and open the PR once it's green.

Committed the implementation (c697dc9) on feature/GRI-2075-panel-campus-admin: server GET /campuses now returns device/playlist counts, DELETE returns a structured 409 campus_in_use naming what's still using it; panel adds Settings -> Campuses (list/add/rename/delete, opens into CampusSettingsScreen for a global admin). Astraea's acceptance tests (GRI-2080) are on this branch and all 13 passed locally. Running ./scripts/local-gates.sh in the background now; will push and open the PR once it's green.
Member

Opened PR #219 (feature/GRI-2075-panel-campus-admin -> dev). Local gates all green (cargo fmt/clippy/test/deny, frontend-web prettier/oxlint/tsc/vitest 63/63, build). CI is queued on the runner (position 2, ETA ~1h15m); will report the verdict here and ask the chief of staff to merge once it's green.

Opened PR #219 (feature/GRI-2075-panel-campus-admin -> dev). Local gates all green (cargo fmt/clippy/test/deny, frontend-web prettier/oxlint/tsc/vitest 63/63, build). CI is queued on the runner (position 2, ETA ~1h15m); will report the verdict here and ask the chief of staff to merge once it's green.
Member

Merged origin/dev into feature/GRI-2075-panel-campus-admin and resolved the conflict against #218/#210’s Settings left sub-menu: campus CRUD now lives in settings/CampusesTab.tsx (replacing the read-only stub #218 left there for this issue), opening one campus from the list renders CampusSettingsScreen with a back link while the left menu stays on Campuses, and the old standalone SettingsScreen/CampusesScreen are gone. Frontend tsc/prettier/oxlint clean, vitest 73/73. Full local gates running; will push once green to refresh PR #219.

Merged origin/dev into feature/GRI-2075-panel-campus-admin and resolved the conflict against #218/#210’s Settings left sub-menu: campus CRUD now lives in `settings/CampusesTab.tsx` (replacing the read-only stub #218 left there for this issue), opening one campus from the list renders `CampusSettingsScreen` with a back link while the left menu stays on Campuses, and the old standalone `SettingsScreen`/`CampusesScreen` are gone. Frontend tsc/prettier/oxlint clean, vitest 73/73. Full local gates running; will push once green to refresh PR #219.
Member

cargo fmt job on 061d2b1 failed after 14m19s against a 10m timeout in ci.yml — a hang (likely in rustup toolchain install), not a formatting diff; cargo fmt --all --check is clean on that exact commit locally. Pushed an empty retrigger commit (50d9a68) to PR #219; CI is re-running. Will hand off to the chief of staff for merge once green, or fix if a real gate fails this time.

cargo fmt job on 061d2b1 failed after 14m19s against a 10m timeout in ci.yml — a hang (likely in rustup toolchain install), not a formatting diff; cargo fmt --all --check is clean on that exact commit locally. Pushed an empty retrigger commit (50d9a68) to PR #219; CI is re-running. Will hand off to the chief of staff for merge once green, or fix if a real gate fails this time.
Member

Addressed review #466: added a confirm step before Delete in CampusesTab (Cancel sends no DELETE; new test + a new confirm test, 8/8 pass). Merged origin/dev (#214, unassign-device-from-playlist, unrelated/clean). Full local-gates.sh running detached (PID 751985, log /workspace/scratch/prismancer/GRI-2075/gates.log). Will push to update PR #219 once green.

Addressed review #466: added a confirm step before Delete in CampusesTab (Cancel sends no DELETE; new test + a new confirm test, 8/8 pass). Merged origin/dev (#214, unassign-device-from-playlist, unrelated/clean). Full local-gates.sh running detached (PID 751985, log /workspace/scratch/prismancer/GRI-2075/gates.log). Will push to update PR #219 once green.
Member

On commit f182f89 (merge of origin/dev's #214, confirm-before-delete already pushed as part of review #466 fix): full ./scripts/local-gates.sh re-run hit a single unrelated flake — pptx_video::tests::fallback_returns_pages_in_page_order panicked with 'Text file busy (os error 26)' on a shared fake soffice binary under parallel test execution; re-ran it alone and it passes. Nothing to do with the campus admin code. Restarted the full gate run detached (log at /workspace/scratch/prismancer/GRI-2075/gates.log); will push once it's green.

On commit f182f89 (merge of origin/dev's #214, confirm-before-delete already pushed as part of review #466 fix): full ./scripts/local-gates.sh re-run hit a single unrelated flake — pptx_video::tests::fallback_returns_pages_in_page_order panicked with 'Text file busy (os error 26)' on a shared fake soffice binary under parallel test execution; re-ran it alone and it passes. Nothing to do with the campus admin code. Restarted the full gate run detached (log at /workspace/scratch/prismancer/GRI-2075/gates.log); will push once it's green.
vivy closed this issue 2026-11-15 13:31:06 +00:00
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#207
No description provided.