@@ -23,6 +23,7 @@ class RoleScope(str, BaseEnum):
2323
2424class PermissionData (TypedDict ):
2525 collection : str
26+ tenant : str
2627
2728
2829class PermissionCollections (TypedDict ):
@@ -192,14 +193,15 @@ def _to_weaviate(self) -> List[WeaviatePermission]:
192193
193194class _TenantsPermission (_Permission [TenantsAction ]):
194195 collection : str
196+ tenant : str
195197
196198 def _to_weaviate (self ) -> List [WeaviatePermission ]:
197199 return [
198200 {
199201 "action" : action ,
200202 "tenants" : {
201203 "collection" : _capitalize_first_letter (self .collection ),
202- "tenant" : "*" ,
204+ "tenant" : self . tenant ,
203205 },
204206 }
205207 for action in self .actions
@@ -275,13 +277,15 @@ def _to_weaviate(self) -> List[WeaviatePermission]:
275277
276278class _DataPermission (_Permission [DataAction ]):
277279 collection : str
280+ tenant : str
278281
279282 def _to_weaviate (self ) -> List [WeaviatePermission ]:
280283 return [
281284 {
282285 "action" : action ,
283286 "data" : {
284287 "collection" : _capitalize_first_letter (self .collection ),
288+ "tenant" : self .tenant ,
285289 },
286290 }
287291 for action in self .actions
@@ -396,6 +400,7 @@ def _from_weaviate_role(cls, role: WeaviateRole) -> "Role":
396400 tenants_permissions .append (
397401 TenantsPermissionOutput (
398402 collection = tenants ["collection" ],
403+ tenant = tenants .get ("tenant" , "*" ),
399404 actions = {TenantsAction (permission ["action" ])},
400405 )
401406 )
@@ -416,6 +421,7 @@ def _from_weaviate_role(cls, role: WeaviateRole) -> "Role":
416421 data_permissions .append (
417422 DataPermissionOutput (
418423 collection = data ["collection" ],
424+ tenant = data .get ("tenant" , "*" ),
419425 actions = {DataAction (permission ["action" ])},
420426 )
421427 )
@@ -550,6 +556,7 @@ class Permissions:
550556 def data (
551557 * ,
552558 collection : Union [str , Sequence [str ]],
559+ tenant : Union [str , Sequence [str ], None ] = None ,
553560 create : bool = False ,
554561 read : bool = False ,
555562 update : bool = False ,
@@ -558,20 +565,25 @@ def data(
558565 permissions : List [_Permission ] = []
559566 if isinstance (collection , str ):
560567 collection = [collection ]
568+ if tenant is None :
569+ tenant = ["*" ]
570+ if isinstance (tenant , str ):
571+ tenant = [tenant ]
561572 for c in collection :
562- permission = _DataPermission (collection = c , actions = set ())
563-
564- if create :
565- permission .actions .add (DataAction .CREATE )
566- if read :
567- permission .actions .add (DataAction .READ )
568- if update :
569- permission .actions .add (DataAction .UPDATE )
570- if delete :
571- permission .actions .add (DataAction .DELETE )
572-
573- if len (permission .actions ) > 0 :
574- permissions .append (permission )
573+ for t in tenant :
574+ permission = _DataPermission (collection = c , tenant = t , actions = set ())
575+
576+ if create :
577+ permission .actions .add (DataAction .CREATE )
578+ if read :
579+ permission .actions .add (DataAction .READ )
580+ if update :
581+ permission .actions .add (DataAction .UPDATE )
582+ if delete :
583+ permission .actions .add (DataAction .DELETE )
584+
585+ if len (permission .actions ) > 0 :
586+ permissions .append (permission )
575587 return permissions
576588
577589 @staticmethod
@@ -605,6 +617,7 @@ def collections(
605617 def tenants (
606618 * ,
607619 collection : Union [str , Sequence [str ]],
620+ tenant : Union [str , Sequence [str ], None ] = None ,
608621 create : bool = False ,
609622 read : bool = False ,
610623 update : bool = False ,
@@ -613,19 +626,25 @@ def tenants(
613626 permissions : List [_Permission ] = []
614627 if isinstance (collection , str ):
615628 collection = [collection ]
629+ if tenant is None :
630+ tenant = ["*" ]
631+ if isinstance (tenant , str ):
632+ tenant = [tenant ]
616633 for c in collection :
617- permission = _TenantsPermission (collection = c , actions = set ())
618- if create :
619- permission .actions .add (TenantsAction .CREATE )
620- if read :
621- permission .actions .add (TenantsAction .READ )
622- if update :
623- permission .actions .add (TenantsAction .UPDATE )
624- if delete :
625- permission .actions .add (TenantsAction .DELETE )
626-
627- if len (permission .actions ) > 0 :
628- permissions .append (permission )
634+ for t in tenant :
635+ permission = _TenantsPermission (collection = c , tenant = t , actions = set ())
636+
637+ if create :
638+ permission .actions .add (TenantsAction .CREATE )
639+ if read :
640+ permission .actions .add (TenantsAction .READ )
641+ if update :
642+ permission .actions .add (TenantsAction .UPDATE )
643+ if delete :
644+ permission .actions .add (TenantsAction .DELETE )
645+
646+ if len (permission .actions ) > 0 :
647+ permissions .append (permission )
629648
630649 return permissions
631650
0 commit comments