Files
artcraft-services/crates/schema/database
Dylan M. Taylor ec461047a5 fix: enforce private media visibility for reads and batch lists (#226)
## Summary

Two endpoints returned private media records without comparing
`creator_set_visibility` against the requester, so knowing a token was
enough to read another user's private media, including its storage
locations and transcripts.

**Single-file lookup** (`media_files/get/get_media_file_handler.rs`)
- The handler now passes the viewer's `user_token` into both lookup
branches.
- A shared `ensure_may_read_media` helper returns `NotFound` for
`Visibility::Private` records unless the viewer is the creator or a
moderator. The same policy now applies to the legacy `TR:` TTS emulation
branch, which previously had no check at all.
- `NotFound` rather than `NotAuthorized` avoids confirming that a
private token exists. This mirrors the check in `get_weight_handler.rs`.

**Batch listing**
(`media_files/list/list_media_files_by_batch_token_handler.rs`)
- The endpoint hard-coded `ViewAs::Author` with a "this is wrong, but
gotta go fast" TODO, so any caller holding a batch token received every
record in the batch regardless of visibility.
- Scope now derives from the session: `Moderator` for moderators,
`Author` for other logged-in users, `AnotherUser` for anonymous callers.
- `maybe_creator_user_token` is selected with the page so private
records are dropped for anyone who is neither the creator nor a
moderator.

## Notes

- Public and hidden media behave as before; only private access changes.
- For non-moderators the batch page can be shorter than `page_size`, and
`total_page_count` still counts records the caller may not read, because
filtering happens after the query. Fixing that properly needs
visibility-aware SQL and is left for a follow-up.
- Verified with `SQLX_OFFLINE=true cargo check -p storyteller-web`
(finished clean). No tests were added or run: the media endpoints are
covered by integration tests that need a live MySQL, which is not
available here.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Private media files are visible only to their creator or a moderator.
Other viewers will not see private files in batch listings, and direct
requests return not found.
* Access rules apply consistently to standard media files and legacy
text-to-speech results.
* Viewer identity is recognized from an authenticated session or a
viewer token, allowing creators to access their private media without
signing in.
  * Public media remains accessible according to existing permissions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:59:51 -05:00
..