feat: implement v9c feature enforcement system
Deploy Development / deploy (push) Successful in 34s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 12s

Backend:
- Add feature access checks to insights, export, import endpoints
- Enforce ai_calls, ai_pipeline, data_export, csv_import limits
- Return HTTP 403 (disabled) or 429 (limit exceeded)

Frontend:
- Create useFeatureAccess hook for feature checking
- Create FeatureGate/FeatureBadge components
- Gate KI-Analysen in Analysis page
- Gate Export/Import in Settings page
- Show usage counters (e.g. "3/10")

Docs:
- Update CLAUDE.md with implementation status

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-03-20 12:43:41 +01:00
1 parent 0210844522
commit 3745ebd6cd
12 files changed
+7176 -158

No files matched your search

+16 -1
View File
@@ -12,7 +12,7 @@ from datetime import datetime
from fastapi import APIRouter, HTTPException, UploadFile, File, Header, Depends
from db import get_db, get_cursor, r2d
from auth import require_auth
from auth import require_auth, check_feature_access, increment_feature_usage
from routers.profiles import get_pid
router = APIRouter(prefix="/api/nutrition", tags=["nutrition"])
@@ -30,6 +30,17 @@ def _pf(s):
async def import_nutrition_csv(file: UploadFile=File(...), x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)):
"""Import FDDB nutrition CSV."""
pid = get_pid(x_profile_id)
# Check feature access (v9c feature system)
access = check_feature_access(pid, 'csv_import')
if not access['allowed']:
if access['reason'] == 'feature_disabled':
raise HTTPException(403, "CSV-Import ist für dein Tier nicht verfügbar")
elif access['reason'] == 'limit_exceeded':
raise HTTPException(429, f"Monatliches Import-Limit erreicht ({access['limit']} Imports)")
else:
raise HTTPException(403, f"Zugriff verweigert: {access['reason']}")
raw = await file.read()
try: text = raw.decode('utf-8')
except: text = raw.decode('latin-1')
@@ -65,6 +76,10 @@ async def import_nutrition_csv(file: UploadFile=File(...), x_profile_id: Optiona
cur.execute("INSERT INTO nutrition_log (id,profile_id,date,kcal,protein_g,fat_g,carbs_g,source,created) VALUES (%s,%s,%s,%s,%s,%s,%s,'csv',CURRENT_TIMESTAMP)",
(str(uuid.uuid4()),pid,iso,kcal,prot,fat,carbs))
inserted+=1
# Increment import usage counter (v9c feature system)
increment_feature_usage(pid, 'csv_import')
return {"rows_parsed":count,"days_imported":inserted,
"date_range":{"from":min(days) if days else None,"to":max(days) if days else None}}