{"record":{"id":"02343de614fd98ad","repo":"HKUDS/DeepTutor","slug":"admin-access-required","errorCode":null,"errorMessage":"Admin access required","messagePattern":"Admin access required","errorType":"http","errorClass":"HTTPException","httpStatus":403,"severity":"error","filePath":"deeptutor/api/routers/auth.py","lineNumber":344,"sourceCode":"\nasync def require_admin(\n    payload: TokenPayload | None = Depends(require_auth),\n) -> TokenPayload:\n    \"\"\"\n    FastAPI dependency that requires the caller to be an admin.\n\n    Raises HTTP 403 if the authenticated user is not an admin.\n    When AUTH_ENABLED=false, all requests are treated as admin.\n\n    ``async def`` mirrors ``require_auth`` so the dependency chain stays on\n    the event loop and the user ContextVar set by ``require_auth`` is visible\n    to the endpoint.\n    \"\"\"\n    if not AUTH_ENABLED:\n        return _local_admin_token_payload()\n\n    if payload is None or payload.role != \"admin\":\n        raise HTTPException(\n            status_code=status.HTTP_403_FORBIDDEN,\n            detail=\"Admin access required\",\n        )\n    return payload\n\n\ndef _local_admin_token_payload() -> TokenPayload:\n    \"\"\"Synthetic admin payload used when AUTH_ENABLED=false.\n\n    Mirrors the local admin identity (LOCAL_ADMIN_USERNAME / LOCAL_ADMIN_ID)\n    so audit logs and self-reference checks behave the same as in multi-user\n    mode. Values are kept aligned with ``local_admin_user()`` in\n    ``deeptutor/multi_user/paths.py``.\n    \"\"\"\n    from deeptutor.multi_user.models import LOCAL_ADMIN_ID, LOCAL_ADMIN_USERNAME\n\n    return TokenPayload(\n        username=LOCAL_ADMIN_USERNAME,","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/api/routers/auth.py#L326-L362","documentation":"Error \"Admin access required\" thrown in HKUDS/DeepTutor.","triggerScenarios":"Thrown at deeptutor/api/routers/auth.py:344 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}