@@ -172,7 +172,9 @@ def get_subclass_by_external_key(mcs, external_key: str) -> Type["ScopeData"]:
172172 scope_subclass = mcs .scope_registry .get (namespace )
173173
174174 if not scope_subclass :
175- raise ValueError (f"Unknown scope: { namespace } for external_key: { external_key } " )
175+ raise ValueError (
176+ f"Unknown scope: { namespace } for external_key: { external_key } "
177+ )
176178
177179 if not scope_subclass .validate_external_key (external_key ):
178180 raise ValueError (f"Invalid external_key format: { external_key } " )
@@ -261,6 +263,14 @@ def validate_external_key(cls, external_key: str) -> bool:
261263 except InvalidKeyError :
262264 return False
263265
266+ def __str__ (self ):
267+ """Human readable string representation of the content library."""
268+ return self .library_id
269+
270+ def __repr__ (self ):
271+ """Developer friendly string representation of the content library."""
272+ return self .namespaced_key
273+
264274
265275class SubjectMeta (type ):
266276 """Metaclass for SubjectData to handle dynamic subclass instantiation based on namespace."""
@@ -342,6 +352,14 @@ def username(self) -> str:
342352 """
343353 return self .external_key
344354
355+ def __str__ (self ):
356+ """Human readable string representation of the user."""
357+ return self .username
358+
359+ def __repr__ (self ):
360+ """Developer friendly string representation of the user."""
361+ return self .namespaced_key
362+
345363
346364@define
347365class ActionData (AuthZData ):
@@ -365,9 +383,17 @@ def name(self) -> str:
365383 """
366384 return self .external_key .replace ("_" , " " ).title ()
367385
386+ def __str__ (self ):
387+ """Human readable string representation of the action."""
388+ return self .name
389+
390+ def __repr__ (self ):
391+ """Developer friendly string representation of the action."""
392+ return self .namespaced_key
393+
368394
369395@define
370- class PermissionData ( AuthZData ) :
396+ class PermissionData :
371397 """A permission is an action that can be performed under certain conditions.
372398
373399 Attributes:
@@ -377,6 +403,14 @@ class PermissionData(AuthZData):
377403 action : ActionData = None
378404 effect : Literal ["allow" , "deny" ] = "allow"
379405
406+ def __str__ (self ):
407+ """Human readable string representation of the permission and its effect."""
408+ return f"{ self .action } - { self .effect } "
409+
410+ def __repr__ (self ):
411+ """Developer friendly string representation of the permission."""
412+ return f"{ self .action .namespaced_key } => { self .effect } "
413+
380414
381415@define
382416class RoleData (AuthZData ):
@@ -402,9 +436,17 @@ def name(self) -> str:
402436 """
403437 return self .external_key .replace ("_" , " " ).title ()
404438
439+ def __str__ (self ):
440+ """Human readable string representation of the role and its permissions."""
441+ return f"{ self .name } : { ', ' .join (str (p ) for p in self .permissions )} "
442+
443+ def __repr__ (self ):
444+ """Developer friendly string representation of the role."""
445+ return self .namespaced_key
446+
405447
406448@define
407- class RoleAssignmentData ( AuthZData ) :
449+ class RoleAssignmentData :
408450 """A role assignment is the assignment of a role to a subject in a specific scope.
409451
410452 Attributes:
@@ -416,3 +458,13 @@ class RoleAssignmentData(AuthZData):
416458 subject : SubjectData = None # Needs defaults to avoid value error from attrs
417459 roles : list [RoleData ] = []
418460 scope : ScopeData = None
461+
462+ def __str__ (self ):
463+ """Human readable string representation of the role assignment."""
464+ role_names = ", " .join (role .name for role in self .roles )
465+ return f"{ self .subject } => { role_names } @ { self .scope } "
466+
467+ def __repr__ (self ):
468+ """Developer friendly string representation of the role assignment."""
469+ role_keys = ", " .join (role .namespaced_key for role in self .roles )
470+ return f"{ self .subject .namespaced_key } => [{ role_keys } ] @ { self .scope .namespaced_key } "
0 commit comments