fix: add missing feature check endpoint and features
Critical fixes for feature enforcement:
- Add GET /api/features/{feature_id}/check-access endpoint (was missing!)
- Add migration for missing features: data_export, csv_import
- These features were used in frontend but didn't exist in DB
This fixes:
- "No analysis available" when setting KI limit
- Export features not working
- Frontend calling non-existent API endpoint
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
3745ebd6cd
commit
cbad50a987
2 files changed
+51
-1
No files matched your search
@@ -6,7 +6,7 @@ Admin-only CRUD for features registry.
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
|
||||
from db import get_db, get_cursor, r2d
|
||||
from auth import require_admin
|
||||
from auth import require_admin, require_auth, check_feature_access
|
||||
|
||||
router = APIRouter(prefix="/api/features", tags=["features"])
|
||||
|
||||
@@ -119,3 +119,20 @@ def delete_feature(feature_id: str, session: dict = Depends(require_admin)):
|
||||
cur.execute("UPDATE features SET active = false WHERE id = %s", (feature_id,))
|
||||
conn.commit()
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.get("/{feature_id}/check-access")
|
||||
def check_access(feature_id: str, session: dict = Depends(require_auth)):
|
||||
"""
|
||||
User: Check if current user can access a feature.
|
||||
|
||||
Returns:
|
||||
- allowed: bool - whether user can use the feature
|
||||
- limit: int|null - total limit (null = unlimited)
|
||||
- used: int - current usage
|
||||
- remaining: int|null - remaining uses (null = unlimited)
|
||||
- reason: str - why access is granted/denied
|
||||
"""
|
||||
profile_id = session['profile_id']
|
||||
result = check_feature_access(profile_id, feature_id)
|
||||
return result
|
||||
Reference in new issue
Block a user