mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 02:24:09 +01:00
fixes
This commit is contained in:
@@ -112,6 +112,10 @@ router.include_router(notes_router)
|
||||
router.include_router(patch_router)
|
||||
|
||||
|
||||
# RomUser fields the statuses filter branches on.
|
||||
STATUS_MEMBERSHIP_FIELDS = frozenset({"status", "now_playing", "backlogged", "hidden"})
|
||||
|
||||
|
||||
def safe_int_or_none(value: Any) -> int | None:
|
||||
if value is None or value == "":
|
||||
return None
|
||||
@@ -2119,7 +2123,9 @@ async def update_rom_user(
|
||||
if "hidden" in cleaned_data:
|
||||
db_rom_handler.invalidate_filter_values_cache()
|
||||
|
||||
if "status" in cleaned_data:
|
||||
# The statuses filter reads all four of these, and `hidden` also drops the
|
||||
# ROM from every user-scoped query, so any of them can move membership.
|
||||
if STATUS_MEMBERSHIP_FIELDS & cleaned_data.keys():
|
||||
refresh_affected_smart_collections([id], membership_only=True)
|
||||
|
||||
return RomUserSchema.model_validate(rom_user)
|
||||
|
||||
@@ -780,3 +780,28 @@ class TestSmartCollectionEndpoints:
|
||||
refreshed = db_collection_handler.get_smart_collection(smart_collection.id)
|
||||
assert refreshed is not None
|
||||
assert refreshed.rom_ids == [rom.id]
|
||||
|
||||
@pytest.mark.parametrize("field", ("now_playing", "backlogged", "hidden"))
|
||||
def test_setting_a_rom_flag_refreshes_membership(
|
||||
self, client, access_token: str, admin_user: User, rom: Rom, field: str
|
||||
):
|
||||
smart_collection = db_collection_handler.add_smart_collection(
|
||||
SmartCollection(
|
||||
name=f"Flagged {field}",
|
||||
description="",
|
||||
user_id=admin_user.id,
|
||||
filter_criteria={"statuses": [field]},
|
||||
)
|
||||
)
|
||||
db_collection_handler.refresh_smart_collection(smart_collection.id)
|
||||
|
||||
response = client.put(
|
||||
f"/api/roms/{rom.id}/props",
|
||||
json={field: True},
|
||||
headers={"Authorization": f"Bearer {access_token}"},
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
refreshed = db_collection_handler.get_smart_collection(smart_collection.id)
|
||||
assert refreshed is not None
|
||||
assert refreshed.rom_ids == [rom.id]
|
||||
|
||||
Reference in New Issue
Block a user