mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-21 23:38:13 +00:00
Merge branch 'main' into dev
This commit is contained in:
11 files changed
+138
-9
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from django.test import override_settings
|
||||
from django.urls import resolve
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
class TestApiAuthViews(TestCase):
|
||||
def test_api_auth_login_uses_allauth_login_view(self):
|
||||
response = self.client.get(reverse("rest_framework:login"))
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertTemplateUsed(response, "account/login.html")
|
||||
|
||||
def test_api_auth_login_uses_same_view_as_account_login(self):
|
||||
api_match = resolve("/api/auth/login/")
|
||||
account_match = resolve("/accounts/login/")
|
||||
|
||||
self.assertIs(api_match.func.view_class, account_match.func.view_class)
|
||||
|
||||
@override_settings(DISABLE_REGULAR_LOGIN=True)
|
||||
def test_api_auth_login_respects_disable_regular_login(self):
|
||||
username = f"testuser-{uuid.uuid4().hex}"
|
||||
User.objects.create_user(
|
||||
username=username,
|
||||
password="testpassword",
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("rest_framework:login"),
|
||||
data={
|
||||
"login": username,
|
||||
"password": "testpassword",
|
||||
"next": "/api/documents/",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertTemplateUsed(response, "account/login.html")
|
||||
self.assertContains(response, "Regular login is disabled")
|
||||
self.assertNotIn("_auth_user_id", self.client.session)
|
||||
|
||||
def test_api_auth_logout_uses_named_route(self):
|
||||
self.assertEqual(reverse("rest_framework:login"), "/api/auth/login/")
|
||||
self.assertEqual(reverse("rest_framework:logout"), "/api/auth/logout/")
|
||||
+15
-1
@@ -98,7 +98,21 @@ urlpatterns = [
|
||||
re_path(
|
||||
"^auth/",
|
||||
include(
|
||||
("rest_framework.urls", "rest_framework"),
|
||||
(
|
||||
[
|
||||
path(
|
||||
"login/",
|
||||
allauth_account_views.login,
|
||||
name="login",
|
||||
),
|
||||
path(
|
||||
"logout/",
|
||||
allauth_account_views.logout,
|
||||
name="logout",
|
||||
),
|
||||
],
|
||||
"rest_framework",
|
||||
),
|
||||
namespace="rest_framework",
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Final
|
||||
|
||||
__version__: Final[tuple[int, int, int]] = (2, 20, 14)
|
||||
__version__: Final[tuple[int, int, int]] = (2, 20, 15)
|
||||
# Version string like X.Y.Z
|
||||
__full_version_str__: Final[str] = ".".join(map(str, __version__))
|
||||
# Version string like X.Y
|
||||
|
||||
@@ -192,6 +192,16 @@ class UserViewSet(ModelViewSet[User]):
|
||||
)
|
||||
return super().update(request, *args, **kwargs)
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
user_to_delete: User = self.get_object()
|
||||
|
||||
if not request.user.is_superuser and user_to_delete.is_superuser:
|
||||
return HttpResponseForbidden(
|
||||
"Superusers can only be deleted by other superusers",
|
||||
)
|
||||
|
||||
return super().destroy(request, *args, **kwargs)
|
||||
|
||||
@extend_schema(
|
||||
request=None,
|
||||
responses={
|
||||
|
||||
Reference in new issue
Block a user