1111from http import HTTPStatus
1212
1313from ai .backend .common .api_handlers import APIResponse , BodyParam , PathParam
14+ from ai .backend .common .data .permission .types import (
15+ EntityType ,
16+ ScopeType ,
17+ )
1418from ai .backend .common .dto .manager .rbac import (
1519 AssignRoleRequest ,
1620 AssignRoleResponse ,
4448 SearchEntitiesResponse ,
4549 SearchScopesResponse ,
4650)
51+ from ai .backend .common .exception import RBACTypeConversionError
4752from ai .backend .manager .data .permission .role import UserRoleAssignmentInput , UserRoleRevocationInput
4853from ai .backend .manager .dto .context import UserContext
4954from ai .backend .manager .errors .permission import NotEnoughPermission
@@ -298,7 +303,13 @@ async def get_scope_types(
298303 action_result = await self ._permission_controller .get_scope_types .wait_for_complete (
299304 GetScopeTypesAction ()
300305 )
301- resp = GetScopeTypesResponse (items = action_result .scope_types )
306+ scope_types : list [ScopeType ] = []
307+ for et in action_result .element_types :
308+ try :
309+ scope_types .append (et .to_scope_type ())
310+ except RBACTypeConversionError :
311+ pass
312+ resp = GetScopeTypesResponse (items = scope_types )
302313 return APIResponse .build (status_code = HTTPStatus .OK , response_model = resp )
303314
304315 async def search_scopes (
@@ -312,8 +323,9 @@ async def search_scopes(
312323 raise NotEnoughPermission ("Only superadmin can search scopes." )
313324
314325 scope_type = path .parsed .scope_type
326+ element_type = scope_type .to_element ()
315327 querier = self ._scope_adapter .build_querier (scope_type , body .parsed )
316- action = SearchScopesAction (scope_type = scope_type , querier = querier )
328+ action = SearchScopesAction (element_type = element_type , querier = querier )
317329 action_result = await self ._permission_controller .search_scopes .wait_for_complete (action )
318330 resp = SearchScopesResponse (
319331 items = [self ._scope_adapter .convert_to_dto (item ) for item in action_result .result .items ],
@@ -338,7 +350,13 @@ async def get_entity_types(
338350 action_result = await self ._permission_controller .get_entity_types .wait_for_complete (
339351 GetEntityTypesAction ()
340352 )
341- resp = GetEntityTypesResponse (items = action_result .entity_types )
353+ entity_types : list [EntityType ] = []
354+ for et in action_result .element_types :
355+ try :
356+ entity_types .append (et .to_entity_type ())
357+ except RBACTypeConversionError :
358+ pass
359+ resp = GetEntityTypesResponse (items = entity_types )
342360 return APIResponse .build (status_code = HTTPStatus .OK , response_model = resp )
343361
344362 async def search_entities (
@@ -352,9 +370,9 @@ async def search_entities(
352370 raise NotEnoughPermission ("Only superadmin can search entities." )
353371
354372 querier = self ._entity_adapter .build_querier (
355- scope_type = path .parsed .scope_type ,
373+ scope_type = path .parsed .scope_type . to_element () ,
356374 scope_id = path .parsed .scope_id ,
357- entity_type = path .parsed .entity_type ,
375+ entity_type = path .parsed .entity_type . to_element () ,
358376 request = body .parsed ,
359377 )
360378 action = SearchEntitiesAction (querier = querier )
0 commit comments