Update manager.py

This commit is contained in:
thekiwismarthome
2026-02-12 11:37:55 +13:00
committed by GitHub
parent 5e043d45f2
commit c114645f88
@@ -160,13 +160,34 @@ class ShoppingListManager:
async def _ensure_lists_loaded(self) -> None: async def _ensure_lists_loaded(self) -> None:
data = await self._store_lists.async_load() data = await self._store_lists.async_load()
if isinstance(data, dict): if isinstance(data, dict):
import time
# Migration: ensure new metadata fields exist
for list_id, meta in data.items():
if "owner" not in meta:
meta["owner"] = "system"
if "visibility" not in meta:
meta["visibility"] = "shared"
if "created_at" not in meta:
meta["created_at"] = time.time()
if "updated_at" not in meta:
meta["updated_at"] = time.time()
self._lists = data self._lists = data
await self._store_lists.async_save(self._lists)
return return
# Default: list_id == catalogue_id (current behavior) # Default: list_id == catalogue_id (current behavior)
import time
self._lists = { self._lists = {
"groceries": { "groceries": {
"catalogue": "groceries", "catalogue": "groceries",
"owner": "system",
"visibility": "shared",
"created_at": time.time(),
"updated_at": time.time(),
} }
} }
@@ -336,6 +357,17 @@ class ShoppingListManager:
def get_catalogues(self) -> Dict[str, dict]: def get_catalogues(self) -> Dict[str, dict]:
return self._catalogues return self._catalogues
def get_visible_lists(self, user):
if user.is_admin:
return self._lists
return {
lid: meta
for lid, meta in self._lists.items()
if meta.get("visibility") == "shared"
or meta.get("owner") == user.id
}
async def async_get_lists(self) -> Dict[str, dict]: async def async_get_lists(self) -> Dict[str, dict]:
await self._ensure_catalogues_loaded() await self._ensure_catalogues_loaded()
@@ -375,4 +407,4 @@ class ShoppingListManager:
# and would need updating to support per-list structure: # and would need updating to support per-list structure:
# - async_get_full_state() # - async_get_full_state()
# - get_product() # - get_product()
# - get_active_qty() # - get_active_qty()