mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-10-05 06:51:12 +01:00
fix(search): follow-ups to per-user book languages (#1267)
Review follow-ups to #1255, all in the code that PR touched. Drop the dead user_id from the Prowlarr retry path. ProwlarrSource.search never reads plan.languages, and _refresh_release builds a synthetic book with no titles_by_language, so the title variants came out identical with and without it. It also should not language-filter: it re-finds one exact release by its guid. Pin the tab move in tests. BOOK_LANGUAGE moved from the General tab to Search Mode with no migration, which only works because both tabs persist into the same settings.json. Nothing asserted that, so splitting the files later would silently reset every install to ["en"]. Covers the stored value, a fresh install, and ENV precedence. Stop the UI inventing a default language. An empty BOOK_LANGUAGE is a deliberate "no default filter" that the backend preserves, but the two frontend call sites replaced it with the first supported language, so the filter said English where the server filtered nothing. resolveDefaultLanguageCodes now falls back only when the value is absent. Keep the normalized value for every validated search key. validate_user_settings gated the write-back on a hand-maintained subset of the keys the search validator recognises, so METADATA_PROVIDER_COMBINED, SHOW_COMBINED_SELECTOR and FORCE_COMBINED_SEARCH were validated and then stored raw -- a padded provider name was accepted and persisted with its padding. Reuse the validator's own key set instead. Skip blank language entries rather than rejecting them, so "" and "en," mean the same as [] and ["en"] instead of erroring on an unnamed language. Extract resolveListOverride for the list-override detection that was copy-pasted between the two user-settings sections, and mention languages in the Search Preferences section description.
This commit is contained in:
@@ -534,6 +534,46 @@ class TestAdminUserUpdateEndpoint:
|
||||
)
|
||||
assert user_db.get_user_settings(user["id"]) == {}
|
||||
|
||||
def test_update_user_settings_skips_blank_book_languages(self, admin_client, user_db):
|
||||
"""A trailing comma or a blank slot means "nothing there", not an unknown language."""
|
||||
user = user_db.create_user(username="alice")
|
||||
|
||||
resp = admin_client.put(
|
||||
f"/api/admin/users/{user['id']}",
|
||||
json={"settings": {"BOOK_LANGUAGE": "en,"}},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert user_db.get_user_settings(user["id"])["BOOK_LANGUAGE"] == ["en"]
|
||||
|
||||
def test_update_user_settings_normalizes_every_validated_search_key(
|
||||
self, admin_client, user_db
|
||||
):
|
||||
"""Keys the search validator recognises keep their normalized value.
|
||||
|
||||
These three were validated but then stored raw, because the write-back was
|
||||
gated on a hand-maintained subset of the validated keys. A padded provider
|
||||
name was accepted and then persisted with its padding, so every later lookup
|
||||
of it failed.
|
||||
"""
|
||||
user = user_db.create_user(username="alice")
|
||||
|
||||
resp = admin_client.put(
|
||||
f"/api/admin/users/{user['id']}",
|
||||
json={
|
||||
"settings": {
|
||||
"METADATA_PROVIDER_COMBINED": " openlibrary ",
|
||||
"SHOW_COMBINED_SELECTOR": "yes",
|
||||
"FORCE_COMBINED_SEARCH": "",
|
||||
}
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
settings = user_db.get_user_settings(user["id"])
|
||||
assert settings["METADATA_PROVIDER_COMBINED"] == "openlibrary"
|
||||
assert settings["SHOW_COMBINED_SELECTOR"] is True
|
||||
assert settings["FORCE_COMBINED_SEARCH"] is False
|
||||
|
||||
def test_update_user_settings_accepts_notification_overrides(self, admin_client, user_db):
|
||||
user = user_db.create_user(username="alice")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user