子账号列表/删除接口加 is_subaccount=TRUE 过滤,避免把客户账号也算进去

This commit is contained in:
朱潮 2026-06-26 15:35:47 +08:00
parent 05a19f59e9
commit 2dab6de6a2

View File

@ -4327,10 +4327,11 @@ async def list_subaccounts(authorization: Optional[str] = Header(None)):
async with pool.connection() as conn:
async with conn.cursor() as cursor:
# 只查真正的子账号排除客户账号is_end_user=TRUE 的也挂在 parent_id 下)
await cursor.execute("""
SELECT id, username, email, is_active, created_at, last_login
FROM agent_user
WHERE parent_id = %s
WHERE parent_id = %s AND is_subaccount = TRUE
ORDER BY created_at DESC
""", (user_id,))
rows = await cursor.fetchall()
@ -4377,9 +4378,10 @@ async def delete_subaccount(
async with pool.connection() as conn:
async with conn.cursor() as cursor:
# 验证子账号属于当前用户
# 验证子账号属于当前用户(且确实是子账号,避免误删客户账号)
await cursor.execute("""
SELECT parent_id FROM agent_user WHERE id = %s
SELECT parent_id FROM agent_user
WHERE id = %s AND is_subaccount = TRUE
""", (subaccount_id,))
row = await cursor.fetchone()