mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
Chore: cleanup urls, use actions for some views (#8346)
This commit is contained in:
parent
2b29233a1e
commit
37f8a77516
@ -1546,6 +1546,12 @@ class StoragePathViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
|||||||
filterset_class = StoragePathFilterSet
|
filterset_class = StoragePathFilterSet
|
||||||
ordering_fields = ("name", "path", "matching_algorithm", "match", "document_count")
|
ordering_fields = ("name", "path", "matching_algorithm", "match", "document_count")
|
||||||
|
|
||||||
|
def get_permissions(self):
|
||||||
|
if self.action == "test":
|
||||||
|
# Test action does not require object level permissions
|
||||||
|
self.permission_classes = (IsAuthenticated,)
|
||||||
|
return super().get_permissions()
|
||||||
|
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
When a storage path is deleted, see if documents
|
When a storage path is deleted, see if documents
|
||||||
@ -1562,17 +1568,12 @@ class StoragePathViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@action(methods=["post"], detail=False)
|
||||||
class StoragePathTestView(GenericAPIView):
|
def test(self, request):
|
||||||
"""
|
"""
|
||||||
Test storage path against a document
|
Test storage path against a document
|
||||||
"""
|
"""
|
||||||
|
serializer = StoragePathTestSerializer(data=request.data)
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
serializer_class = StoragePathTestSerializer
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
serializer = self.get_serializer(data=request.data)
|
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
||||||
document = serializer.validated_data.get("document")
|
document = serializer.validated_data.get("document")
|
||||||
|
@ -11,7 +11,6 @@ from django.contrib.auth.decorators import login_required
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from django.urls import re_path
|
from django.urls import re_path
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
|
||||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||||
from django.views.generic import RedirectView
|
from django.views.generic import RedirectView
|
||||||
from django.views.static import serve
|
from django.views.static import serve
|
||||||
@ -35,7 +34,6 @@ from documents.views import SelectionDataView
|
|||||||
from documents.views import SharedLinkView
|
from documents.views import SharedLinkView
|
||||||
from documents.views import ShareLinkViewSet
|
from documents.views import ShareLinkViewSet
|
||||||
from documents.views import StatisticsView
|
from documents.views import StatisticsView
|
||||||
from documents.views import StoragePathTestView
|
|
||||||
from documents.views import StoragePathViewSet
|
from documents.views import StoragePathViewSet
|
||||||
from documents.views import SystemStatusView
|
from documents.views import SystemStatusView
|
||||||
from documents.views import TagViewSet
|
from documents.views import TagViewSet
|
||||||
@ -56,7 +54,6 @@ from paperless.views import ProfileView
|
|||||||
from paperless.views import SocialAccountProvidersView
|
from paperless.views import SocialAccountProvidersView
|
||||||
from paperless.views import TOTPView
|
from paperless.views import TOTPView
|
||||||
from paperless.views import UserViewSet
|
from paperless.views import UserViewSet
|
||||||
from paperless_mail.views import MailAccountTestView
|
|
||||||
from paperless_mail.views import MailAccountViewSet
|
from paperless_mail.views import MailAccountViewSet
|
||||||
from paperless_mail.views import MailRuleViewSet
|
from paperless_mail.views import MailRuleViewSet
|
||||||
from paperless_mail.views import OauthCallbackView
|
from paperless_mail.views import OauthCallbackView
|
||||||
@ -94,58 +91,83 @@ urlpatterns = [
|
|||||||
namespace="rest_framework",
|
namespace="rest_framework",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
re_path(
|
|
||||||
"^search/autocomplete/",
|
|
||||||
SearchAutoCompleteView.as_view(),
|
|
||||||
name="autocomplete",
|
|
||||||
),
|
|
||||||
re_path(
|
re_path(
|
||||||
"^search/",
|
"^search/",
|
||||||
GlobalSearchView.as_view(),
|
include(
|
||||||
name="global_search",
|
[
|
||||||
),
|
re_path(
|
||||||
re_path("^statistics/", StatisticsView.as_view(), name="statistics"),
|
"^$",
|
||||||
re_path(
|
GlobalSearchView.as_view(),
|
||||||
"^documents/post_document/",
|
name="global_search",
|
||||||
PostDocumentView.as_view(),
|
),
|
||||||
name="post_document",
|
re_path(
|
||||||
|
"^autocomplete/",
|
||||||
|
SearchAutoCompleteView.as_view(),
|
||||||
|
name="autocomplete",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
re_path(
|
re_path(
|
||||||
"^documents/bulk_edit/",
|
"^statistics/",
|
||||||
BulkEditView.as_view(),
|
StatisticsView.as_view(),
|
||||||
name="bulk_edit",
|
name="statistics",
|
||||||
),
|
),
|
||||||
re_path(
|
re_path(
|
||||||
"^documents/selection_data/",
|
"^documents/",
|
||||||
SelectionDataView.as_view(),
|
include(
|
||||||
name="selection_data",
|
[
|
||||||
|
re_path(
|
||||||
|
"^post_document/",
|
||||||
|
PostDocumentView.as_view(),
|
||||||
|
name="post_document",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
"^bulk_edit/",
|
||||||
|
BulkEditView.as_view(),
|
||||||
|
name="bulk_edit",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
"^bulk_download/",
|
||||||
|
BulkDownloadView.as_view(),
|
||||||
|
name="bulk_download",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
"^selection_data/",
|
||||||
|
SelectionDataView.as_view(),
|
||||||
|
name="selection_data",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
re_path(
|
|
||||||
"^documents/bulk_download/",
|
|
||||||
BulkDownloadView.as_view(),
|
|
||||||
name="bulk_download",
|
|
||||||
),
|
|
||||||
re_path(
|
|
||||||
"^remote_version/",
|
|
||||||
RemoteVersionView.as_view(),
|
|
||||||
name="remoteversion",
|
|
||||||
),
|
|
||||||
re_path("^ui_settings/", UiSettingsView.as_view(), name="ui_settings"),
|
|
||||||
re_path(
|
|
||||||
"^mail_accounts/test/",
|
|
||||||
MailAccountTestView.as_view(),
|
|
||||||
name="mail_accounts_test",
|
|
||||||
),
|
|
||||||
path("token/", views.obtain_auth_token),
|
|
||||||
re_path(
|
re_path(
|
||||||
"^bulk_edit_objects/",
|
"^bulk_edit_objects/",
|
||||||
BulkEditObjectsView.as_view(),
|
BulkEditObjectsView.as_view(),
|
||||||
name="bulk_edit_objects",
|
name="bulk_edit_objects",
|
||||||
),
|
),
|
||||||
|
re_path(
|
||||||
|
"^remote_version/",
|
||||||
|
RemoteVersionView.as_view(),
|
||||||
|
name="remoteversion",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
"^ui_settings/",
|
||||||
|
UiSettingsView.as_view(),
|
||||||
|
name="ui_settings",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"token/",
|
||||||
|
views.obtain_auth_token,
|
||||||
|
),
|
||||||
re_path(
|
re_path(
|
||||||
"^profile/",
|
"^profile/",
|
||||||
include(
|
include(
|
||||||
[
|
[
|
||||||
|
re_path(
|
||||||
|
"^$",
|
||||||
|
ProfileView.as_view(),
|
||||||
|
name="profile_view",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"generate_auth_token/",
|
"generate_auth_token/",
|
||||||
GenerateAuthTokenView.as_view(),
|
GenerateAuthTokenView.as_view(),
|
||||||
@ -158,11 +180,6 @@ urlpatterns = [
|
|||||||
"social_account_providers/",
|
"social_account_providers/",
|
||||||
SocialAccountProvidersView.as_view(),
|
SocialAccountProvidersView.as_view(),
|
||||||
),
|
),
|
||||||
re_path(
|
|
||||||
"^$",
|
|
||||||
ProfileView.as_view(),
|
|
||||||
name="profile_view",
|
|
||||||
),
|
|
||||||
path(
|
path(
|
||||||
"totp/",
|
"totp/",
|
||||||
TOTPView.as_view(),
|
TOTPView.as_view(),
|
||||||
@ -181,11 +198,6 @@ urlpatterns = [
|
|||||||
TrashView.as_view(),
|
TrashView.as_view(),
|
||||||
name="trash",
|
name="trash",
|
||||||
),
|
),
|
||||||
re_path(
|
|
||||||
"^storage_paths/test/",
|
|
||||||
StoragePathTestView.as_view(),
|
|
||||||
name="storage_paths_test",
|
|
||||||
),
|
|
||||||
re_path(
|
re_path(
|
||||||
r"^oauth/callback/",
|
r"^oauth/callback/",
|
||||||
OauthCallbackView.as_view(),
|
OauthCallbackView.as_view(),
|
||||||
@ -223,14 +235,6 @@ urlpatterns = [
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
re_path(
|
|
||||||
r"^push$",
|
|
||||||
csrf_exempt(
|
|
||||||
RedirectView.as_view(
|
|
||||||
url=settings.BASE_URL + "api/documents/post_document/",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
# Frontend assets TODO: this is pretty bad, but it works.
|
# Frontend assets TODO: this is pretty bad, but it works.
|
||||||
path(
|
path(
|
||||||
"assets/<path:path>",
|
"assets/<path:path>",
|
||||||
|
@ -6,6 +6,7 @@ from django.http import HttpResponseBadRequest
|
|||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from httpx_oauth.oauth2 import GetAccessTokenError
|
from httpx_oauth.oauth2 import GetAccessTokenError
|
||||||
|
from rest_framework.decorators import action
|
||||||
from rest_framework.generics import GenericAPIView
|
from rest_framework.generics import GenericAPIView
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
@ -34,22 +35,14 @@ class MailAccountViewSet(ModelViewSet, PassUserMixin):
|
|||||||
permission_classes = (IsAuthenticated, PaperlessObjectPermissions)
|
permission_classes = (IsAuthenticated, PaperlessObjectPermissions)
|
||||||
filter_backends = (ObjectOwnedOrGrantedPermissionsFilter,)
|
filter_backends = (ObjectOwnedOrGrantedPermissionsFilter,)
|
||||||
|
|
||||||
|
def get_permissions(self):
|
||||||
|
if self.action == "test":
|
||||||
|
# Test action does not require object level permissions
|
||||||
|
self.permission_classes = (IsAuthenticated,)
|
||||||
|
return super().get_permissions()
|
||||||
|
|
||||||
class MailRuleViewSet(ModelViewSet, PassUserMixin):
|
@action(methods=["post"], detail=False)
|
||||||
model = MailRule
|
def test(self, request):
|
||||||
|
|
||||||
queryset = MailRule.objects.all().order_by("order")
|
|
||||||
serializer_class = MailRuleSerializer
|
|
||||||
pagination_class = StandardPagination
|
|
||||||
permission_classes = (IsAuthenticated, PaperlessObjectPermissions)
|
|
||||||
filter_backends = (ObjectOwnedOrGrantedPermissionsFilter,)
|
|
||||||
|
|
||||||
|
|
||||||
class MailAccountTestView(GenericAPIView):
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
serializer_class = MailAccountSerializer
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
logger = logging.getLogger("paperless_mail")
|
logger = logging.getLogger("paperless_mail")
|
||||||
request.data["name"] = datetime.datetime.now().isoformat()
|
request.data["name"] = datetime.datetime.now().isoformat()
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
@ -95,6 +88,16 @@ class MailAccountTestView(GenericAPIView):
|
|||||||
return HttpResponseBadRequest("Unable to connect to server")
|
return HttpResponseBadRequest("Unable to connect to server")
|
||||||
|
|
||||||
|
|
||||||
|
class MailRuleViewSet(ModelViewSet, PassUserMixin):
|
||||||
|
model = MailRule
|
||||||
|
|
||||||
|
queryset = MailRule.objects.all().order_by("order")
|
||||||
|
serializer_class = MailRuleSerializer
|
||||||
|
pagination_class = StandardPagination
|
||||||
|
permission_classes = (IsAuthenticated, PaperlessObjectPermissions)
|
||||||
|
filter_backends = (ObjectOwnedOrGrantedPermissionsFilter,)
|
||||||
|
|
||||||
|
|
||||||
class OauthCallbackView(GenericAPIView):
|
class OauthCallbackView(GenericAPIView):
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user