Commit 3e54607b authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

Use djangorestframework-guardian package

Certain filters are being moved out of the djangorestframework
package and into djangorestframework-guardian.
parent 5590fcb2
import logging
from rest_framework import filters
from rest_framework_guardian import filters
# Set up logger
logger = logging.getLogger(__name__)
......@@ -11,24 +11,5 @@ class DjangoObjectAndGlobalPermissionsFilter(
Same as DjangoObjectPermissionsFilter, except it allows global permissions.
accept_global_perms = True
def filter_queryset(self, request, queryset, view):
# Mostly from rest_framework.filters.DjangoObjectPermissionsFilter
# We want to defer this import until run-time, rather than import-time.
# See
# (Also see #1624 for why we need to make this import explicitly)
from guardian.shortcuts import get_objects_for_user
extra = {}
user = request.user
model_cls = queryset.model
kwargs = {
'app_label': model_cls._meta.app_label,
'model_name': model_cls._meta.model_name
permission = self.perm_format % kwargs
extra['accept_global_perms'] = self.accept_global_perms
return get_objects_for_user(user, permission, queryset, **extra)
shortcut_kwargs = filters.DjangoObjectPermissionsFilter.shortcut_kwargs
shortcut_kwargs['accept_global_perms'] = True
......@@ -9,6 +9,7 @@ django-silk==3.0.1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment