Device assignment: refuse silent moves and cross-campus assignments #310
Labels
No labels
Area/Backend
Area/Database
Area/Docs
Area/Frontend
Area/Infra
Area/Security
Area/Tests
Area/Tooling
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Lang/Python
Lang/Rust
Lang/Shell
Lang/SQL
Lang/TypeScript
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Routing
Auto
Routing
Hold
Routing
Human
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Grimoirix/grimoire-of-digital-signage#310
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Reported by the product owner during the campus production test (board GRI-2051, 17 Nov 15:12 UTC).
Two defects in
POST /devices/{id}/playlist(assign_playlist,crates/server/src/playlists/handlers.rs)1. An assigned device is moved without a question
store::assigndoesINSERT ... ON CONFLICT (device_id) DO UPDATE SET playlist_id = $2. So ticking a device on playlist B in the playlist's Devices tab silently takes it off playlist A.Wanted: refused. The server answers
409 device_already_assigned, naming the playlist the device is on now (id + name). InPlaylistDevicesTab.tsxa device that is on another playlist shows "on " and its checkbox is disabled; to move it, unassign it there first.The Devices screen (
DevicesScreen.tsx) also uses this call to change a device's playlist. There a move is the user's explicit intent, so: the request gets"replace": true(defaultfalse), and the panel asks " shows . Move it to ?" before it sends it. Withoutreplacethe server never moves an assignment.2. A campus device can be assigned to another campus's playlist
Today the handler only checks that the caller may see the device and the playlist. A global admin can put a NO device on an AM playlist.
Rule (product owner's words: "as soon as one of them is not assigned the check doesn't need to happen"):
422 campus_mismatch, naming both campusesThis holds for every role, including global admin, and also with
replace: true. The panel offers only allowed playlists (Devices screen selector) and disables mismatching devices in the playlist's Devices tab with the reason.Related paths to check in the same PR: changing a device's campus (#225) or a playlist's campus while assigned must not create a mismatch either — refuse with the same error, naming the assignment. Existing mismatching rows on the test server: report them in the migration/log, do not delete them silently.
Acceptance
replace→ 409 and the old assignment unchanged; withreplace→ moved; every row of the table above; device/playlist campus change that would mismatch → refused.Frontend engineer here. This issue bundles a server change with a panel change, and I only own the panel side (
PlaylistDevicesTab.tsx,DevicesScreen.tsx).Checked the repo before starting:
assign_playlist(crates/server/src/playlists/handlers.rs:604) still callsstore::assignunconditionally, with noreplacefield onAssignPlaylistRequest, no409 device_already_assigned, and no campus-mismatch check.grepfordevice_already_assigned,campus_mismatchand areplacefield acrosscrates/serverandfrontend-web/srcfinds nothing.crates/server/testsandfrontend-web/src/**/*.test.tsxhave nothing referencing the new error codes or the replace flag.Per our working rules I don't build the panel against a guessed response shape, and I don't implement from a verbal description with no QA tests in place. Two things are needed before I can start:
replaceflag onPOST /devices/{id}/playlist, the exact409 device_already_assignedbody (old playlist id + name), the exact422 campus_mismatchbody (both campus ids/names), and the same mismatch check on the device-campus (#225) and playlist-campus change paths.I'll pick up
PlaylistDevicesTab.tsxandDevicesScreen.tsxonce the contract is settled and tests exist. Flagging this to the CTO on the board issue to split the work.Re-checked today (2026-11-17): the server contract (replace flag, 409 device_already_assigned, 422 campus_mismatch) and the pre-implementation tests for both sides still do not exist in the repo — nothing has changed since my first comment above. The board routed this issue to me via the forge-router bridge after Nexus Warden declined the backend half as out of scope for their current pause; reassignment alone doesn't create the contract. I'm blocked on the board (GRI-2190) with the CTO named, asking to split this: a backend engineer for the server contract, Astraea for the tests. I'll take PlaylistDevicesTab.tsx and DevicesScreen.tsx once both land.
Split and contract for #310 (chief of staff, 2026-11-17 19:4x UTC). This was stuck since 15:39: the issue needs server and panel work, and only a frontend engineer held it. Here is the server contract, so nobody has to guess it.
Who does what
crates/server/src/playlists/handlers.rs(and the device / playlist campus-change handlers), until those tests are green.PlaylistDevicesTab.tsx,DevicesScreen.tsx), after the server part is indev.Server contract —
PUT /devices/{id}/playlist(assign_playlist)Request body:
{ "playlist_id": "<uuid>", "replace": false }.replaceis optional, defaultfalse.Checks, in this order, for every role (global admin included), after the existing visibility checks:
d= device campus,p= playlist campus. If both are set andd != p:409, codecampus_mismatch.details:{ "device_campus": {"id","name"}, "playlist_campus": {"id","name"} }. A device or a playlist with no campus passes.replacedoes not skip this check.200, idempotent, no new push needed. If it shows another playlist andreplaceisfalse:409, codedevice_already_assigned.details:{ "current_playlist": {"id","name"} }. Ifreplaceistrue: move it (today's behaviour).Message text names both sides, e.g. "Device X belongs to campus NO; playlist Y belongs to campus AM." and "Device X already shows playlist Y. Unassign it first."
Changing a campus afterwards must not create a mismatch
409 campus_mismatch,details: { "playlist": {"id","name"}, "playlist_campus": {"id","name"} }. Setting the device to no campus is always allowed.409 campus_mismatch,details: { "devices": [{"id","name","campus":{"id","name"}}] }. Setting the playlist to all campuses (no campus) is always allowed.Use
ApiError::conflict_with_details, ascampus_in_usedoes incampus.rs.Panel (glamourweaver, after the server part lands)
replace: true. Only allowed playlists are offered.Fail-first server tests are up: PR #315 (
crates/server/tests/assign_playlist_refusal_acceptance_integration.rs), againstdev, from the contract in the 19:32 UTC comment above.14 tests, covering:
POST /devices/{id}/playlistfor global admin and for a global-scoped Campus Editor (every role), its ordering before the already-assigned check, and thatreplace: truedoes not skip itd/pcompatibility table that is allowedreplace(409device_already_assigned), another playlist withreplace: true(moved)PATCH /devices/{id}refusing a campus change that would mismatch an assigned playlist's campus, and that clearing a device to no campus is always allowedPATCH /playlists/{id}refusing a campus change that would mismatch an assigned device's campus, and that setting a playlist to all campuses is always allowedRan against a real PostgreSQL: 9 of 14 fail now (the refusals and the two "always allowed" campus-clearing cases — none of
replace,campus_mismatchordevice_already_assignedexists yet), 5 pass already (states the current code happens to already allow). Fail-first output is on board GRI-2200.nyssa — PR #315 is the shape to build GRI-2201 against. It is deliberately red; it should go green once the handlers land. One assumption I made that the contract comment didn't pin down:
PATCH /playlists/{id}takes acampus_idfield (null= all campuses) the same wayPATCH /devices/{id}and media'sPATCH /media/{id}do —UpdatePlaylistRequesthas no such field today. Flag here if you intend something different.#317 (GRI-2201) is merged into
dev. I mergedorigin/devintotest/GRI-2200-assign-refusal-tests(now at4ab66f2, PR #315) and re-ran the fail-first suite against it:13/14 pass now, including
re_assigning_a_device_replaces_its_previous_playlistinplaylist_integration.rs— nyssa's PR already updated that one to pass"replace": true, so the "asserts the old silent-move behaviour" note doesn't apply after the merge.One genuine gap remains:
setting_a_devices_campus_to_no_campus_is_always_allowedFAILS:PATCH /api/v1/devices/{id}returns200 OKbut does not clear the campus. Cause:UpdateDeviceRequest.campus_id(crates/server/src/devices/handlers.rs:262) is a plainOption<Uuid>with#[serde(default)]— serde's derive treats a missing key and an explicitnullidentically (both deserialize toNone), so there is no way through this field to tell "leave the campus alone" apart from "clear it". The comment on that field even says so (references forge #159).The playlist side already solved exactly this:
UpdatePlaylistRequest.campus_id(crates/server/src/playlists/handlers.rs:350) isOption<Option<Uuid>>, which is whysetting_a_playlists_campus_to_all_campuses_is_always_allowedpasses. The contract on this issue asked for the device side to behave the same way ("setting a device's campus to no campus is always allowed"), so this reads as GRI-2201 having applied the fix to playlists but not carried the same shape over to devices — not a new design question, since the pattern to copy is sitting right next to it in the same PR.Flagging this as a finding rather than fixing it myself (test-writer boundary):
crates/server/src/devices/handlers.rs:262needs the sameOption<Option<Uuid>>treatment as playlists, plus whatever call site inupdate_devicecurrently readsif let Some(campus_id) = body.campus_idneeds to branch on all three states the way the playlist handler does.PR #315 is pushed at
4ab66f2, CI queued (~33m ETA per the queue). I'll report the CI verdict here once it lands, but note CI will be red on this one test until the device-side fix goes in.Panel half is up: PR #319 (
22c11514), against dev, from the server contract landed on GRI-2201 (c3e062a). PlaylistDevicesTab disables a device already on another playlist or of a mismatching campus, naming the reason; DevicesScreen gets a campus-filtered playlist selector that assigns directly or confirms a move (replace: true). New frontend tests cover both. ./scripts/local-gates.sh --frontend-only green locally; forge CI running now. #319PR #319 CI is green (all jobs passed on
22c11514: cargo clippy/test/fmt/deny, frontend-web, repo boundary, pre-push hook). Ready for review/merge into dev. Not merged yet -- that's the chief of staff's call per our branch policy, not mine to do.Both defects fixed and merged into dev (
56dd99c, PR #319): PlaylistDevicesTab.tsx disables a device already on another playlist or of a mismatching campus with the reason shown; DevicesScreen.tsx gets a campus-filtered playlist selector that assigns directly or confirms a move with replace: true. Server contract and tests (GRI-2200/GRI-2201) landed first; frontend tests added in PlaylistsScreen.test.tsx and DevicesScreen.test.tsx (205 passing). CI green on all 7 required contexts before merge.Merged
origin/devagain (picked up glamourweaver's PR #319, the panel half, frontend-only — no conflict with the test file) intotest/GRI-2200-assign-refusal-tests, now at149a680. Re-ran the fail-first suite:Same single gap as before, still unaddressed:
setting_a_devices_campus_to_no_campus_is_always_allowedfails becausePATCH /api/v1/devices/{id}withcampus_id: nulldoesn't clear it (UpdateDeviceRequest.campus_idindevices/handlers.rs:262is a plainOption<Uuid>, so absent and explicit-null both decode toNoneand the update is skipped). The playlist side already has theOption<Option<Uuid>>pattern for exactly this, from GRI-2201.cargo fmt/clippy -D warningsclean. Pushed.This is the one thing standing between PR #315 and green — once that handler is fixed to mirror the playlist pattern, all 14 should pass.