@@ -40,6 +40,7 @@ class RoleScope(str, BaseEnum):
4040
4141class PermissionData (TypedDict ):
4242 collection : str
43+ tenant : str
4344
4445
4546class PermissionCollections (TypedDict ):
@@ -220,14 +221,15 @@ def _to_weaviate(self) -> List[WeaviatePermission]:
220221
221222class _TenantsPermission (_Permission [TenantsAction ]):
222223 collection : str
224+ tenant : str
223225
224226 def _to_weaviate (self ) -> List [WeaviatePermission ]:
225227 return [
226228 {
227229 "action" : action ,
228230 "tenants" : {
229231 "collection" : _capitalize_first_letter (self .collection ),
230- "tenant" : "*" ,
232+ "tenant" : self . tenant ,
231233 },
232234 }
233235 for action in self .actions
@@ -303,13 +305,15 @@ def _to_weaviate(self) -> List[WeaviatePermission]:
303305
304306class _DataPermission (_Permission [DataAction ]):
305307 collection : str
308+ tenant : str
306309
307310 def _to_weaviate (self ) -> List [WeaviatePermission ]:
308311 return [
309312 {
310313 "action" : action ,
311314 "data" : {
312315 "collection" : _capitalize_first_letter (self .collection ),
316+ "tenant" : self .tenant ,
313317 },
314318 }
315319 for action in self .actions
@@ -428,6 +432,7 @@ def _from_weaviate_role(cls, role: WeaviateRole) -> "Role":
428432 tenants_permissions .append (
429433 TenantsPermissionOutput (
430434 collection = tenants ["collection" ],
435+ tenant = tenants .get ("tenant" , "*" ),
431436 actions = {TenantsAction (permission ["action" ])},
432437 )
433438 )
@@ -448,6 +453,7 @@ def _from_weaviate_role(cls, role: WeaviateRole) -> "Role":
448453 data_permissions .append (
449454 DataPermissionOutput (
450455 collection = data ["collection" ],
456+ tenant = data .get ("tenant" , "*" ),
451457 actions = {DataAction (permission ["action" ])},
452458 )
453459 )
@@ -576,6 +582,7 @@ class Permissions:
576582 def data (
577583 * ,
578584 collection : Union [str , Sequence [str ]],
585+ tenant : Union [str , Sequence [str ], None ] = None ,
579586 create : bool = False ,
580587 read : bool = False ,
581588 update : bool = False ,
@@ -584,20 +591,25 @@ def data(
584591 permissions : List [_Permission ] = []
585592 if isinstance (collection , str ):
586593 collection = [collection ]
594+ if tenant is None :
595+ tenant = ["*" ]
596+ if isinstance (tenant , str ):
597+ tenant = [tenant ]
587598 for c in collection :
588- permission = _DataPermission (collection = c , actions = set ())
589-
590- if create :
591- permission .actions .add (DataAction .CREATE )
592- if read :
593- permission .actions .add (DataAction .READ )
594- if update :
595- permission .actions .add (DataAction .UPDATE )
596- if delete :
597- permission .actions .add (DataAction .DELETE )
598-
599- if len (permission .actions ) > 0 :
600- permissions .append (permission )
599+ for t in tenant :
600+ permission = _DataPermission (collection = c , tenant = t , actions = set ())
601+
602+ if create :
603+ permission .actions .add (DataAction .CREATE )
604+ if read :
605+ permission .actions .add (DataAction .READ )
606+ if update :
607+ permission .actions .add (DataAction .UPDATE )
608+ if delete :
609+ permission .actions .add (DataAction .DELETE )
610+
611+ if len (permission .actions ) > 0 :
612+ permissions .append (permission )
601613 return permissions
602614
603615 @staticmethod
@@ -631,6 +643,7 @@ def collections(
631643 def tenants (
632644 * ,
633645 collection : Union [str , Sequence [str ]],
646+ tenant : Union [str , Sequence [str ], None ] = None ,
634647 create : bool = False ,
635648 read : bool = False ,
636649 update : bool = False ,
@@ -639,19 +652,25 @@ def tenants(
639652 permissions : List [_Permission ] = []
640653 if isinstance (collection , str ):
641654 collection = [collection ]
655+ if tenant is None :
656+ tenant = ["*" ]
657+ if isinstance (tenant , str ):
658+ tenant = [tenant ]
642659 for c in collection :
643- permission = _TenantsPermission (collection = c , actions = set ())
644- if create :
645- permission .actions .add (TenantsAction .CREATE )
646- if read :
647- permission .actions .add (TenantsAction .READ )
648- if update :
649- permission .actions .add (TenantsAction .UPDATE )
650- if delete :
651- permission .actions .add (TenantsAction .DELETE )
652-
653- if len (permission .actions ) > 0 :
654- permissions .append (permission )
660+ for t in tenant :
661+ permission = _TenantsPermission (collection = c , tenant = t , actions = set ())
662+
663+ if create :
664+ permission .actions .add (TenantsAction .CREATE )
665+ if read :
666+ permission .actions .add (TenantsAction .READ )
667+ if update :
668+ permission .actions .add (TenantsAction .UPDATE )
669+ if delete :
670+ permission .actions .add (TenantsAction .DELETE )
671+
672+ if len (permission .actions ) > 0 :
673+ permissions .append (permission )
655674
656675 return permissions
657676
0 commit comments