mirror of
https://github.com/suitenumerique/docs.git
synced 2026-09-20 08:38:01 +02:00
✨(backend) create a dedicated endpoint to update document content
We want a dedicated endpoint to update a document content. Previously, updating the content was made on the update action shared with all other document's properties. When the title is updated, the response contains the content, so a call to the s3 storage is made and we don't want this. Isolating the content update will allow us in the next commit to remove the content from the Document serializer.
This commit is contained in:
@@ -358,6 +358,34 @@ class DocumentSerializer(ListDocumentSerializer):
|
||||
return super().save(**kwargs)
|
||||
|
||||
|
||||
class DocumentContentSerializer(serializers.Serializer):
|
||||
"""Serializer for updating only the raw content of a document stored in S3."""
|
||||
|
||||
content = serializers.CharField(required=True)
|
||||
websocket = serializers.BooleanField(required=False)
|
||||
|
||||
def validate_content(self, value):
|
||||
"""Validate the content field."""
|
||||
try:
|
||||
b64decode(value, validate=True)
|
||||
except binascii.Error as err:
|
||||
raise serializers.ValidationError("Invalid base64 content.") from err
|
||||
|
||||
return value
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
"""
|
||||
This serializer does not support updates.
|
||||
"""
|
||||
raise NotImplementedError("Update is not supported for this serializer.")
|
||||
|
||||
def create(self, validated_data):
|
||||
"""
|
||||
This serializer does not support create.
|
||||
"""
|
||||
raise NotImplementedError("Create is not supported for this serializer.")
|
||||
|
||||
|
||||
class DocumentAccessSerializer(serializers.ModelSerializer):
|
||||
"""Serialize document accesses."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user