Skip to content

Commit dec1a1a

Browse files
committed
🔥(api) remove possibility to force document id on creation
This feature poses security issues in the way it is implemented. We decide to remove it while clarifying the use case.
1 parent 1e432cf commit dec1a1a

File tree

2 files changed

+0
-38
lines changed

2 files changed

+0
-38
lines changed

src/backend/core/api/viewsets.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,6 @@ class DocumentViewSet(
321321
queryset = models.Document.objects.all()
322322
ordering = ["-updated_at"]
323323

324-
def perform_create(self, serializer):
325-
"""
326-
Override perform_create to use the provided ID in the payload if it exists
327-
"""
328-
document_id = self.request.data.get("id")
329-
document = serializer.save(id=document_id) if document_id else serializer.save()
330-
331-
self.access_model_class.objects.create(
332-
user=self.request.user,
333-
role=models.RoleChoices.OWNER,
334-
**{self.resource_field_name: document},
335-
)
336-
337324
def list(self, request, *args, **kwargs):
338325
"""Restrict resources returned by the list endpoint"""
339326
queryset = self.filter_queryset(self.get_queryset())

src/backend/core/tests/documents/test_api_documents_create.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Tests for Documents API endpoint in impress's core app: create
33
"""
44

5-
import uuid
6-
75
import pytest
86
from rest_framework.test import APIClient
97

@@ -48,26 +46,3 @@ def test_api_documents_create_authenticated():
4846
document = Document.objects.get()
4947
assert document.title == "my document"
5048
assert document.accesses.filter(role="owner", user=user).exists()
51-
52-
53-
def test_api_documents_create_with_id_from_payload():
54-
"""
55-
We should be able to create a document with an ID from the payload.
56-
"""
57-
user = factories.UserFactory()
58-
59-
client = APIClient()
60-
client.force_login(user)
61-
62-
doc_id = uuid.uuid4()
63-
response = client.post(
64-
"/api/v1.0/documents/",
65-
{"title": "my document", "id": str(doc_id)},
66-
format="json",
67-
)
68-
69-
assert response.status_code == 201
70-
document = Document.objects.get()
71-
assert document.title == "my document"
72-
assert document.id == doc_id
73-
assert document.accesses.filter(role="owner", user=user).exists()

0 commit comments

Comments
 (0)