Skip to content

Commit

Permalink
attachment public serializers: remove unnecessary and sensitive data …
Browse files Browse the repository at this point in the history
…from output
  • Loading branch information
NC-jsAhonen committed Jan 27, 2025
1 parent 6eb8c62 commit 9863eb9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions forms/serializers/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,5 +923,14 @@ def save(self, **kwargs):
return super().save(**kwargs)


class AttachmentPublicSerializer(AttachmentSerializer):
def to_representation(self, instance):
representation = super().to_representation(instance)
for key in ["attachment"]:
if key in representation:
representation.pop(key)
return representation


class ReadAttachmentSerializer(AttachmentSerializer):
field = serializers.CharField(source="field.identifier")
3 changes: 2 additions & 1 deletion forms/viewsets/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
AnswerOpeningRecordSerializer,
AnswerPublicSerializer,
AnswerSerializer,
AttachmentPublicSerializer,
AttachmentSerializer,
FormSerializer,
MeetingMemoSerializer,
Expand Down Expand Up @@ -178,7 +179,7 @@ def download(self, request, pk=None):
class AttachmentPublicViewSet(FileExtensionFileMixin, AttachmentViewSet):
"""Includes FileExtensionFileMixin to validate file extensions."""

pass
serializer_class = AttachmentPublicSerializer


class TargetStatusViewset(
Expand Down
9 changes: 9 additions & 0 deletions plotsearch/serializers/plot_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,15 @@ def create(self, validated_data):
return attachment


class AreaSearchAttachmentPublicSerializer(AreaSearchAttachmentSerializer):
def to_representation(self, instance):
representation = super().to_representation(instance)
for key in ["attachment", "user", "area_search", "created_at"]:
if key in representation:
representation.pop(key)
return representation


class AreaSearchStatusNoteSerializer(serializers.ModelSerializer):
preparer = UserSerializer(read_only=True)
time_stamp = serializers.DateTimeField(read_only=True)
Expand Down
2 changes: 2 additions & 0 deletions plotsearch/views/plot_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
PlotSearchOpeningRecordPermissions,
)
from plotsearch.serializers.plot_search import (
AreaSearchAttachmentPublicSerializer,
AreaSearchAttachmentSerializer,
AreaSearchDetailSerializer,
AreaSearchListSerializer,
Expand Down Expand Up @@ -411,6 +412,7 @@ class AreaSearchAttachmentPublicViewset(
):
"""Includes FileExtensionFileMixin to validate file extensions."""

serializer_class = AreaSearchAttachmentPublicSerializer
permission_classes = (AreaSearchAttachmentPublicPermissions,)

def destroy(self, request, *args, **kwargs):
Expand Down

0 comments on commit 9863eb9

Please sign in to comment.