mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-01-30 23:08:59 -06:00
Security: enforce permissions for post_document
This commit is contained in:
@@ -1216,6 +1216,17 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
def test_upload_insufficient_permissions(self):
|
||||
self.client.force_authenticate(user=User.objects.create_user("testuser2"))
|
||||
|
||||
with (Path(__file__).parent / "samples" / "simple.pdf").open("rb") as f:
|
||||
response = self.client.post(
|
||||
"/api/documents/post_document/",
|
||||
{"document": f},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
def test_upload_empty_metadata(self):
|
||||
self.consume_file_mock.return_value = celery.result.AsyncResult(
|
||||
id=str(uuid.uuid4()),
|
||||
|
||||
@@ -1703,6 +1703,8 @@ class PostDocumentView(GenericAPIView):
|
||||
parser_classes = (parsers.MultiPartParser,)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if not request.user.has_perm("documents.add_document"):
|
||||
return HttpResponseForbidden("Insufficient permissions")
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user