From b5e31e9dce92f6aca4d99200d0acc87d30e90d75 Mon Sep 17 00:00:00 2001 From: krmax44 Date: Fri, 6 Dec 2024 15:47:15 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=BA=20ensure=20foirequest=20reference?= =?UTF-8?q?=20can=20only=20be=20set=20when=20initially=20creating?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit workaround since restframework doesn't support read & create only, see https://github.com/encode/django-rest-framework/discussions/8606 --- froide/foirequest/api/serializers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/froide/foirequest/api/serializers.py b/froide/foirequest/api/serializers.py index 5d0327d02..82f9e25ce 100644 --- a/froide/foirequest/api/serializers.py +++ b/froide/foirequest/api/serializers.py @@ -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 @@ -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")