feat: implement v9c feature enforcement system
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:
1 parent
0210844522
commit
3745ebd6cd
12 files changed
+7176
-158
No files matched your search
@@ -13,7 +13,7 @@ from datetime import datetime
|
||||
from fastapi import APIRouter, HTTPException, Header, Depends
|
||||
|
||||
from db import get_db, get_cursor, r2d
|
||||
from auth import require_auth, require_admin
|
||||
from auth import require_auth, require_admin, check_feature_access, increment_feature_usage
|
||||
from routers.profiles import get_pid
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["insights"])
|
||||
@@ -251,7 +251,16 @@ def delete_ai_insight(scope: str, x_profile_id: Optional[str]=Header(default=Non
|
||||
async def analyze_with_prompt(slug: str, x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)):
|
||||
"""Run AI analysis with specified prompt template."""
|
||||
pid = get_pid(x_profile_id)
|
||||
check_ai_limit(pid)
|
||||
|
||||
# Check feature access (v9c feature system)
|
||||
access = check_feature_access(pid, 'ai_calls')
|
||||
if not access['allowed']:
|
||||
if access['reason'] == 'feature_disabled':
|
||||
raise HTTPException(403, "KI-Analysen sind für dein Tier nicht verfügbar")
|
||||
elif access['reason'] == 'limit_exceeded':
|
||||
raise HTTPException(429, f"Monatliches KI-Limit erreicht ({access['limit']} Analysen)")
|
||||
else:
|
||||
raise HTTPException(403, f"Zugriff verweigert: {access['reason']}")
|
||||
|
||||
# Get prompt template
|
||||
with get_db() as conn:
|
||||
@@ -301,7 +310,8 @@ async def analyze_with_prompt(slug: str, x_profile_id: Optional[str]=Header(defa
|
||||
cur.execute("INSERT INTO ai_insights (id, profile_id, scope, content, created) VALUES (%s,%s,%s,%s,CURRENT_TIMESTAMP)",
|
||||
(str(uuid.uuid4()), pid, slug, content))
|
||||
|
||||
inc_ai_usage(pid)
|
||||
# Increment usage counter (v9c feature system)
|
||||
increment_feature_usage(pid, 'ai_calls')
|
||||
return {"scope": slug, "content": content}
|
||||
|
||||
|
||||
@@ -309,7 +319,16 @@ async def analyze_with_prompt(slug: str, x_profile_id: Optional[str]=Header(defa
|
||||
async def analyze_pipeline(x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)):
|
||||
"""Run 3-stage pipeline analysis."""
|
||||
pid = get_pid(x_profile_id)
|
||||
check_ai_limit(pid)
|
||||
|
||||
# Check feature access for pipeline (v9c feature system)
|
||||
access = check_feature_access(pid, 'ai_pipeline')
|
||||
if not access['allowed']:
|
||||
if access['reason'] == 'feature_disabled':
|
||||
raise HTTPException(403, "KI-Pipeline ist für dein Tier nicht verfügbar")
|
||||
elif access['reason'] == 'limit_exceeded':
|
||||
raise HTTPException(429, f"Monatliches Pipeline-Limit erreicht ({access['limit']} Pipelines)")
|
||||
else:
|
||||
raise HTTPException(403, f"Zugriff verweigert: {access['reason']}")
|
||||
|
||||
data = _get_profile_data(pid)
|
||||
vars = _prepare_template_vars(data)
|
||||
@@ -438,7 +457,8 @@ async def analyze_pipeline(x_profile_id: Optional[str]=Header(default=None), ses
|
||||
cur.execute("INSERT INTO ai_insights (id, profile_id, scope, content, created) VALUES (%s,%s,'gesamt',%s,CURRENT_TIMESTAMP)",
|
||||
(str(uuid.uuid4()), pid, final_content))
|
||||
|
||||
inc_ai_usage(pid)
|
||||
# Increment pipeline usage counter (v9c feature system)
|
||||
increment_feature_usage(pid, 'ai_pipeline')
|
||||
return {"scope": "gesamt", "content": final_content, "stage1": stage1_results}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user