Skip to content

Conversation

@jonathangreen
Copy link
Member

@jonathangreen jonathangreen commented Dec 10, 2025

Description

Note: This PR is still a work in progress.

Add library-level content filtering that allows administrators to hide catalog content by audience and/or genre. This enables libraries (particularly K-12 schools) to restrict content such as Adult-only materials or specific genres like Romance or Horror.

Changes include:

  • Add filtered_audiences and filtered_genres settings to LibrarySettings with validation against controlled vocabularies
  • Apply filters at search query time via OpenSearch must_not clauses
  • Apply filters to direct work lookup endpoints (permalink and URN lookup)
  • Add Work.is_filtered_for_library() helper method for reusable filtering logic

Motivation and Context

Libraries (especially K-12) need the ability to filter catalog content based on audience and genre. This feature allows library administrators to configure content restrictions that are automatically applied to search results and direct work lookups.

Implements PP-3237.

How Has This Been Tested?

  • Unit tests for LibrarySettings validation (filtered_audiences, filtered_genres)
  • Unit tests for Work.is_filtered_for_library() helper method
  • Unit tests for Filter.build() with library content filtering
  • End-to-end test for search filtering against OpenSearch
  • Integration tests for permalink endpoint filtering
  • Integration tests for URN lookup endpoint filtering

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

Add new library configuration options that allow library administrators
to specify which audiences and genres should be filtered from their
catalog. This is the first step in implementing catalog filtering for
K-12 schools that need to hide content matching certain metadata fields.

- Add filtered_audiences field with validation against Classifier.AUDIENCES
- Add filtered_genres field with validation against available genres
- Both fields use FormFieldType.MENU for multi-select UI
- Access level set to SYS_ADMIN_OR_MANAGER (library managers can configure)
- Add comprehensive tests for both fields
Modify the search Filter class to apply library-configured audience and
genre filters when building OpenSearch queries. The Filter now stores
filtered_audiences and filtered_genres from LibrarySettings at
construction time, and adds must_not clauses to exclude matching works.

This enables libraries to hide content by audience (Adult, Young Adult,
etc.) and/or genre (Romance, Horror, etc.) from catalog search results.

Includes unit tests and an end-to-end test against OpenSearch.
Add filtered_audiences and filtered_genres to expected output.
Add filtering for permalink and URN lookup endpoints based on library's
filtered_audiences and filtered_genres settings:

- Add Work.is_filtered_for_library() helper method to check if a work
  should be hidden for a library based on audience or genre filters
- Modify load_work() in CirculationManagerController to return 404
  for filtered works
- Modify URNLookupHandler to accept an optional library parameter and
  exclude filtered works from lookup results
- Add comprehensive tests for the new filtering behavior
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.80%. Comparing base (db08959) to head (a9e8a44).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2933      +/-   ##
==========================================
+ Coverage   92.78%   92.80%   +0.02%     
==========================================
  Files         454      454              
  Lines       42838    42892      +54     
  Branches     5974     5987      +13     
==========================================
+ Hits        39746    39805      +59     
+ Misses       2021     2017       -4     
+ Partials     1071     1070       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants