1111import pytest
1212import sqlalchemy as sa
1313
14- from ai .backend .common .data .permission .types import EntityType , OperationType , ScopeType
14+ from ai .backend .common .data .permission .types import (
15+ EntityType ,
16+ OperationType ,
17+ RBACElementType ,
18+ )
1519from ai .backend .manager .data .permission .id import ObjectId
1620from ai .backend .manager .data .permission .types import RoleSource
1721from ai .backend .manager .models .rbac_models .permission .permission import PermissionRow
@@ -46,7 +50,7 @@ class SingleEntityWithRoleContext:
4650 """Context with single entity granted to a role."""
4751
4852 entity_id : ObjectId
49- entity_scope_type : ScopeType
53+ entity_scope_type : RBACElementType
5054 role_id : UUID
5155
5256
@@ -55,7 +59,7 @@ class EntityWithTwoRolesContext:
5559 """Context with entity granted to two different roles."""
5660
5761 entity_id : ObjectId
58- entity_scope_type : ScopeType
62+ entity_scope_type : RBACElementType
5963 role_id1 : UUID
6064 role_id2 : UUID
6165
@@ -90,7 +94,7 @@ async def single_entity_with_role(
9094 ) -> AsyncGenerator [SingleEntityWithRoleContext , None ]:
9195 """Create entity with role having permissions."""
9296 entity_id = ObjectId (entity_type = EntityType .VFOLDER , entity_id = str (uuid .uuid4 ()))
93- entity_scope_type = ScopeType .VFOLDER
97+ entity_scope_type = RBACElementType .VFOLDER
9498
9599 role_id : UUID
96100
@@ -108,7 +112,7 @@ async def single_entity_with_role(
108112 for op in [OperationType .READ , OperationType .UPDATE ]:
109113 perm = PermissionRow (
110114 role_id = role .id ,
111- scope_type = entity_scope_type ,
115+ scope_type = entity_scope_type . to_scope_type () ,
112116 scope_id = entity_id .entity_id ,
113117 entity_type = entity_id .entity_type ,
114118 operation = op ,
@@ -231,7 +235,7 @@ async def entity_with_two_roles(
231235 ) -> AsyncGenerator [EntityWithTwoRolesContext , None ]:
232236 """Create entity granted to two different roles."""
233237 entity_id = ObjectId (entity_type = EntityType .VFOLDER , entity_id = str (uuid .uuid4 ()))
234- entity_scope_type = ScopeType .VFOLDER
238+ entity_scope_type = RBACElementType .VFOLDER
235239
236240 role_id1 : UUID
237241 role_id2 : UUID
@@ -256,7 +260,7 @@ async def entity_with_two_roles(
256260 for role in [role1 , role2 ]:
257261 perm = PermissionRow (
258262 role_id = role .id ,
259- scope_type = entity_scope_type ,
263+ scope_type = entity_scope_type . to_scope_type () ,
260264 scope_id = entity_id .entity_id ,
261265 entity_type = entity_id .entity_type ,
262266 operation = OperationType .READ ,
@@ -331,7 +335,7 @@ async def single_entity_with_role(
331335 ) -> AsyncGenerator [SingleEntityWithRoleContext , None ]:
332336 """Create entity with role having permissions."""
333337 entity_id = ObjectId (entity_type = EntityType .VFOLDER , entity_id = str (uuid .uuid4 ()))
334- entity_scope_type = ScopeType .VFOLDER
338+ entity_scope_type = RBACElementType .VFOLDER
335339
336340 role_id : UUID
337341
@@ -346,7 +350,7 @@ async def single_entity_with_role(
346350
347351 perm = PermissionRow (
348352 role_id = role .id ,
349- scope_type = entity_scope_type ,
353+ scope_type = entity_scope_type . to_scope_type () ,
350354 scope_id = entity_id .entity_id ,
351355 entity_type = entity_id .entity_type ,
352356 operation = OperationType .READ ,
0 commit comments