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
@@ -99,11 +99,11 @@ mitai-jinkendo/
|
||||
### Was in v9c kommt: Subscription & Coupon Management System
|
||||
**Phase 1 (DB-Schema): ✅ DONE**
|
||||
**Phase 2 (Backend API): ✅ DONE**
|
||||
**Phase 3 (Frontend UI): ⚡ MOSTLY DONE** (Kern-Features komplett, Self-Registration offen)
|
||||
**Phase 3 (Frontend UI): ✅ DONE** (Feature Enforcement komplett, Self-Registration offen)
|
||||
|
||||
**Core Features (Backend):**
|
||||
- ✅ DB-Schema (11 neue Tabellen, Feature-Registry Pattern)
|
||||
- ⚠️ Feature-Access Middleware (existiert, aber wird NICHT in Endpoints aufgerufen - siehe KRITISCH unten!)
|
||||
- ✅ **Feature-Access Enforcement** - Limits werden jetzt korrekt durchgesetzt!
|
||||
- ✅ Flexibles Tier-System (free/basic/premium/selfhosted) - Admin-editierbar via API
|
||||
- ✅ **Coupon-System** (3 Typen: single_use, period, wellpass)
|
||||
- ✅ Coupon-Stacking-Logik (Pause + Resume bei Wellpass-Override)
|
||||
@@ -120,47 +120,60 @@ mitai-jinkendo/
|
||||
- ✅ **AdminCouponsPage** - Coupon-Manager (CRUD, 3 Typen, auto-generate codes, redemption history)
|
||||
- ✅ **AdminUserRestrictionsPage** - User-Override-System (effektive Werte, auto-remove redundant overrides)
|
||||
- ✅ **SubscriptionPage** - User Subscription-Info + Coupon-Einlösung (tier badge, limits, usage progress bars)
|
||||
- ✅ **Feature Enforcement (März 2026)** - Backend + Frontend Feature Gates komplett implementiert
|
||||
- ✅ Alle Routes in App.jsx registriert
|
||||
- 🔲 Selbst-Registrierung mit E-Mail-Verifizierung (Pflicht)
|
||||
- 🔲 Trial-System UI (Countdown-Banner, auto-start nach E-Mail-Verifikation)
|
||||
- 🔲 App-Settings Admin-Panel (globale Konfiguration: trial_days, allow_registration, etc.)
|
||||
|
||||
**⚠️ KRITISCH: Feature-Enforcement fehlt noch! (März 2026)**
|
||||
**✅ Feature Enforcement Implementation (20. März 2026):**
|
||||
|
||||
**Problem:** Admin-UI zum Konfigurieren existiert, aber die eigentliche Prüfung/Durchsetzung fehlt!
|
||||
- User kann Limits überschreiten (KI-Analysen, Export, etc.)
|
||||
- Deaktivierte Features sind trotzdem nutzbar
|
||||
- Feature-Middleware existiert aber wird NICHT aufgerufen
|
||||
**Backend - Feature Checks in Endpoints:**
|
||||
- ✅ **routers/insights.py** - KI-Analysen geschützt
|
||||
- `analyze_with_prompt()` - prüft 'ai_calls' feature, wirft HTTP 403/429 bei Limit
|
||||
- `run_pipeline()` - prüft 'ai_pipeline' feature
|
||||
- Beide inkrementieren usage nach erfolgreicher Ausführung
|
||||
- ✅ **routers/exportdata.py** - Alle Export-Endpoints geschützt (CSV/JSON/ZIP)
|
||||
- Prüft 'data_export' feature, wirft HTTP 403 bei deaktiviert/429 bei Limit
|
||||
- Inkrementiert usage nach Export
|
||||
- ✅ **routers/importdata.py** - ZIP-Import geschützt
|
||||
- Prüft 'csv_import' feature vor Import
|
||||
- ✅ **routers/nutrition.py** - FDDB CSV-Import geschützt
|
||||
- Prüft 'csv_import' feature
|
||||
- ✅ **routers/activity.py** - Apple Health CSV-Import geschützt
|
||||
- Prüft 'csv_import' feature
|
||||
|
||||
**Backend TODO (KRITISCH):**
|
||||
- 🔲 **insights.py** - Feature-Checks für KI-Analysen einbauen
|
||||
```python
|
||||
@router.post('/run/{slug}')
|
||||
def run_analysis(slug: str, session = Depends(require_auth)):
|
||||
profile_id = session['profile_id']
|
||||
# TODO: check_feature_access(profile_id, 'ai_calls', action='use')
|
||||
# TODO: increment_feature_usage(profile_id, 'ai_calls')
|
||||
```
|
||||
- 🔲 **exportdata.py** - Feature-Check für Export (CSV/JSON/ZIP)
|
||||
- 🔲 **importdata.py** - Feature-Check für Import
|
||||
- 🔲 **nutrition.py** - Feature-Check für FDDB-Import
|
||||
- 🔲 **activity.py** - Feature-Check für Apple Health Import
|
||||
- 🔲 **photos.py** - Feature-Check für Progress-Fotos
|
||||
- 🔲 **weight.py, circumference.py, caliper.py** - Entry-Limits prüfen
|
||||
**Frontend - Feature Gate System:**
|
||||
- ✅ **hooks/useFeatureAccess.js** - Custom Hook für Feature-Access-Prüfung
|
||||
- Ruft `/api/features/{slug}/check-access` auf
|
||||
- Liefert: canUse, limit, used, remaining, reason, loading, error
|
||||
- Optimistic default (canUse=true) für bessere UX
|
||||
- ✅ **components/FeatureGate.jsx** - Reusable Feature Gate Component
|
||||
- `<FeatureGate>` - versteckt children wenn Feature nicht verfügbar
|
||||
- `<FeatureBadge>` - zeigt Usage-Counter (z.B. "3/10") mit Farb-Codierung
|
||||
- Upgrade-Prompt optional anzeigbar
|
||||
- ✅ **pages/Analysis.jsx** - KI-Analysen Feature-Gates
|
||||
- Pipeline-Button wrapped in `<FeatureGate feature="ai_pipeline">`
|
||||
- Einzelanalysen wrapped in `<FeatureGate feature="ai_calls">`
|
||||
- Usage-Counter in beiden Sektionen
|
||||
- ✅ **pages/SettingsPage.jsx** - Export/Import Feature-Gates
|
||||
- Export-Buttons wrapped in `<FeatureGate feature="data_export">`
|
||||
- Import-Button wrapped in `<FeatureGate feature="csv_import">`
|
||||
- Usage-Counter bei beiden
|
||||
- ✅ **utils/api.js** - API-Funktion hinzugefügt
|
||||
- `checkFeatureAccess(featureSlug)` für Frontend-Checks
|
||||
|
||||
**Frontend TODO (wichtig für UX):**
|
||||
- 🔲 `useFeatureAccess()` Hook implementieren
|
||||
```javascript
|
||||
const { canUse, remaining, limit } = useFeatureAccess('ai_calls')
|
||||
```
|
||||
- 🔲 `<FeatureGate feature="...">` Komponente erstellen
|
||||
- 🔲 Feature-Gates in Analysis-Seite (KI-Button ausblenden wenn limit=0)
|
||||
- 🔲 Feature-Gates in Settings (Export-Buttons)
|
||||
- 🔲 Feature-Gates in Import-Funktionen
|
||||
- 🔲 Limit-Anzeige ("3/10 KI-Analysen verbleibend")
|
||||
- 🔲 Upgrade-Prompt bei Limit erreicht
|
||||
**Verhalten:**
|
||||
- Backend wirft HTTP 403 "Feature nicht verfügbar" bei deaktiviertem Feature
|
||||
- Backend wirft HTTP 429 "Limit erreicht" bei überschrittenem Limit
|
||||
- Frontend blendet Feature aus oder zeigt Upgrade-Prompt
|
||||
- Usage-Counter zeigt aktuelle Nutzung (z.B. "5/10 AI-Calls")
|
||||
- Farb-Codierung: Grün (0-70%), Orange (70-90%), Rot (90-100%)
|
||||
|
||||
**Geschätzte Arbeit:** 2-3 Stunden (Backend 60%, Frontend 40%)
|
||||
**Noch NICHT geschützt (optional für v9d):**
|
||||
- 🔲 **photos.py** - Feature-Check für Progress-Fotos Upload
|
||||
- 🔲 **weight.py, circumference.py, caliper.py** - Entry-Limits prüfen (verhindert neue Einträge wenn Limit erreicht)
|
||||
- 🔲 **nutrition.py, activity.py** - Entry-Limits prüfen (analog zu weight)
|
||||
|
||||
**E-Mail Templates (v9c):**
|
||||
- 🔲 Registrierung + E-Mail-Verifizierung
|
||||
|
||||
Reference in new issue
Block a user