diff --git a/backend/src/openarchiefbeheer/zaken/api/filtersets.py b/backend/src/openarchiefbeheer/zaken/api/filtersets.py index b643d8e8..4475f786 100644 --- a/backend/src/openarchiefbeheer/zaken/api/filtersets.py +++ b/backend/src/openarchiefbeheer/zaken/api/filtersets.py @@ -11,6 +11,18 @@ from ..models import Zaak +class ExpandFilter(CharFilter): + """ + Custom filter looking for `field_name` and `lookup_expr` within _expand. + """ + + def filter(self, qs, value): + if value: + lookup = f"_expand__{self.field_name}__{self.lookup_expr}" + qs = qs.filter(**{lookup: value}) + return qs + + class ZaakFilter(FilterSet): not_in_destruction_list = BooleanFilter( field_name="not_in_destruction_list", @@ -49,6 +61,10 @@ class ZaakFilter(FilterSet): ), ) + zaaktype__omschrijving__icontains = ExpandFilter( + field_name="zaaktype__omschrijving", lookup_expr="icontains" + ) + class Meta: model = Zaak fields = { diff --git a/backend/src/openarchiefbeheer/zaken/tests/factories.py b/backend/src/openarchiefbeheer/zaken/tests/factories.py index 41a17602..85f22f8e 100644 --- a/backend/src/openarchiefbeheer/zaken/tests/factories.py +++ b/backend/src/openarchiefbeheer/zaken/tests/factories.py @@ -27,6 +27,7 @@ class Params: "zaaktype": { "url": "http://catalogue-api.nl/zaaktypen/111-111-111", "selectielijst_procestype": {"nummer": 1}, + "omschrijving": "Aangifte behandelen", }, "resultaat": { "resultaattype": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/111-111-111", diff --git a/backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py b/backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py index 34086979..8a3b8ceb 100644 --- a/backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py +++ b/backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py @@ -238,17 +238,18 @@ def test_filter_heeft_relaties(self): def test_partial_filter(self): ZaakFactory.create(identificatie="ZAAK-ABCDEF-01") - ZaakFactory.create(identificatie="ZAAK-ABC-02") + ZaakFactory.create(identificatie="ZAAK-ABC-02", with_expand=True) ZaakFactory.create(identificatie="ZAAK-BCDEF-02") user = UserFactory(username="record_manager", role__can_start_destruction=True) endpoint = furl(reverse("api:zaken-list")) endpoint.args["identificatie__icontains"] = "ABC" + endpoint.args["zaaktype__omschrijving__icontains"] = "Aangifte behandelen" self.client.force_authenticate(user) response = self.client.get(endpoint.url) data = response.json() self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(data["count"], 2) + self.assertEqual(data["count"], 1)