Skip to content

Commit

Permalink
Merge pull request #8206 from rtibbles/permissions_code_quality
Browse files Browse the repository at this point in the history
Small code quality cleanup
  • Loading branch information
rtibbles committed Jul 27, 2021
2 parents e3807a0 + dc3ab7d commit c3c7ac6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kolibri/core/auth/permissions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def user_can_delete_object(self, user, obj):
"Override `user_can_delete_object` in your permission class before you use it."
)

def readable_by_user_filter(self, user, queryset):
"""Applies a filter to the provided queryset, only returning items for which the user has read permission."""
def readable_by_user_filter(self, user):
"""Returns a Q object that defines a filter for objects readable by this user."""
raise NotImplementedError(
"Override `readable_by_user_filter` in your permission class before you use it."
)
Expand Down Expand Up @@ -297,10 +297,12 @@ def user_can_delete_object(self, user, obj):

def readable_by_user_filter(self, user):
# call each of the children permissions instances in turn, conjoining each filter
filter = Q()
intersection_filter = Q()
for perm in self.perms:
filter = filter & perm.readable_by_user_filter(user)
return filter
intersection_filter = intersection_filter & perm.readable_by_user_filter(
user
)
return intersection_filter


# helper functions
Expand Down

0 comments on commit c3c7ac6

Please sign in to comment.