fix: manuelle Lebensmittel in der Liste wieder bearbeiten
Admin-Katalog und Nutzer-Liste oeffnen den Editor statt nur die Lesansicht; PUT gilt fuer zentrale und persoenliche Manuals. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8b1e1da5d8
commit
9a0767c8ac
9 files changed
+59
-20
No files matched your search
@@ -29,6 +29,10 @@ _KIND_VIS = {
|
||||
_VIS_RANK = {VIS_PERSONAL: 0, VIS_GLOBAL: 1, VIS_BLS: 2}
|
||||
|
||||
|
||||
def same_id(a, b) -> bool:
|
||||
return str(a or "").replace("-", "").lower() == str(b or "").replace("-", "").lower()
|
||||
|
||||
|
||||
def visibility_of(food: dict[str, Any] | None) -> str:
|
||||
if not food:
|
||||
return VIS_BLS
|
||||
|
||||
@@ -188,7 +188,7 @@ def admin_list_foods(
|
||||
|
||||
|
||||
@router.get("/foods/{food_id}")
|
||||
def admin_food_detail(food_id: str, session: dict = Depends(require_admin)):
|
||||
def admin_food_detail(food_id: str, editor: bool = False, session: dict = Depends(require_admin)):
|
||||
from data_layer.nutrition_items import resolve_food_attributes
|
||||
|
||||
with get_db() as conn:
|
||||
@@ -197,6 +197,13 @@ def admin_food_detail(food_id: str, session: dict = Depends(require_admin)):
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, "Lebensmittel nicht gefunden")
|
||||
food = dict(row)
|
||||
if editor:
|
||||
from data_layer.food_attributes import editor_payload_for_food
|
||||
from data_layer.food_visibility import attach_visibility
|
||||
|
||||
editable = food.get("catalog_kind") in ("manual_admin", "manual_user")
|
||||
return attach_visibility(editor_payload_for_food(cur, food, editable=editable))
|
||||
attrs = resolve_food_attributes(cur, food_id)
|
||||
return {**r2d(row), "attributes": attrs}
|
||||
|
||||
@@ -252,13 +259,13 @@ def admin_update_manual_food(food_id: str, body: ManualFoodCreate, session: dict
|
||||
"""
|
||||
SELECT id, name_de, name_en, catalog_kind, owner_profile_id
|
||||
FROM food_catalog
|
||||
WHERE id = %s AND catalog_kind = 'manual_admin' AND is_active = true
|
||||
WHERE id = %s AND catalog_kind IN ('manual_admin', 'manual_user') AND is_active = true
|
||||
""",
|
||||
(food_id,),
|
||||
)
|
||||
food = cur.fetchone()
|
||||
if not food:
|
||||
raise HTTPException(404, "Zentrales Lebensmittel nicht gefunden")
|
||||
raise HTTPException(404, "Manuelles Lebensmittel nicht gefunden")
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE food_catalog
|
||||
|
||||
@@ -238,8 +238,8 @@ def get_food_detail(food_id: str, session: dict = Depends(require_auth)):
|
||||
if not food:
|
||||
raise HTTPException(404, "Lebensmittel nicht gefunden")
|
||||
food = dict(food)
|
||||
editable = food.get("catalog_kind") == "manual_user" and str(food.get("owner_profile_id") or "") == str(pid)
|
||||
from data_layer.food_visibility import attach_visibility
|
||||
from data_layer.food_visibility import attach_visibility, same_id
|
||||
editable = food.get("catalog_kind") == "manual_user" and same_id(food.get("owner_profile_id"), pid)
|
||||
return attach_visibility(editor_payload_for_food(cur, food, editable=editable))
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,16 @@ from data_layer.food_visibility import (
|
||||
is_global_mapping_target,
|
||||
is_visible_to,
|
||||
require_mapping_target,
|
||||
same_id,
|
||||
visibility_of,
|
||||
visibility_rank,
|
||||
)
|
||||
|
||||
|
||||
def test_same_id_ignores_dashes_and_case():
|
||||
assert same_id("AaBbCcDd-0000-0000-0000-000000000001", "aabbccdd000000000000000000000001")
|
||||
|
||||
|
||||
def test_visibility_scopes():
|
||||
assert visibility_of({"catalog_kind": "official_bls"}) == "bls"
|
||||
assert visibility_of({"catalog_kind": "manual_admin", "owner_profile_id": None}) == "global"
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ MODULE_VERSIONS = {
|
||||
"activity": "1.2.1", # Legacy CSV import: activity_entries feature enforcement
|
||||
"nutrition": "1.3.7", # Sichtbarkeit persönlich vs. zentral im Mapping
|
||||
"tandoor": "1.0.1", # Router-Import ohne future-annotations (Backend startet)
|
||||
"bls": "1.0.9", # Nutzer-Foods privat, Admin-Foods zentral; Mapping achtet Sichtbarkeit
|
||||
"bls": "1.0.10", # Manuelle Liste: Zeile öffnet Editor; Admin darf alle Manuals ändern
|
||||
|
||||
"photos": "1.0.0",
|
||||
"insights": "1.3.0",
|
||||
|
||||
Reference in new issue
Block a user