Merge branch 'xuhd' into 'master'

fix: /login/admin 自动把历史 admin 账户升级为 admin 角色

See merge request knowledge-base-bj/deerflow-server!8
This commit is contained in:
xu hd committed 2026-05-14 02:28:42 +00:00
commit 0bae393e07
1 file changed
+7
@@ -379,6 +379,13 @@ async def login_by_username(request: Request, response: Response, body: Username
user = await provider.get_user_by_email(email)
if user is None:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to create or load user")
elif body.username == "admin" and user.system_role != "admin":
# Historical accounts created before the username-based role assignment
# may still have system_role="user" — promote the canonical admin user
# so /login/admin behaves consistently.
user.system_role = "admin"
user = await provider.update_user(user)
logger.info("Promoted historical 'admin' account to system_role=admin: %s", email)
token = create_access_token(str(user.id), token_version=user.token_version)
_set_session_cookie(response, token, request)