From 94db39e055cac43399da6c7b2ae059ab99e1d4f3 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:37:09 -0800 Subject: [PATCH] A few minor tweaks to the backend --- src/documents/filters.py | 3 ++- src/documents/tests/test_api.py | 21 ++------------------- src/documents/views.py | 10 +++++----- src/paperless/filters.py | 6 +----- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/documents/filters.py b/src/documents/filters.py index 4bcbda98d..ffedb22da 100644 --- a/src/documents/filters.py +++ b/src/documents/filters.py @@ -11,6 +11,7 @@ from .models import Log from .models import StoragePath from .models import Tag + CHAR_KWARGS = ["istartswith", "iendswith", "icontains", "iexact"] ID_KWARGS = ["in", "exact"] INT_KWARGS = ["exact", "gt", "gte", "lt", "lte", "isnull"] @@ -137,7 +138,7 @@ class StoragePathFilterSet(FilterSet): } -class ObjectOwnedOrGrandtedPermissionsFilter(ObjectPermissionsFilter): +class ObjectOwnedOrGrantedPermissionsFilter(ObjectPermissionsFilter): """ A filter backend that limits results to those where the requesting user has read object level permissions, owns the objects, or objects without diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py index af368e6cb..6280ea3bb 100644 --- a/src/documents/tests/test_api.py +++ b/src/documents/tests/test_api.py @@ -3063,11 +3063,6 @@ class TestTasks(APITestCase): returned_task1 = response.data[1] returned_task2 = response.data[0] - from pprint import pprint - - pprint(returned_task1) - pprint(returned_task2) - self.assertEqual(returned_task1["task_id"], task1.task_id) self.assertEqual(returned_task1["status"], celery.states.PENDING) self.assertEqual(returned_task1["task_file_name"], task1.task_file_name) @@ -3323,10 +3318,6 @@ class TestApiUser(APITestCase): returned_user1 = User.objects.get(username="testuser") - from pprint import pprint - - pprint(returned_user1) - self.assertEqual(returned_user1.username, user1["username"]) self.assertEqual(returned_user1.first_name, user1["first_name"]) self.assertEqual(returned_user1.last_name, user1["last_name"]) @@ -3348,7 +3339,7 @@ class TestApiUser(APITestCase): last_name="User", ) - nUsers = len(User.objects.all()) + nUsers = User.objects.count() response = self.client.delete( f"{self.ENDPOINT}{user1.pk}/", @@ -3356,7 +3347,7 @@ class TestApiUser(APITestCase): self.assertEqual(response.status_code, 204) - self.assertEqual(len(User.objects.all()), nUsers - 1) + self.assertEqual(User.objects.count(), nUsers - 1) def test_update_user(self): """ @@ -3435,10 +3426,6 @@ class TestApiGroup(APITestCase): self.assertEqual(response.data["count"], 1) returned_group1 = response.data["results"][0] - from pprint import pprint - - pprint(returned_group1) - self.assertEqual(returned_group1["name"], group1.name) def test_create_group(self): @@ -3462,10 +3449,6 @@ class TestApiGroup(APITestCase): returned_group1 = Group.objects.get(name="Test Group") - from pprint import pprint - - pprint(returned_group1) - self.assertEqual(returned_group1.name, group1["name"]) def test_delete_group(self): diff --git a/src/documents/views.py b/src/documents/views.py index d982c0a21..89a30636e 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -31,7 +31,7 @@ from django.utils.translation import get_language from django.views.decorators.cache import cache_control from django.views.generic import TemplateView from django_filters.rest_framework import DjangoFilterBackend -from documents.filters import ObjectOwnedOrGrandtedPermissionsFilter +from documents.filters import ObjectOwnedOrGrantedPermissionsFilter from documents.permissions import PaperlessAdminPermissions from documents.permissions import PaperlessObjectPermissions from documents.tasks import consume_file @@ -166,7 +166,7 @@ class CorrespondentViewSet(ModelViewSet, PassUserMixin): filter_backends = ( DjangoFilterBackend, OrderingFilter, - ObjectOwnedOrGrandtedPermissionsFilter, + ObjectOwnedOrGrantedPermissionsFilter, ) filterset_class = CorrespondentFilterSet ordering_fields = ( @@ -198,7 +198,7 @@ class TagViewSet(ModelViewSet): filter_backends = ( DjangoFilterBackend, OrderingFilter, - ObjectOwnedOrGrandtedPermissionsFilter, + ObjectOwnedOrGrantedPermissionsFilter, ) filterset_class = TagFilterSet ordering_fields = ("color", "name", "matching_algorithm", "match", "document_count") @@ -217,7 +217,7 @@ class DocumentTypeViewSet(ModelViewSet, PassUserMixin): filter_backends = ( DjangoFilterBackend, OrderingFilter, - ObjectOwnedOrGrandtedPermissionsFilter, + ObjectOwnedOrGrantedPermissionsFilter, ) filterset_class = DocumentTypeFilterSet ordering_fields = ("name", "matching_algorithm", "match", "document_count") @@ -240,7 +240,7 @@ class DocumentViewSet( DjangoFilterBackend, SearchFilter, OrderingFilter, - ObjectOwnedOrGrandtedPermissionsFilter, + ObjectOwnedOrGrantedPermissionsFilter, ) filterset_class = DocumentFilterSet search_fields = ("title", "correspondent__name", "content") diff --git a/src/paperless/filters.py b/src/paperless/filters.py index e847f141e..5be7cc2f7 100644 --- a/src/paperless/filters.py +++ b/src/paperless/filters.py @@ -1,11 +1,7 @@ from django.contrib.auth.models import Group from django.contrib.auth.models import User from django_filters.rest_framework import FilterSet - -CHAR_KWARGS = ["istartswith", "iendswith", "icontains", "iexact"] -ID_KWARGS = ["in", "exact"] -INT_KWARGS = ["exact", "gt", "gte", "lt", "lte", "isnull"] -DATE_KWARGS = ["year", "month", "day", "date__gt", "gt", "date__lt", "lt"] +from documents.filters import CHAR_KWARGS class UserFilterSet(FilterSet):