mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-12 00:19:48 +00:00
Fix: respect global permissions for UI settings (#5919)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
@@ -65,3 +66,47 @@ class TestApiUiSettings(DirectoriesMixin, APITestCase):
|
||||
ui_settings.settings,
|
||||
settings["settings"],
|
||||
)
|
||||
|
||||
def test_api_set_ui_settings_insufficient_global_permissions(self):
|
||||
not_superuser = User.objects.create_user(username="test_not_superuser")
|
||||
self.client.force_authenticate(user=not_superuser)
|
||||
|
||||
settings = {
|
||||
"settings": {
|
||||
"dark_mode": {
|
||||
"enabled": True,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
response = self.client.post(
|
||||
self.ENDPOINT,
|
||||
json.dumps(settings),
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
def test_api_set_ui_settings_sufficient_global_permissions(self):
|
||||
not_superuser = User.objects.create_user(username="test_not_superuser")
|
||||
not_superuser.user_permissions.add(
|
||||
*Permission.objects.filter(codename__contains="uisettings"),
|
||||
)
|
||||
not_superuser.save()
|
||||
self.client.force_authenticate(user=not_superuser)
|
||||
|
||||
settings = {
|
||||
"settings": {
|
||||
"dark_mode": {
|
||||
"enabled": True,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
response = self.client.post(
|
||||
self.ENDPOINT,
|
||||
json.dumps(settings),
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
Reference in New Issue
Block a user