@@ -72,14 +72,9 @@ class HasPermissionInContentLibraryScope(Rule):
7272 2. Parsing the library keys (org/slug) from the scopes
7373 3. Building database filters to match ContentLibrary models with those org/slug combinations
7474
75- This enables both individual object permission checks and efficient QuerySet
76- filtering - a key feature that allows database-level filtering instead of
77- checking each object individually.
78-
7975 Attributes:
80- action_external_key (str): The action/permission to check (e.g., 'view_library', 'edit_library').
81- This should be the external key WITHOUT the namespace prefix.
82- For example, use 'view_library' not 'act^view_library'.
76+ permission (PermissionData): The permission object representing the action to check
77+ (e.g., 'view', 'edit'). This is used to look up scopes in the authorization system.
8378
8479 filter_keys (list[str]): The Django model fields to use when building QuerySet filters.
8580 Defaults to ['org', 'slug'] for ContentLibrary models.
@@ -127,7 +122,6 @@ class HasPermissionInContentLibraryScope(Rule):
127122 >>> library = ContentLibrary.objects.get(org__short_name='DemoX', slug='CSPROB')
128123 >>> if perms['libraries.view_library'].check(request.user, library):
129124 ... # User can view this specific library
130- ... return render_library(library)
131125
132126 Note:
133127 The library keys in authorization scopes must have the format 'lib:ORG:SLUG'
@@ -150,14 +144,6 @@ def __init__(self, permission: PermissionData, filter_keys: list[str] | None = N
150144 def query (self , user ):
151145 """Convert this rule to a Django Q object for QuerySet filtering.
152146
153- This method enables efficient database-level filtering by:
154- 1. Querying the authorization system to get ALL library scopes where the user has this permission
155- 2. Parsing the library keys (org/slug pairs) from the scopes
156- 3. Building a Django Q object that filters for libraries matching those org/slug combinations
157-
158- This avoids N+1 query problems by filtering at the database level rather
159- than checking permission for each object individually.
160-
161147 Args:
162148 user: The Django user object (must have a 'username' attribute).
163149
0 commit comments