Pass ?persona= query param on the help link so the server knows which persona to return to. Previously always defaulted to personas[0], causing navigation back to the wrong persona. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""
|
|
Help page router.
|
|
|
|
Routes:
|
|
GET /help → full-page help viewer (requires auth)
|
|
"""
|
|
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
import jwt
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
|
|
|
from auth_utils import COOKIE_NAME, decode_token
|
|
from persona import list_user_personas
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter()
|
|
|
|
_STATIC = Path(__file__).parent.parent / "static"
|
|
|
|
|
|
def _get_session_user(request: Request) -> str | None:
|
|
token = request.cookies.get(COOKIE_NAME)
|
|
if not token:
|
|
return None
|
|
try:
|
|
return decode_token(token)
|
|
except jwt.InvalidTokenError:
|
|
return None
|
|
|
|
|
|
@router.get("/help", include_in_schema=False)
|
|
async def help_page(request: Request, persona: str = ""):
|
|
username = _get_session_user(request)
|
|
if not username:
|
|
return RedirectResponse("/login", status_code=302)
|
|
|
|
personas = list_user_personas(username)
|
|
# Use persona from query param if valid, else fall back to first
|
|
if persona and persona in personas:
|
|
back_persona = persona
|
|
else:
|
|
back_persona = personas[0] if personas else ""
|
|
back_href = f"/{username}/{back_persona}" if back_persona else "/"
|
|
|
|
html = (_STATIC / "help.html").read_text()
|
|
config_tag = (
|
|
f'<script>window.HELP_CONFIG = '
|
|
f'{{user: "{username}", persona: "{back_persona}", backHref: "{back_href}"}};</script>'
|
|
)
|
|
html = html.replace("</head>", f"{config_tag}\n</head>", 1)
|
|
return HTMLResponse(html)
|