Acceptance tests: settings global and per-campus, with fallback (#161) #178

Closed
opened 2026-11-14 03:10:28 +00:00 by prismancer · 1 comment
Member

Acceptance tests for #161, written before the implementation (process: tests first, written by QA, same as #172/#174).

Scope

Playback defaults only, to start: default_duration_seconds, the field playlists already require ([crates/server/src/playlists/handlers.rs], validate_duration: must be > 0). Two levels — global (one value, server-wide) and per campus (optional override) — with the campus falling back to global when unset.

Proposed contract (mine to build; flag here if the shape is wrong before you write against it)

New table, migration 0007: playback_settings(campus_id UUID NULL UNIQUE REFERENCES campus(id) ON DELETE CASCADE, default_duration_seconds INTEGER NOT NULL), campus_id IS NULL is the single global row (a partial unique index guards there only ever being one). Same NULL = "global" convention crate::campus already uses.

  • GET /api/v1/settings/playback — the global default. Requires settings_manage and campus_id IS NULL on the caller (unscoped admin or unscoped settings_manage holder). A campus-scoped caller gets 403, same wording as the existing settings.manage is required on /api/v1/settings.
  • PUT /api/v1/settings/playback — body {"default_duration_seconds": 10}, same permission as the GET, 400 invalid_duration when <= 0.
  • GET /api/v1/campuses/{campus_id}/settings/playback — the effective value for that campus: {"default_duration_seconds": {"value": 15, "source": "campus"|"global"}}. Any signed-in user may read their own campus; an admin or an unscoped user may read any. A campus-scoped caller naming a different campus, or an unknown campus id, both get 404 — not 403, same rule #172/#174 already use for media/playlists outside scope.
  • PUT /api/v1/campuses/{campus_id}/settings/playback — requires settings_manage and may_access(Some(campus_id)) (crate::auth::CurrentUser::may_access). Body {"default_duration_seconds": 20} sets an override; {"default_duration_seconds": null} clears it (falls back to global). Same 404-not-403 for out-of-scope/unknown campus, same 400 invalid_duration for <= 0.

A gap this closes, worth its own test

Today SetupOrSignedIn (crates/server/src/settings.rs) lets any settings_manage holder see and change the existing global-only settings (GET/PUT /api/v1/settings, /api/v1/server/restart, the setup-wizard database routes) — it checks may(SettingsManage) but never campus_id.is_none(). A campus-scoped admin with settings_manage can today read and rewrite the server's reverse-proxy/public-URL/mail/sign-in settings. Please add a test that a campus-scoped settings_manage user gets 403 from GET/PUT /api/v1/settings once this lands — that's "only a user with the global-settings permission sees global settings" from the done-when.

Test scenarios

  • Global GET/PUT: an unscoped settings_manage user succeeds; a campus-scoped settings_manage user gets 403 on both.
  • Campus GET for a campus with no override returns source: "global" and the global value; after a PUT with a value, returns source: "campus" and that value; after a PUT with null, back to source: "global".
  • Campus GET/PUT: a user scoped to campus A gets 404 on campus B's path (not 403), and 404 on an unknown campus id.
  • Campus GET/PUT: an unscoped user (admin or campus_id: None) may act on any campus, including one not their own.
  • PUT with default_duration_seconds <= 0 on either endpoint: 400 invalid_duration, nothing written.
  • GET/PUT /api/v1/settings (existing global settings): a campus-scoped settings_manage user is refused 403 (the gap above).

Put these wherever the existing settings tests already live (crates/server/src/settings.rs's own #[cfg(test)] mod tests, or a new crates/server/tests/... integration file if you'd rather keep campus-scoping tests together with #172/#174's) — your call on the file. Push on a branch and open the PR, marked the way the suite already marks not-yet-implemented behaviour, so #161 can make them pass.

Acceptance tests for #161, written **before** the implementation (process: tests first, written by QA, same as #172/#174). ## Scope Playback defaults only, to start: `default_duration_seconds`, the field playlists already require ([`crates/server/src/playlists/handlers.rs`], `validate_duration`: must be `> 0`). Two levels — **global** (one value, server-wide) and **per campus** (optional override) — with the campus falling back to global when unset. ## Proposed contract (mine to build; flag here if the shape is wrong before you write against it) New table, migration `0007`: `playback_settings(campus_id UUID NULL UNIQUE REFERENCES campus(id) ON DELETE CASCADE, default_duration_seconds INTEGER NOT NULL)`, `campus_id IS NULL` is the single global row (a partial unique index guards there only ever being one). Same `NULL` = "global" convention `crate::campus` already uses. - `GET /api/v1/settings/playback` — the global default. Requires `settings_manage` **and** `campus_id IS NULL` on the caller (unscoped admin or unscoped `settings_manage` holder). A campus-scoped caller gets **403**, same wording as the existing `settings.manage is required` on `/api/v1/settings`. - `PUT /api/v1/settings/playback` — body `{"default_duration_seconds": 10}`, same permission as the GET, `400 invalid_duration` when `<= 0`. - `GET /api/v1/campuses/{campus_id}/settings/playback` — the effective value for that campus: `{"default_duration_seconds": {"value": 15, "source": "campus"|"global"}}`. Any signed-in user may read their **own** campus; an admin or an unscoped user may read any. A campus-scoped caller naming a *different* campus, or an unknown campus id, both get **404** — not 403, same rule #172/#174 already use for media/playlists outside scope. - `PUT /api/v1/campuses/{campus_id}/settings/playback` — requires `settings_manage` **and** `may_access(Some(campus_id))` (`crate::auth::CurrentUser::may_access`). Body `{"default_duration_seconds": 20}` sets an override; `{"default_duration_seconds": null}` clears it (falls back to global). Same 404-not-403 for out-of-scope/unknown campus, same `400 invalid_duration` for `<= 0`. ## A gap this closes, worth its own test Today `SetupOrSignedIn` (`crates/server/src/settings.rs`) lets **any** `settings_manage` holder see and change the existing global-only settings (`GET`/`PUT /api/v1/settings`, `/api/v1/server/restart`, the setup-wizard database routes) — it checks `may(SettingsManage)` but never `campus_id.is_none()`. A campus-scoped admin with `settings_manage` can today read and rewrite the *server's* reverse-proxy/public-URL/mail/sign-in settings. Please add a test that a campus-scoped `settings_manage` user gets **403** from `GET`/`PUT /api/v1/settings` once this lands — that's "only a user with the global-settings permission sees global settings" from the done-when. ## Test scenarios - Global GET/PUT: an unscoped `settings_manage` user succeeds; a campus-scoped `settings_manage` user gets 403 on both. - Campus GET for a campus with no override returns `source: "global"` and the global value; after a PUT with a value, returns `source: "campus"` and that value; after a PUT with `null`, back to `source: "global"`. - Campus GET/PUT: a user scoped to campus A gets 404 on campus B's path (not 403), and 404 on an unknown campus id. - Campus GET/PUT: an unscoped user (admin or `campus_id: None`) may act on any campus, including one not their own. - `PUT` with `default_duration_seconds <= 0` on either endpoint: `400 invalid_duration`, nothing written. - `GET`/`PUT /api/v1/settings` (existing global settings): a campus-scoped `settings_manage` user is refused 403 (the gap above). Put these wherever the existing settings tests already live (`crates/server/src/settings.rs`'s own `#[cfg(test)] mod tests`, or a new `crates/server/tests/...` integration file if you'd rather keep campus-scoping tests together with #172/#174's) — your call on the file. Push on a branch and open the PR, marked the way the suite already marks not-yet-implemented behaviour, so #161 can make them pass.
Member

Tests are up on PR #179 (test/GRI-1997-settings-acceptance-tests -> dev): 16 acceptance tests in crates/server/tests/settings_playback_acceptance_integration.rs, one per scenario bullet above.

Fail-first, run against the current (unimplemented) code: 0 passed, 16 failed -- every failure is a 404 (route/table does not exist) or, for the two existing-/api/v1/settings-gap tests, a 200 where a 403 is required.

CI on the PR: green, except CI / cargo deny advisories, which is a pre-existing failure on dev itself, unrelated to this change (GRI-1872: gtk-renderer feature advisories, red on every branch). My branch touches only the new test file and no dependency tree.

Proposed route/migration contract is still above for the back-end engineer to flag against if the shape needs to change. Closing this issue -- tests are written and verified fail-first. Handing off to the CTO to release implementation.

Tests are up on PR #179 (test/GRI-1997-settings-acceptance-tests -> dev): 16 acceptance tests in crates/server/tests/settings_playback_acceptance_integration.rs, one per scenario bullet above. Fail-first, run against the current (unimplemented) code: 0 passed, 16 failed -- every failure is a 404 (route/table does not exist) or, for the two existing-/api/v1/settings-gap tests, a 200 where a 403 is required. CI on the PR: green, except CI / cargo deny advisories, which is a pre-existing failure on dev itself, unrelated to this change (GRI-1872: gtk-renderer feature advisories, red on every branch). My branch touches only the new test file and no dependency tree. Proposed route/migration contract is still above for the back-end engineer to flag against if the shape needs to change. Closing this issue -- tests are written and verified fail-first. Handing off to the CTO to release implementation.
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#178
No description provided.