@@ -32,47 +32,12 @@ class AclEntry:
3232 permissions : List [str ] = field (default_factory = list )
3333 """List of permission strings granted to this principal."""
3434
35- def has_permission (self , permission : str ) -> bool :
36- """
37- Check if this ACL entry includes a specific permission.
38-
39- Arguments:
40- permission: The permission string to check for (e.g., 'READ', 'DOWNLOAD').
41-
42- Returns:
43- True if the permission is granted, False otherwise.
44- """
45- return permission in self .permissions
46-
47- def add_permission (self , permission : str ) -> None :
48- """
49- Add a permission to this ACL entry if not already present.
50-
51- Arguments:
52- permission: The permission string to add.
53- """
54- if permission not in self .permissions :
55- self .permissions .append (permission )
56-
57- def remove_permission (self , permission : str ) -> None :
58- """
59- Remove a permission from this ACL entry if present.
60-
61- Arguments:
62- permission: The permission string to remove.
63- """
64- if permission in self .permissions :
65- self .permissions .remove (permission )
66-
6735
6836@dataclass
6937class EntityAcl :
7038 """
7139 Represents the complete Access Control List for a single Synapse entity.
7240
73- This dataclass contains all ACL entries for an entity, organizing them
74- by principal ID and providing convenient methods for ACL management.
75-
7641 Attributes:
7742 entity_id: The Synapse ID of the entity (e.g., "syn123").
7843 acl_entries: List of ACL entries, each representing permissions for a principal.
@@ -84,76 +49,6 @@ class EntityAcl:
8449 acl_entries : List [AclEntry ] = field (default_factory = list )
8550 """List of ACL entries, each representing permissions for a principal."""
8651
87- def get_acl_entry (self , principal_id : str ) -> Optional [AclEntry ]:
88- """
89- Get the ACL entry for a specific principal.
90-
91- Arguments:
92- principal_id: The ID of the principal to look up.
93-
94- Returns:
95- The AclEntry for the principal, or None if not found.
96- """
97- for entry in self .acl_entries :
98- if entry .principal_id == principal_id :
99- return entry
100- return None
101-
102- def get_principals (self ) -> List [str ]:
103- """
104- Get a list of all principal IDs that have ACL entries for this entity.
105-
106- Returns:
107- List of principal ID strings.
108- """
109- return [entry .principal_id for entry in self .acl_entries ]
110-
111- def get_permissions_for_principal (self , principal_id : str ) -> List [str ]:
112- """
113- Get the permissions list for a specific principal.
114-
115- Arguments:
116- principal_id: The ID of the principal to look up.
117-
118- Returns:
119- List of permission strings, or empty list if principal not found.
120- """
121- entry = self .get_acl_entry (principal_id )
122- return entry .permissions if entry else []
123-
124- def add_acl_entry (self , acl_entry : AclEntry ) -> None :
125- """
126- Add an ACL entry to this entity ACL.
127-
128- If an entry for the same principal already exists, it will be replaced.
129-
130- Arguments:
131- acl_entry: The ACL entry to add.
132- """
133- # Remove existing entry for the same principal if it exists
134- self .acl_entries = [
135- entry
136- for entry in self .acl_entries
137- if entry .principal_id != acl_entry .principal_id
138- ]
139- self .acl_entries .append (acl_entry )
140-
141- def remove_acl_entry (self , principal_id : str ) -> bool :
142- """
143- Remove the ACL entry for a specific principal.
144-
145- Arguments:
146- principal_id: The ID of the principal whose ACL entry should be removed.
147-
148- Returns:
149- True if an entry was removed, False if the principal was not found.
150- """
151- original_length = len (self .acl_entries )
152- self .acl_entries = [
153- entry for entry in self .acl_entries if entry .principal_id != principal_id
154- ]
155- return len (self .acl_entries ) < original_length
156-
15752 @classmethod
15853 def from_dict (cls , entity_id : str , acl_dict : Dict [str , List [str ]]) -> "EntityAcl" :
15954 """
@@ -211,78 +106,9 @@ class AclListResult:
211106 entity_acls : List [EntityAcl ] = field (default_factory = list )
212107 """List of EntityAcl objects, each representing the ACL for one entity."""
213108
214- def get_entity_acl (self , entity_id : str ) -> Optional [EntityAcl ]:
215- """
216- Get the ACL for a specific entity.
217-
218- Arguments:
219- entity_id: The Synapse ID of the entity to look up.
220-
221- Returns:
222- The EntityAcl for the entity, or None if not found.
223- """
224- for entity_acl in self .entity_acls :
225- if entity_acl .entity_id == entity_id :
226- return entity_acl
227- return None
228-
229- def get_entity_ids (self ) -> List [str ]:
230- """
231- Get a list of all entity IDs included in this ACL result.
232-
233- Returns:
234- List of entity ID strings.
235- """
236- return [entity_acl .entity_id for entity_acl in self .entity_acls ]
237-
238- def get_permissions_for_entity_and_principal (
239- self , entity_id : str , principal_id : str
240- ) -> List [str ]:
241- """
242- Get the permissions for a specific principal on a specific entity.
243-
244- Arguments:
245- entity_id: The Synapse ID of the entity.
246- principal_id: The ID of the principal.
247-
248- Returns:
249- List of permission strings, or empty list if entity or principal not found.
250- """
251- entity_acl = self .get_entity_acl (entity_id )
252- if entity_acl :
253- return entity_acl .get_permissions_for_principal (principal_id )
254- return []
255-
256- def add_entity_acl (self , entity_acl : EntityAcl ) -> None :
257- """
258- Add an EntityAcl to this result.
259-
260- If an ACL for the same entity already exists, it will be replaced.
261-
262- Arguments:
263- entity_acl: The EntityAcl to add.
264- """
265- # Remove existing ACL for the same entity if it exists
266- self .entity_acls = [
267- acl for acl in self .entity_acls if acl .entity_id != entity_acl .entity_id
268- ]
269- self .entity_acls .append (entity_acl )
270-
271- def remove_entity_acl (self , entity_id : str ) -> bool :
272- """
273- Remove the ACL for a specific entity.
274-
275- Arguments:
276- entity_id: The Synapse ID of the entity whose ACL should be removed.
277-
278- Returns:
279- True if an ACL was removed, False if the entity was not found.
280- """
281- original_length = len (self .entity_acls )
282- self .entity_acls = [
283- acl for acl in self .entity_acls if acl .entity_id != entity_id
284- ]
285- return len (self .entity_acls ) < original_length
109+ ascii_tree : Optional [str ] = None
110+ """Optional ASCII tree representation of the ACLs. This is only populated when
111+ `log_tree` is set to True when calling `list_acl_async`."""
286112
287113 @classmethod
288114 def from_dict (cls , acl_dict : Dict [str , Dict [str , List [str ]]]) -> "AclListResult" :
@@ -332,49 +158,3 @@ def to_dict(self) -> Dict[str, Dict[str, List[str]]]:
332158 entity_acl .entity_id : entity_acl .to_dict ()
333159 for entity_acl in self .entity_acls
334160 }
335-
336- def get_all_principals (self ) -> List [str ]:
337- """
338- Get a list of all unique principal IDs across all entities in this result.
339-
340- Returns:
341- List of unique principal ID strings.
342- """
343- all_principals = set ()
344- for entity_acl in self .entity_acls :
345- all_principals .update (entity_acl .get_principals ())
346- return list (all_principals )
347-
348- def get_entities_for_principal (self , principal_id : str ) -> List [str ]:
349- """
350- Get a list of entity IDs where the specified principal has any permissions.
351-
352- Arguments:
353- principal_id: The ID of the principal to look up.
354-
355- Returns:
356- List of entity ID strings where the principal has permissions.
357- """
358- entity_ids = []
359- for entity_acl in self .entity_acls :
360- if entity_acl .get_acl_entry (principal_id ):
361- entity_ids .append (entity_acl .entity_id )
362- return entity_ids
363-
364- def is_empty (self ) -> bool :
365- """
366- Check if this result contains any ACL data.
367-
368- Returns:
369- True if there are no entity ACLs, False otherwise.
370- """
371- return len (self .entity_acls ) == 0
372-
373- def __len__ (self ) -> int :
374- """
375- Get the number of entities in this ACL result.
376-
377- Returns:
378- The number of entities with ACL data.
379- """
380- return len (self .entity_acls )
0 commit comments