mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
A few minor tweaks to the backend
This commit is contained in:
parent
d15773f282
commit
94db39e055
@ -11,6 +11,7 @@ from .models import Log
|
|||||||
from .models import StoragePath
|
from .models import StoragePath
|
||||||
from .models import Tag
|
from .models import Tag
|
||||||
|
|
||||||
|
|
||||||
CHAR_KWARGS = ["istartswith", "iendswith", "icontains", "iexact"]
|
CHAR_KWARGS = ["istartswith", "iendswith", "icontains", "iexact"]
|
||||||
ID_KWARGS = ["in", "exact"]
|
ID_KWARGS = ["in", "exact"]
|
||||||
INT_KWARGS = ["exact", "gt", "gte", "lt", "lte", "isnull"]
|
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
|
A filter backend that limits results to those where the requesting user
|
||||||
has read object level permissions, owns the objects, or objects without
|
has read object level permissions, owns the objects, or objects without
|
||||||
|
@ -3063,11 +3063,6 @@ class TestTasks(APITestCase):
|
|||||||
returned_task1 = response.data[1]
|
returned_task1 = response.data[1]
|
||||||
returned_task2 = response.data[0]
|
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["task_id"], task1.task_id)
|
||||||
self.assertEqual(returned_task1["status"], celery.states.PENDING)
|
self.assertEqual(returned_task1["status"], celery.states.PENDING)
|
||||||
self.assertEqual(returned_task1["task_file_name"], task1.task_file_name)
|
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")
|
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.username, user1["username"])
|
||||||
self.assertEqual(returned_user1.first_name, user1["first_name"])
|
self.assertEqual(returned_user1.first_name, user1["first_name"])
|
||||||
self.assertEqual(returned_user1.last_name, user1["last_name"])
|
self.assertEqual(returned_user1.last_name, user1["last_name"])
|
||||||
@ -3348,7 +3339,7 @@ class TestApiUser(APITestCase):
|
|||||||
last_name="User",
|
last_name="User",
|
||||||
)
|
)
|
||||||
|
|
||||||
nUsers = len(User.objects.all())
|
nUsers = User.objects.count()
|
||||||
|
|
||||||
response = self.client.delete(
|
response = self.client.delete(
|
||||||
f"{self.ENDPOINT}{user1.pk}/",
|
f"{self.ENDPOINT}{user1.pk}/",
|
||||||
@ -3356,7 +3347,7 @@ class TestApiUser(APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 204)
|
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):
|
def test_update_user(self):
|
||||||
"""
|
"""
|
||||||
@ -3435,10 +3426,6 @@ class TestApiGroup(APITestCase):
|
|||||||
self.assertEqual(response.data["count"], 1)
|
self.assertEqual(response.data["count"], 1)
|
||||||
returned_group1 = response.data["results"][0]
|
returned_group1 = response.data["results"][0]
|
||||||
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
pprint(returned_group1)
|
|
||||||
|
|
||||||
self.assertEqual(returned_group1["name"], group1.name)
|
self.assertEqual(returned_group1["name"], group1.name)
|
||||||
|
|
||||||
def test_create_group(self):
|
def test_create_group(self):
|
||||||
@ -3462,10 +3449,6 @@ class TestApiGroup(APITestCase):
|
|||||||
|
|
||||||
returned_group1 = Group.objects.get(name="Test Group")
|
returned_group1 = Group.objects.get(name="Test Group")
|
||||||
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
pprint(returned_group1)
|
|
||||||
|
|
||||||
self.assertEqual(returned_group1.name, group1["name"])
|
self.assertEqual(returned_group1.name, group1["name"])
|
||||||
|
|
||||||
def test_delete_group(self):
|
def test_delete_group(self):
|
||||||
|
@ -31,7 +31,7 @@ from django.utils.translation import get_language
|
|||||||
from django.views.decorators.cache import cache_control
|
from django.views.decorators.cache import cache_control
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
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 PaperlessAdminPermissions
|
||||||
from documents.permissions import PaperlessObjectPermissions
|
from documents.permissions import PaperlessObjectPermissions
|
||||||
from documents.tasks import consume_file
|
from documents.tasks import consume_file
|
||||||
@ -166,7 +166,7 @@ class CorrespondentViewSet(ModelViewSet, PassUserMixin):
|
|||||||
filter_backends = (
|
filter_backends = (
|
||||||
DjangoFilterBackend,
|
DjangoFilterBackend,
|
||||||
OrderingFilter,
|
OrderingFilter,
|
||||||
ObjectOwnedOrGrandtedPermissionsFilter,
|
ObjectOwnedOrGrantedPermissionsFilter,
|
||||||
)
|
)
|
||||||
filterset_class = CorrespondentFilterSet
|
filterset_class = CorrespondentFilterSet
|
||||||
ordering_fields = (
|
ordering_fields = (
|
||||||
@ -198,7 +198,7 @@ class TagViewSet(ModelViewSet):
|
|||||||
filter_backends = (
|
filter_backends = (
|
||||||
DjangoFilterBackend,
|
DjangoFilterBackend,
|
||||||
OrderingFilter,
|
OrderingFilter,
|
||||||
ObjectOwnedOrGrandtedPermissionsFilter,
|
ObjectOwnedOrGrantedPermissionsFilter,
|
||||||
)
|
)
|
||||||
filterset_class = TagFilterSet
|
filterset_class = TagFilterSet
|
||||||
ordering_fields = ("color", "name", "matching_algorithm", "match", "document_count")
|
ordering_fields = ("color", "name", "matching_algorithm", "match", "document_count")
|
||||||
@ -217,7 +217,7 @@ class DocumentTypeViewSet(ModelViewSet, PassUserMixin):
|
|||||||
filter_backends = (
|
filter_backends = (
|
||||||
DjangoFilterBackend,
|
DjangoFilterBackend,
|
||||||
OrderingFilter,
|
OrderingFilter,
|
||||||
ObjectOwnedOrGrandtedPermissionsFilter,
|
ObjectOwnedOrGrantedPermissionsFilter,
|
||||||
)
|
)
|
||||||
filterset_class = DocumentTypeFilterSet
|
filterset_class = DocumentTypeFilterSet
|
||||||
ordering_fields = ("name", "matching_algorithm", "match", "document_count")
|
ordering_fields = ("name", "matching_algorithm", "match", "document_count")
|
||||||
@ -240,7 +240,7 @@ class DocumentViewSet(
|
|||||||
DjangoFilterBackend,
|
DjangoFilterBackend,
|
||||||
SearchFilter,
|
SearchFilter,
|
||||||
OrderingFilter,
|
OrderingFilter,
|
||||||
ObjectOwnedOrGrandtedPermissionsFilter,
|
ObjectOwnedOrGrantedPermissionsFilter,
|
||||||
)
|
)
|
||||||
filterset_class = DocumentFilterSet
|
filterset_class = DocumentFilterSet
|
||||||
search_fields = ("title", "correspondent__name", "content")
|
search_fields = ("title", "correspondent__name", "content")
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django_filters.rest_framework import FilterSet
|
from django_filters.rest_framework import FilterSet
|
||||||
|
from documents.filters import CHAR_KWARGS
|
||||||
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"]
|
|
||||||
|
|
||||||
|
|
||||||
class UserFilterSet(FilterSet):
|
class UserFilterSet(FilterSet):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user