Repository navigation
refactor(catalog): resolve every library scope through AccessFilter.LibraryScope - #2006
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughLibrary access scope resolution is centralized and applied across catalog queries, collections, sections, and compatibility paths. The changes distinguish unrestricted access from an empty effective scope and add tests for library intersections, disabled IDs, and disjoint collection scopes. ChangesLibrary Access
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Possibly related PRs
Suggested reviewers: Merge Risk: ⚪ Minimal · up to This refactor centralizes library-scope handling and tightens empty-scope behavior, with no concrete defect identified. The author reports tests and an end-to-end comparison with no response differences. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Silo's pull request guidance changed today (#2016). A PR that changes what a user sees now needs before-and-after evidence in its Evidence section, and a PR with no visible change says Missing here: Needs the line 'Evidence: none, no user-visible change' (this PR's own commit is a refactor with identical responses). The rules are in Show visible changes, and the PR template shows the Evidence section layout. I've converted this PR to draft for now. Mark it ready for review once the Evidence section is filled in. Generated by Claude Code |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
The Evidence section says there is no user-visible change, but this PR changes section responses and visibility:
The reported tests and request-count comparison are not before-and-after response excerpts for these cases. The collection behavior previously mentioned is already in the current base, so it is not part of this diff. Suggested fix: Add the matching before-and-after API response excerpts under Evidence, with the surface and source builds or commits identified. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence Posted via Macroscope — Visible change evidence |
c499273 to
148153b
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
…ch scope Section queries intersected their own library_ids with the fetch's library set and stored the result. When the two shared no library the intersection was nil, which the query executor reads as "no library filter", so the section filled from every library in the viewer's scope instead of none. An admin previewing a custom filter scoped to one library with library_ids naming another got every library's items back; a smart collection rail whose saved libraries a restricted profile cannot reach filled from the profile's other libraries. applySectionLibraryScopeToQuery now reports when nothing survives, and every caller returns an empty section in that case. The editorial spotlight, seasonal and mood fetchers carried inline copies of the same switch; they now call the helper too.
…ibraryScope The rule "requested libraries (none = all), limited to the allowlist, minus disabled libraries; an empty result matches nothing" lived in effectiveCatalogLibraryIDs, its effectiveLibraryScope wrapper, and several hand-rolled copies. AccessFilter.LibraryScope is now the one implementation. Moved onto it: catalog browse and search access, the preview-page plan and its episode fast path, the search sort scope, Recently Added TV library resolution, playable-target file scope, discovery section scope, the calendar single-library check, server collection access, home section access filtering, the section query library scope, the collection-rail and returning-shows section scopes, and the Jellyfin-compat library narrowing and library listing. intersectLibraryIDs in the sections fetcher is gone. Callers that also exclude disabled libraries in SQL now receive a scope without them; the extra NOT EXISTS clause already removed those rows, so results do not change.
148153b to
cdba55a
Compare
|
The catalog/collection fail-closed behavior belongs to prerequisite #1953, and the section-intersection fix belongs to #2005. This PR changes the AccessFilter representation and preserves behavior. The current description reports the same-fixture before/after API comparison against the #2005 prerequisite; adding screenshots of ancestor fixes would misattribute their behavior to this refactor. |
Quick104
left a comment
There was a problem hiding this comment.
Reviewed head cdba55a1f. I found no code defects. One note below on the only reachable behavior change, plus one PR-body issue that I've already fixed.
PR body (fixed). The body still said to merge after #1953 and #2005 and called the refactor "the last commit", but both prerequisites have merged and the last commit is now fix(sections): match nothing when a section's fetch scope is empty, which the body didn't describe. I updated the Problem section to list both commits and say what the second one changes. The rest of the body is untouched.
Review by Claude Code (claude-opus-5-5).
| case libraryID != nil: | ||
| def.LibraryIDs = []int{*libraryID} | ||
| case libraryIDs != nil: | ||
| if len(libraryIDs) == 0 { |
There was a problem hiding this comment.
Low, informational. No change needed. This is the PR's only reachable behavior change. Before this line, libraryIDs = []int{} with a query that names no libraries left def.LibraryIDs nil, so the query ran unscoped.
Who reaches it:
- Home sections pass
scope.AllowedLibraryIDsas bothlibraryIDsandfilter.AllowedLibraryIDs(loadResolvedHomeSections). Jellycompat passesfilter.AllowedLibraryIDs. In both cases the filter already matched nothing, so results don't change. - v1
POST /api/admin/sections/previewdecodes"library_ids": []into a non-nil empty slice. For an unrestricted admin previewing a custom-filter section, the result goes from every library to nothing. - v2 preview runs
adminSectionLibraryIDs, which turns an empty list into nil, so v2 is unchanged.
The new behavior matches collectionRailQueryAccess, which already read an empty fetch scope as no access, so I think it's right. I added this to the PR body because the body said nothing changes.
Review summaryReviewed head: Addressed
Remaining: none blocking. The inline note on What I checked
Validated features: the body names #193 S1/S3 (Collections — Server) and #1196 C1 (User management / access groups — Server). The changes that reach them preserve behavior, and the author's 2,478-request comparison found no response differences. No re-test is needed beyond the normal hand-off after merge. User manual: no change. Library visibility rules are unchanged. Apple / Android: no API or response change, so no client work is needed. Jellyfin compat views and item lists are covered by the author's comparison. Fit: 9/10 · Readiness: 9/10 — ready
Review by Claude Code (claude-opus-5-5). |
Conflict resolution: - internal/userdb: main took SQLite schema v30 for the profile PIN revision (#2020). The login-wide sharing migration moves to v31, so a store already at main's v30 still runs it. - internal/catalog, internal/sections: main's fail-closed library scope (#1953, #2005, #2006) and this branch fixed the same empty-scope bug. The executor and section fetcher keep main's AccessFilter.LibraryScope; library collections keep this branch's ResolveLibraryCollectionMembership, which already returns nothing when the saved libraries miss the collection's own. main's scope test now exercises that resolver. narrowLibraryScope no longer needs the helper main removed. - internal/policy: main's hidden-library output (#2058) and this branch's ContentAccessOnly input both declared `hidden`; the input side is renamed. - Home sections (#2043): the admin per-profile card keeps main's row list but saves with this branch's override builder and a baseline, so like Settings > Home Screen it stores only what changed and untouched rows keep following the server. main's duplicate lib/sectionOverrides.ts is dropped; EditableSectionRows stays for that card and labels rows with rowKindLabel. Settings > Home Screen keeps this branch's page. - apiv2: keep both sides' services and fixtures; the admin profile section settings fixture gains default_title. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Problem
Related issue: N/A
Validation tasks: none changed (the refactor reaches #193 S1, S3 and #1196 C1; their behavior is unchanged)
#1953 and #2005 have merged. The diff is two commits:
refactor(catalog): resolve every library scope through AccessFilter.LibraryScopeandfix(sections): match nothing when a section's fetch scope is empty.The rule for which libraries a read may touch was implemented several times: catalog browse and search, the preview-page plan, Recently Added TV, playable targets, discovery and home sections, server collections, the calendar, and Jellyfin compat each had their own copy. The rule is: the requested libraries (none means all), limited to the viewer's allowed libraries, minus disabled libraries, and an empty result matches nothing. #1953 and #2005 fixed copies that read an empty result as "no library filter". With one implementation, a future change can't fix one copy and leave the others wrong.
The refactor has no intended behavior change. The second commit closes one gap:
applySectionLibraryScopeToQueryread an empty, non-nil fetch scope as "every library" when the section's query named no libraries. Home sections and Jellyfin compat pass the viewer's allowlist as both the fetch scope and the access filter, so their results don't change. The one caller whose result changes is the v1 admin preview,POST /api/admin/sections/previewwith"library_ids": []: a query-based section such as a custom filter now previews nothing instead of every library, which is how collection rails already treated an empty list. The v2 preview turns an emptylibrary_idsinto no scope, so it is unchanged.Approach
AccessFilter.LibraryScopeis now the only implementation. It returns the scope and a flag for "nothing survives". Callers that previously usedeffectiveCatalogLibraryIDs, theeffectiveLibraryScopewrapper, the sections fetcher'sintersectLibraryIDs, or inline loops now call it, and those helpers are removed.Some callers also exclude disabled libraries in SQL. They now get a scope that has those libraries removed already. The SQL
NOT EXISTSclause still runs and already excluded those rows, so results are the same.Validation
LibraryScopecover the allowlist, disabled-library, request-order, deduplication, nonexistent-library and empty-result combinations, and check that it does not alias its inputs.go testforinternal/sections,internal/catalog,internal/jellycompatandinternal/api/handlersagainst a fresh Postgres: pass, exceptTestAdminSubtitleListPageDB, which also fails on fix(catalog): return nothing when a requested library is outside the viewer's access #1953's head.make lint-changedandmake verify-local-paths: clean.make test-gowas not run.Evidence
This PR's own commit does not change any response. The visible change in this stack is #2005's: a section whose libraries miss the viewer's scope now returns nothing instead of filling from the viewer's other libraries. #2005's Evidence section shows that change before and after.
The two cases flagged in review give the same responses on #2005's head and on this PR's head: a section whose only library the profile has hidden, and a section or collection rail whose library is outside the viewer's scope. Test library with Movies, TV and Mixed libraries and synthetic files. Home sections "New on TV" (TV library), "New in Movies and TV", "New in Mixed" (Mixed library), and rails for the server collections "TV Classics" (TV library) and "Movie Classics" (Movies library).
Before (
3aef85313, head of #2005)After (
cdba55a1f, this PR's head)Home section lists are trimmed to the five sections above; "New on TV" is left out of both profiles' lists on both builds. The full JSON of all 24 native API responses, for these two profiles and an unrestricted Admin profile, is identical on both builds apart from request IDs in error bodies and the catalog
window_cursor, which encodes the request time. Jellyfin compat views and item lists for the admin account are identical as well.Surface and build:
/api/v2/home/sections,/api/v2/home/sections/{id}/items,/api/v2/collections/server,/api/v2/catalogand Jellyfin compat/Users/{id}/Viewsand/Users/{id}/Items. Before3aef85313(head of #2005), aftercdba55a1f(PR head), each server on a copy of the same database.Risks
Checklist
AI Disclosure
Note
Resolve all library access scoping through
AccessFilter.LibraryScopeAccessFilter.LibraryScoperesolver in access_filter.go that combines requested libraries, viewer allowlist, and disabled libraries. It distinguishes unrestricted access (nil) from an explicit empty scope, and covers table-driven tests including input aliasing.applySectionLibraryScopeToQuerynow returns a success flag and most section fetchers short-circuit to empty results when no library scope survives.applySectionLibraryScopeToQueryin fetcher.go andsingleEpisodeCatalogLibraryIDin episode_catalog_entries_executor.go.Macroscope summarized cdba55a.