Skip to content

Commit 439f680

Browse files
committed
refact(discovery): rm unused ScopeableModel method + docstrings
1 parent 412573c commit 439f680

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

chord_metadata_service/authz/viewset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def _get_scope_for_request(self, request: DrfRequest) -> ValidatedDiscover
2828

2929
async def obj_is_in_request_scope(self, request: DrfRequest, obj: BaseScopeableModel) -> bool:
3030
scope = await self._get_scope_for_request(request)
31-
return await obj.scope_contains_object_async(scope)
31+
return await obj.scope_contains_object(scope)
3232

3333
def permission_from_request(self, request: DrfRequest) -> Permission | None:
3434
if self.action in ("list", "retrieve"):

chord_metadata_service/discovery/scopeable_model.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,24 @@ class Meta:
2323
@abstractmethod
2424
def get_scope_filters() -> ModelScopeFilters: # pragma: no cover
2525
"""
26-
TODO
26+
Abstract static method (essentially a property) which returns a dictionary matching the ModelScopeFilters
27+
format, which defines which lookups are used to filter a queryset of objects of this model to just those which
28+
fall under a given scope.
2729
"""
2830
pass
2931

30-
def scope_contains_object(self, scope: ValidatedDiscoveryScope) -> bool:
32+
async def scope_contains_object(self, scope: ValidatedDiscoveryScope) -> bool:
3133
"""
32-
TODO
34+
Returns whether the scoped queryset for the model and the passed scope contains this particular object.
35+
Useful for checking permissions.
3336
"""
34-
return self.get_model_scoped_queryset(scope).filter(pk=self.pk).exists()
35-
36-
async def scope_contains_object_async(self, scope: ValidatedDiscoveryScope) -> bool:
3737
return await self.get_model_scoped_queryset(scope).filter(pk=self.pk).aexists()
3838

3939
@classmethod
4040
def get_model_scoped_queryset(cls, scope: ValidatedDiscoveryScope) -> QuerySet:
4141
"""
42-
TODO
42+
Returns a queryset (and subset) of objects of this model which belong to the passed scope. This method uses the
43+
defined get_scope_filters() function to narrow the queryset.
4344
"""
4445

4546
filter_scope: PublicScopeFilterKeys

0 commit comments

Comments
 (0)