Skip to content

Commit d72cd5c

Browse files
authored
fix(BA-1006): superadmin query agent nodes (#3996)
1 parent d9b1ef1 commit d72cd5c

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

changes/3996.fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow superadmins to query all GQL agent nodes

src/ai/backend/manager/models/gql_models/agent.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ai.backend.logging.utils import BraceStyleAdapter
3232

3333
from ..agent import (
34+
ADMIN_PERMISSIONS,
3435
AgentRow,
3536
AgentStatus,
3637
agents,
@@ -305,21 +306,28 @@ async def get_connection(
305306
)
306307
async with graph_ctx.db.connect() as db_conn:
307308
user = graph_ctx.user
308-
client_ctx = ClientContext(
309-
graph_ctx.db, user["domain_name"], user["uuid"], user["role"]
310-
)
311-
permission_ctx = await get_permission_ctx(db_conn, client_ctx, scope, permission)
312-
cond = permission_ctx.query_condition
313-
if cond is None:
314-
return ConnectionResolverResult([], cursor, pagination_order, page_size, 0)
315-
query = query.where(cond)
316-
cnt_query = cnt_query.where(cond)
309+
if user["role"] != UserRole.SUPERADMIN:
310+
client_ctx = ClientContext(
311+
graph_ctx.db, user["domain_name"], user["uuid"], user["role"]
312+
)
313+
permission_ctx = await get_permission_ctx(db_conn, client_ctx, scope, permission)
314+
cond = permission_ctx.query_condition
315+
if cond is None:
316+
return ConnectionResolverResult([], cursor, pagination_order, page_size, 0)
317+
permission_getter = permission_ctx.calculate_final_permission
318+
query = query.where(cond)
319+
cnt_query = cnt_query.where(cond)
320+
else:
321+
322+
async def all_permissions(row):
323+
return ADMIN_PERMISSIONS
324+
325+
permission_getter = all_permissions
317326
async with graph_ctx.db.begin_readonly_session(db_conn) as db_session:
318327
agent_rows = (await db_session.scalars(query)).all()
319328
total_cnt = await db_session.scalar(cnt_query)
320329
result: list[AgentNode] = [
321-
cls.parse(info, row, await permission_ctx.calculate_final_permission(row))
322-
for row in agent_rows
330+
cls.parse(info, row, await permission_getter(row)) for row in agent_rows
323331
]
324332

325333
return ConnectionResolverResult(result, cursor, pagination_order, page_size, total_cnt)

0 commit comments

Comments
 (0)