Skip to content

Commit 26a1ca3

Browse files
committed
✨ [#726] Add filter on zaaktype identificatie for external typen endpoints
1 parent 6d63d9b commit 26a1ca3

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

backend/src/openarchiefbeheer/zaken/api/mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ def get_query_params(self, request: Request) -> HashableDict:
1010
serializer = ZaaktypeFilterSerializer(data=request.query_params)
1111
serializer.is_valid(raise_exception=True)
1212
query_params = HashableDict()
13-
query_params.update(serializer.validated_data)
13+
query_params.update(serializer.data)
1414

1515
return query_params

backend/src/openarchiefbeheer/zaken/api/serializers.py

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.utils.translation import gettext_lazy as _
44

5+
from djangorestframework_camel_case.util import camelize
56
from drf_spectacular.utils import extend_schema_field
67
from furl import furl
78
from rest_framework import serializers
@@ -96,6 +97,13 @@ class ZaaktypeFilterSerializer(serializers.Serializer):
9697
required=False,
9798
help_text=_("The URL of the zaaktype on which to filter."),
9899
)
100+
zaaktype_identificatie = serializers.CharField(
101+
required=False,
102+
help_text=_("The identificatie of the zaaktype on which to filter."),
103+
)
104+
105+
def to_representation(self, instance):
106+
return camelize(instance)
99107

100108

101109
@lru_cache

backend/src/openarchiefbeheer/zaken/api/views.py

+32
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from rest_framework import status
88
from rest_framework.exceptions import ValidationError
99
from rest_framework.permissions import IsAdminUser, IsAuthenticated
10+
from rest_framework.request import Request
1011
from rest_framework.response import Response
1112
from rest_framework.views import APIView
1213

@@ -193,6 +194,37 @@ def get(self, request, *args, **kwargs):
193194
class InformatieobjecttypeChoicesView(FilterOnZaaktypeMixin, APIView):
194195
permission_classes = [IsAuthenticated]
195196

197+
# TODO
198+
# Remove once https://github.com/open-zaak/open-zaak/issues/1939 is fixed
199+
def get_query_params(self, request: Request) -> HashableDict:
200+
"""
201+
We need to filter the informatieobjecttypen on zaaktype URL, but we only have the identificatie.
202+
The identificatie can represent multiple versions of the zaaktype (multiple URLs).
203+
As a bandaid fix, we use the URL of the latest version (highest begin_geldigheid field).
204+
"""
205+
query_params = HashableDict()
206+
if not request.GET.get("zaaktype_identificatie"):
207+
return query_params
208+
209+
serializer = ZaaktypeFilterSerializer(data=request.query_params)
210+
serializer.is_valid(raise_exception=True)
211+
212+
zaaktypen_query_params = HashableDict()
213+
zaaktypen_query_params.update(
214+
{"identificatie": serializer.validated_data["zaaktype_identificatie"]}
215+
)
216+
zaaktypen = retrieve_zaaktypen(zaaktypen_query_params)
217+
if not zaaktypen:
218+
return query_params
219+
220+
# Sort in descending order, so that the zaaktype with the most recent begin date is first. (Latest zaaktype version)
221+
zaaktypen = sorted(
222+
zaaktypen, key=lambda zaaktype: zaaktype["begin_geldigheid"], reverse=True
223+
)
224+
query_params.update({"zaaktype": zaaktypen[0]["url"]})
225+
226+
return query_params
227+
196228
@extend_schema(
197229
summary=_("Retrieve informatieobjecttypen choices"),
198230
description=_(

0 commit comments

Comments
 (0)