Campus move: PATCH /api/v1/media/{id} to change a media item's (or whole document's) campus #244

Closed
opened 2026-11-15 18:10:48 +00:00 by glamourweaver · 4 comments
Member

Backend half of #242 (Global admin can move a media item, or a whole document, to another campus). The panel work stays on #242; this issue is the PATCH /api/v1/media/{media_id} route only.

Route

PATCH /api/v1/media/{media_id} with { "campus_id": "<uuid>" | null, "remove_from_playlists": bool } (campus_id: null = all campuses; remove_from_playlists optional, default false).

  • Global admin only. A campus admin may not move content into or out of a campus that is not theirs. 403 otherwise.
  • A document moves as one. A PDF or PPTX is many media rows sharing one document_id (one row per page). Changing the campus of one page changes it for every row of that document, in one transaction. A page of a document must never end up in a different campus from the rest.
  • The playlist rule stays true (check_items_campus, #159): campus media may only sit in a playlist of the same campus. Before the move, read the playlists that use the item:
    • Moving to all campuses (null) never breaks a playlist. Always allowed.
    • Moving to campus B while a playlist of campus A (or a shared playlist) uses the item: 409 media_in_use_by_other_campus, naming those playlists — same shape as the media_in_use error of delete (GRI-1962). Nothing changes.
    • With "remove_from_playlists": true: remove the item from those playlists and move it, in one transaction.
  • Unknown campus id: 400. Unknown media: 404.
  • Devices whose playlist lost an item must get the new playlist (existing playlist-change push) once the removal commits.

Why split from #242

#242 bundled this with a panel (frontend) change. The two have different owners (crates/server/src/media) and the frontend engineer does not touch crates/. Acceptance tests are being requested separately so the behaviour here (document atomicity, the 409 shape, the all-or-nothing remove-and-move) is pinned before either side implements against it — see the linked tests issue.

Parent: #242.

Backend half of #242 (Global admin can move a media item, or a whole document, to another campus). The panel work stays on #242; this issue is the `PATCH /api/v1/media/{media_id}` route only. ## Route `PATCH /api/v1/media/{media_id}` with `{ "campus_id": "<uuid>" | null, "remove_from_playlists": bool }` (`campus_id: null` = all campuses; `remove_from_playlists` optional, default false). - **Global admin only.** A campus admin may not move content into or out of a campus that is not theirs. 403 otherwise. - **A document moves as one.** A PDF or PPTX is many media rows sharing one `document_id` (one row per page). Changing the campus of one page changes it for every row of that document, in one transaction. A page of a document must never end up in a different campus from the rest. - **The playlist rule stays true** (`check_items_campus`, #159): campus media may only sit in a playlist of the same campus. Before the move, read the playlists that use the item: - Moving to **all campuses** (`null`) never breaks a playlist. Always allowed. - Moving to campus B while a playlist of campus A (or a shared playlist) uses the item: **409 `media_in_use_by_other_campus`**, naming those playlists — same shape as the `media_in_use` error of delete (GRI-1962). Nothing changes. - With `"remove_from_playlists": true`: remove the item from those playlists and move it, in one transaction. - Unknown campus id: 400. Unknown media: 404. - Devices whose playlist lost an item must get the new playlist (existing playlist-change push) once the removal commits. ## Why split from #242 #242 bundled this with a panel (frontend) change. The two have different owners (`crates/server/src/media`) and the frontend engineer does not touch `crates/`. Acceptance tests are being requested separately so the behaviour here (document atomicity, the 409 shape, the all-or-nothing remove-and-move) is pinned before either side implements against it — see the linked tests issue. Parent: #242.
Member

Checked for the QA engineer's acceptance tests before implementing (per the backend-engineer rule: tests exist first, never implement from a verbal description).

Found none: #245 (Acceptance tests: campus move for media) is still open, assigned to Astraea, and its own body says "Both the backend route and the panel are blocked on these existing." No test file for this route exists in crates/server/tests/ (checked for media_in_use_by_other_campus, campus_move, and a campus_move_*_acceptance_integration.rs-shaped file — nothing).

I did confirm the error shape to build against: delete_media's 409 media_in_use (crates/server/src/media/handlers.rs:729-772, from GRI-1962) is the precedent the issue says to mirror for media_in_use_by_other_campus. So the route is well-specified; what's missing is the pinned test, same as #174 did for #172 before that backend work started.

Blocking on #245 landing. Will pick this back up as soon as tests exist.

Checked for the QA engineer's acceptance tests before implementing (per the backend-engineer rule: tests exist first, never implement from a verbal description). Found none: #245 (Acceptance tests: campus move for media) is still **open**, assigned to Astraea, and its own body says *"Both the backend route and the panel are blocked on these existing."* No test file for this route exists in `crates/server/tests/` (checked for `media_in_use_by_other_campus`, `campus_move`, and a `campus_move_*_acceptance_integration.rs`-shaped file — nothing). I did confirm the error shape to build against: `delete_media`'s `409 media_in_use` (crates/server/src/media/handlers.rs:729-772, from GRI-1962) is the precedent the issue says to mirror for `media_in_use_by_other_campus`. So the route is well-specified; what's missing is the pinned test, same as #174 did for #172 before that backend work started. Blocking on #245 landing. Will pick this back up as soon as tests exist.
Owner

Chief of staff, for the Monday demo: this repo's local-gates.sh has no --start, so a background job dies when your turn ends (that is what happened earlier). Run the tests for #244 in the foreground, push, open the PR, and switch the #247 tests on. Forge CI runs the full gates. Next for you after this: #248 (server half of #228, the contract is in the issue).

Chief of staff, for the Monday demo: this repo's local-gates.sh has no --start, so a background job dies when your turn ends (that is what happened earlier). Run the tests for #244 in the foreground, push, open the PR, and switch the #247 tests on. Forge CI runs the full gates. Next for you after this: #248 (server half of #228, the contract is in the issue).
Member

Reviewed: PR #253 branches from my acceptance tests (#247, test/GRI-2115-campus-move-media-acceptance) and runs all 13 against the real implementation, including the device-push test with #[ignore] dropped. CI green on fb1d1a30. No gaps found; ready to merge alongside #247.

Reviewed: PR #253 branches from my acceptance tests (#247, test/GRI-2115-campus-move-media-acceptance) and runs all 13 against the real implementation, including the device-push test with #[ignore] dropped. CI green on fb1d1a30. No gaps found; ready to merge alongside #247.
Owner

In dev: PR #253 merged 23:59 UTC (409540c) carries the PATCH /api/v1/media/{media_id} campus move and the acceptance tests from #247, un-ignored. Closing.

In dev: PR #253 merged 23:59 UTC (`409540c`) carries the PATCH /api/v1/media/{media_id} campus move and the acceptance tests from #247, un-ignored. Closing.
vivy closed this issue 2026-11-16 00:01:56 +00:00
Sign in to join this conversation.
No project
No assignees
4 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#244
No description provided.