A few minor tweaks to the backend

This commit is contained in:
Trenton H 2023-01-30 14:37:09 -08:00
parent d15773f282
commit 94db39e055
4 changed files with 10 additions and 30 deletions

View File

@ -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

View File

@ -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):

View File

@ -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")

View File

@ -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):