fix: zentrale Lebensmittel fuer Admins aenderbar
Deploy Development / deploy (push) Successful in 1m7s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 23s

Persoenliche Liste bleibt beim Owner; zentrale Eintraege oeffnen den Admin-Editor. Admin-Katalog trennt beide Listen, persoenliche bleiben sichtbar.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-09-14 13:01:41 +02:00
1 parent 9a0767c8ac
commit e452d9a8fe
13 files changed
+134 -45

No files matched your search

+13 -1
View File
@@ -62,7 +62,7 @@ def is_visible_to(food: dict[str, Any] | None, profile_id: str | None) -> bool:
owner = food.get("owner_profile_id")
if owner is None:
return True
return profile_id is not None and str(owner) == str(profile_id)
return profile_id is not None and same_id(owner, profile_id)
def is_global_mapping_target(food: dict[str, Any] | None) -> bool:
@@ -104,6 +104,18 @@ def require_mapping_target(cur, food_id: str, mapping_profile_id: str | None) ->
return require_global_mapping_target(cur, food_id)
def can_edit_food(food: dict[str, Any] | None, profile_id: str | None, *, is_admin: bool = False) -> bool:
"""Owner ändert persönlich; Admin ändert zentral (und im Admin-Katalog auch fremde Manuals)."""
if not is_active(food):
return False
kind = food.get("catalog_kind")
if kind == "manual_user":
return same_id(food.get("owner_profile_id"), profile_id) or bool(is_admin)
if kind == "manual_admin":
return bool(is_admin)
return False
def attach_visibility(row: dict[str, Any]) -> dict[str, Any]:
row["visibility"] = visibility_of(row)
return row
+2 -2
View File
@@ -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)
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)
from data_layer.food_visibility import attach_visibility, can_edit_food
editable = can_edit_food(food, pid, is_admin=session.get("role") == "admin")
return attach_visibility(editor_payload_for_food(cur, food, editable=editable))
+13
View File
@@ -1,5 +1,6 @@
from data_layer.food_visibility import (
attach_visibility,
can_edit_food,
is_global_mapping_target,
is_visible_to,
require_mapping_target,
@@ -9,6 +10,18 @@ from data_layer.food_visibility import (
)
def test_can_edit_central_only_as_admin():
central = {"catalog_kind": "manual_admin", "owner_profile_id": None, "is_active": True}
personal = {"catalog_kind": "manual_user", "owner_profile_id": "alice", "is_active": True}
bls = {"catalog_kind": "official_bls", "owner_profile_id": None, "is_active": True}
assert can_edit_food(central, "alice", is_admin=False) is False
assert can_edit_food(central, "alice", is_admin=True) is True
assert can_edit_food(personal, "alice", is_admin=False) is True
assert can_edit_food(personal, "bob", is_admin=False) is False
assert can_edit_food(personal, "bob", is_admin=True) is True
assert can_edit_food(bls, "alice", is_admin=True) is False
def test_same_id_ignores_dashes_and_case():
assert same_id("AaBbCcDd-0000-0000-0000-000000000001", "aabbccdd000000000000000000000001")
+1 -1
View File
@@ -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.10", # Manuelle Liste: Zeile öffnet Editor; Admin darf alle Manuals ändern
"bls": "1.0.11", # Zentrale Manuals: Admin-Editor inkl. Nutzerliste; Admin-Katalog getrennt
"photos": "1.0.0",
"insights": "1.3.0",