mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-22 00:49:35 -06:00
Prevent non-owners from changing db models
This commit is contained in:
@@ -1416,6 +1416,17 @@ class SavedViewSerializer(OwnedObjectSerializer):
|
|||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
|
user = getattr(self, "user", None)
|
||||||
|
is_superuser = user.is_superuser if user is not None else False
|
||||||
|
is_owner = instance.owner == user if user is not None else False
|
||||||
|
is_unowned = instance.owner is None
|
||||||
|
if not (is_superuser or is_owner or is_unowned) and (
|
||||||
|
"show_on_dashboard" in validated_data or "show_in_sidebar" in validated_data
|
||||||
|
):
|
||||||
|
raise PermissionDenied(
|
||||||
|
_("Insufficient permissions."),
|
||||||
|
)
|
||||||
|
|
||||||
if "filter_rules" in validated_data:
|
if "filter_rules" in validated_data:
|
||||||
rules_data = validated_data.pop("filter_rules")
|
rules_data = validated_data.pop("filter_rules")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2066,6 +2066,13 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
{"show_in_sidebar": True},
|
{"show_in_sidebar": True},
|
||||||
format="json",
|
format="json",
|
||||||
)
|
)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
|
response = self.client.patch(
|
||||||
|
f"/api/saved_views/{v2.id}/",
|
||||||
|
{"sort_field": "added"},
|
||||||
|
format="json",
|
||||||
|
)
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
response = self.client.patch(
|
response = self.client.patch(
|
||||||
|
|||||||
Reference in New Issue
Block a user