Skip to content

Commit

Permalink
🦺 ensure foirequest reference can only be set when initially creating
Browse files Browse the repository at this point in the history
workaround since restframework doesn't support read & create only, see encode/django-rest-framework#8606
  • Loading branch information
krmax44 committed Dec 6, 2024
1 parent 74f9d20 commit b5e31e9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions froide/foirequest/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.utils.translation import gettext as _

from rest_framework import permissions, serializers
from rest_framework.generics import ValidationError
from rest_framework.views import PermissionDenied

from froide.document.api_views import DocumentSerializer
Expand Down Expand Up @@ -174,6 +175,11 @@ def get_queryset(self):
else:
return get_write_foirequest_queryset(request)

def run_validation(self, data):
if self.context["view"].action == "update":
raise ValidationError("Cannot update request reference.")
return super().run_validation(data)


class FoiMessageSerializer(serializers.HyperlinkedModelSerializer):
resource_uri = serializers.HyperlinkedIdentityField(view_name="api:message-detail")
Expand Down

0 comments on commit b5e31e9

Please sign in to comment.