diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f370f7c..2809e430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to ### Fixed - ✨(frontend) sync backend user language to browser on load +- 🐛(backend) fix WOPI PutFile to check stored file size ## [v0.13.0] - 2026-02-18 diff --git a/src/backend/wopi/tests/viewset/test_put_file_content.py b/src/backend/wopi/tests/viewset/test_put_file_content.py index 9228baab..0ebd4e9c 100644 --- a/src/backend/wopi/tests/viewset/test_put_file_content.py +++ b/src/backend/wopi/tests/viewset/test_put_file_content.py @@ -352,6 +352,7 @@ def test_put_file_content_with_no_lock_header_and_body_size_greater_than_0(): update_upload_state=models.ItemUploadStateChoices.READY, link_reach=models.LinkReachChoices.RESTRICTED, link_role=models.LinkRoleChoices.EDITOR, + size=100, ) user = factories.UserFactory() factories.UserItemAccessFactory( @@ -374,7 +375,8 @@ def test_put_file_content_with_no_lock_header_and_body_size_greater_than_0(): assert response.headers.get("X-WOPI-Lock") == "" -def test_put_file_content_with_no_lock_header_and_body_size_0(): +@pytest.mark.parametrize("data", [b"", b"new content"]) +def test_put_file_content_with_no_lock_header_and_body_size_0(data): """User can put file content when not providing a lock header and the body size is 0.""" folder = factories.ItemFactory( type=models.ItemTypeChoices.FOLDER, @@ -386,6 +388,7 @@ def test_put_file_content_with_no_lock_header_and_body_size_0(): update_upload_state=models.ItemUploadStateChoices.READY, link_reach=models.LinkReachChoices.RESTRICTED, link_role=models.LinkRoleChoices.EDITOR, + size=0, ) user = factories.UserFactory() factories.UserItemAccessFactory( @@ -397,7 +400,7 @@ def test_put_file_content_with_no_lock_header_and_body_size_0(): client = APIClient() response = client.post( f"/api/v1.0/wopi/files/{item.id}/contents/", - data=b"", + data=data, content_type="text/plain", HTTP_AUTHORIZATION=f"Bearer {access_token}", headers={ @@ -413,5 +416,5 @@ def test_put_file_content_with_no_lock_header_and_body_size_0(): Bucket=default_storage.bucket_name, Key=item.file_key, ) - assert file["Body"].read() == b"" + assert file["Body"].read() == data assert response.headers.get("X-WOPI-ItemVersion") == file["VersionId"] diff --git a/src/backend/wopi/viewsets.py b/src/backend/wopi/viewsets.py index 3263f31e..f94a6054 100644 --- a/src/backend/wopi/viewsets.py +++ b/src/backend/wopi/viewsets.py @@ -143,7 +143,6 @@ class WopiViewSet(viewsets.ViewSet): Implementation of the Wopi PutFile file operation https://learn.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/rest/files/putfile """ - if request.META.get(HTTP_X_WOPI_OVERRIDE) != "PUT": return Response(status=404) @@ -154,7 +153,6 @@ class WopiViewSet(viewsets.ViewSet): return Response(status=401) lock_value = request.META.get(HTTP_X_WOPI_LOCK) - if lock_value: lock_service = LockService(item) current_lock_value = lock_service.get_lock(default="") @@ -162,7 +160,7 @@ class WopiViewSet(viewsets.ViewSet): return Response(status=409, headers={X_WOPI_LOCK: current_lock_value}) else: # Check if the body is 0 bytes - body_size = int(request.META.get("CONTENT_LENGTH") or 0) + body_size = item.size or 0 if body_size > 0: return Response(status=409, headers={X_WOPI_LOCK: ""})