fix: admin видит чужие сессии через /?tab=UUID
get_history() ищет по username+tab_id. Если пусто и role=admin, fallback на get_history_any_user(tab_id) — без фильтра по username. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ from fastapi.responses import FileResponse, HTMLResponse, StreamingResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from auth import authenticate, verify_token
|
||||
from db import get_history, init_db, list_sessions, save_message
|
||||
from db import get_history, get_history_any_user, init_db, list_sessions, save_message
|
||||
|
||||
# Backend: "claude" (Docker sandbox), "glm" (GLM-5 + CAG), "auto" (route by task)
|
||||
AI_BACKEND = os.environ.get("AI_BACKEND", "claude")
|
||||
@@ -217,7 +217,14 @@ async def chat(request: Request):
|
||||
async def history(request: Request):
|
||||
user = _get_user(request)
|
||||
tab_id = request.headers.get("x-tab-id", "default")
|
||||
return get_history(user, tab_id)
|
||||
# Try own history first; if empty and admin — try any user's history for this tab
|
||||
result = get_history(user, tab_id)
|
||||
if not result:
|
||||
from auth import get_token_role
|
||||
token = request.headers.get("authorization", "").removeprefix("Bearer ").strip()
|
||||
if get_token_role(token) == "admin":
|
||||
result = get_history_any_user(tab_id)
|
||||
return result
|
||||
|
||||
|
||||
@app.get("/api/sessions")
|
||||
|
||||
Reference in New Issue
Block a user