Skip to content

Commit

Permalink
Merge pull request #1526 from open-zaak/feature/1525-eio-zoek
Browse files Browse the repository at this point in the history
Feature/1525 eio zoek
  • Loading branch information
annashamray committed Jan 17, 2024
2 parents d4b0d15 + 7a3a9bc commit bb7427a
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 49 deletions.
21 changes: 10 additions & 11 deletions src/openzaak/components/documenten/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
from rest_framework.pagination import PageNumberPagination
from rest_framework.parsers import FormParser, MultiPartParser
from rest_framework.response import Response
from rest_framework.serializers import ValidationError
from rest_framework.serializers import ErrorDetail, ValidationError
from rest_framework.settings import api_settings
from vng_api_common.audittrails.viewsets import (
AuditTrailViewSet,
AuditTrailViewsetMixin,
)
from vng_api_common.filters import Backend
from vng_api_common.search import SearchMixin
from vng_api_common.viewsets import CheckQueryParamsMixin

Expand Down Expand Up @@ -203,6 +204,7 @@ class EnkelvoudigInformatieObjectViewSet(
lookup_field = "uuid"
serializer_class = EnkelvoudigInformatieObjectSerializer
search_input_serializer_class = EIOZoekSerializer
filter_backends = (Backend,)
permission_classes = (InformationObjectAuthRequired,)
required_scopes = {
"list": SCOPE_DOCUMENTEN_ALLES_LEZEN,
Expand Down Expand Up @@ -374,7 +376,6 @@ def unlock(self, request, *args, **kwargs):
unlock_serializer.save()
return Response(status=status.HTTP_204_NO_CONTENT)

@swagger_auto_schema(request_body=EIOZoekSerializer)
@action(methods=["post"], detail=False)
def _zoek(self, request, *args, **kwargs):
"""
Expand All @@ -383,23 +384,21 @@ def _zoek(self, request, *args, **kwargs):
Zoeken/filteren gaat normaal via de `list` operatie, deze is echter
niet geschikt voor zoekopdrachten met UUIDs.
"""

# this method is not marked as is_search_action, because the DRC standard
# doesn't include LIST query params as possible request data attributes here
# The related issue which highlights it https://github.com/VNG-Realisatie/gemma-zaken/issues/2294
#
# For now we support only 'uuid__in' input parameter here to adhere to the standard OAS
# Even if the DRC reference implementation doesn't do it
if not request.data:
err = ErrorDetail(
_("Search parameters must be specified"), code="empty_search_body"
)
raise ValidationError({api_settings.NON_FIELD_ERRORS_KEY: err})

search_input = self.get_search_input()
queryset = self.get_queryset()
queryset = self.filter_queryset(self.get_queryset())

for name, value in search_input.items():
queryset = queryset.filter(**{name: value})

return self.get_search_output(queryset)

_zoek.is_page_action = True
_zoek.is_search_action = True


@cmis_conditional_retrieve()
Expand Down
45 changes: 44 additions & 1 deletion src/openzaak/components/documenten/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ paths:
required: true
responses:
'200':
description: ''
description: OK
headers:
API-version:
schema:
Expand Down Expand Up @@ -367,6 +367,36 @@ paths:
type: array
items:
$ref: '#/components/schemas/EnkelvoudigInformatieObjectData'
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'403':
$ref: '#/components/responses/403'
'406':
$ref: '#/components/responses/406'
'409':
$ref: '#/components/responses/409'
'410':
$ref: '#/components/responses/410'
'413':
description: Request entity too large
headers:
API-version:
schema:
type: string
description: 'Geeft een specifieke API-versie aan in de context van
een specifieke aanroep. Voorbeeld: 1.2.1.'
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Fout'
'415':
$ref: '#/components/responses/415'
'429':
$ref: '#/components/responses/429'
'500':
$ref: '#/components/responses/500'
tags:
- enkelvoudiginformatieobjecten
security:
Expand Down Expand Up @@ -3219,6 +3249,19 @@ components:
items:
type: string
format: uuid
identificatie:
title: Identificatie
description: Een binnen een gegeven context ondubbelzinnige referentie naar
het INFORMATIEOBJECT.
type: string
minLength: 1
bronorganisatie:
title: Bronorganisatie
description: "Het RSIN van de Niet-natuurlijk persoon zijnde de organisatie\
\ die het informatieobject heeft gecre\xEBerd of heeft ontvangen en als\
\ eerste in een samenwerkingsketen heeft vastgelegd."
type: string
minLength: 1
EnkelvoudigInformatieObjectData:
required:
- bronorganisatie
Expand Down
55 changes: 54 additions & 1 deletion src/openzaak/components/documenten/swagger2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
],
"responses": {
"200": {
"description": "",
"description": "OK",
"schema": {
"required": [
"count",
Expand Down Expand Up @@ -440,6 +440,47 @@
"description": "Geeft een specifieke API-versie aan in de context van een specifieke aanroep. Voorbeeld: 1.2.1."
}
}
},
"400": {
"$ref": "#/responses/400"
},
"401": {
"$ref": "#/responses/401"
},
"403": {
"$ref": "#/responses/403"
},
"406": {
"$ref": "#/responses/406"
},
"409": {
"$ref": "#/responses/409"
},
"410": {
"$ref": "#/responses/410"
},
"413": {
"description": "Request entity too large",
"schema": {
"$ref": "#/definitions/Fout"
},
"headers": {
"API-version": {
"schema": {
"type": "string"
},
"description": "Geeft een specifieke API-versie aan in de context van een specifieke aanroep. Voorbeeld: 1.2.1."
}
}
},
"415": {
"$ref": "#/responses/415"
},
"429": {
"$ref": "#/responses/429"
},
"500": {
"$ref": "#/responses/500"
}
},
"produces": [
Expand Down Expand Up @@ -3790,6 +3831,18 @@
"type": "string",
"format": "uuid"
}
},
"identificatie": {
"title": "Identificatie",
"description": "Een binnen een gegeven context ondubbelzinnige referentie naar het INFORMATIEOBJECT.",
"type": "string",
"minLength": 1
},
"bronorganisatie": {
"title": "Bronorganisatie",
"description": "Het RSIN van de Niet-natuurlijk persoon zijnde de organisatie die het informatieobject heeft gecre\u00eberd of heeft ontvangen en als eerste in een samenwerkingsketen heeft vastgelegd.",
"type": "string",
"minLength": 1
}
}
},
Expand Down
27 changes: 19 additions & 8 deletions src/openzaak/components/documenten/tests/test_eio_zoek.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2023 Dimpact
from rest_framework import status
from rest_framework.test import APITestCase
from vng_api_common.tests import get_validation_errors, reverse
from vng_api_common.tests import get_validation_errors, reverse, reverse_lazy

from openzaak.tests.utils import JWTAuthMixin

Expand All @@ -11,13 +11,13 @@

class ZaakZoekTests(JWTAuthMixin, APITestCase):
heeft_alle_autorisaties = True
url = reverse_lazy("enkelvoudiginformatieobject--zoek")

def test_zoek_uuid_in(self):
eio1, eio2, eio3 = EnkelvoudigInformatieObjectFactory.create_batch(3)
url = reverse("enkelvoudiginformatieobject--zoek")
data = {"uuid__in": [eio1.uuid, eio2.uuid]}

response = self.client.post(url, data)
response = self.client.post(self.url, data)

self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand All @@ -29,11 +29,22 @@ def test_zoek_uuid_in(self):
self.assertEqual(data[1]["url"], f"http://testserver{reverse(eio2)}")

def test_zoek_without_params(self):
url = reverse("enkelvoudiginformatieobject--zoek")

response = self.client.post(url, {})
response = self.client.post(self.url, {})

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

error = get_validation_errors(response, "uuid__in")
self.assertEqual(error["code"], "required")
error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "empty_search_body")

def test_zoek_with_filter_param(self):
eio1, eio2, eio3 = EnkelvoudigInformatieObjectFactory.create_batch(3)
data = {"uuid__in": [eio1.uuid, eio2.uuid], "identificatie": eio1.identificatie}

response = self.client.post(self.url, data)

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()["results"]

self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{reverse(eio1)}")
28 changes: 0 additions & 28 deletions src/openzaak/utils/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,3 @@ def get_produces(self):
def is_deprecated(self):
deprecation_message = getattr(self.view, "deprecation_message", None)
return bool(deprecation_message) or super().is_deprecated()

def get_default_responses(self) -> OrderedDict:
"""
Workaround for EnkelvoudigInformatieObject/_zoek endpoint, which can't be marked as `is_search_action`
But still needs pagination
"""
if self._is_page_view:
return self._get_search_responses()

return super().get_default_responses()

def should_page(self):
"""
Workaround for EnkelvoudigInformatieObject/_zoek endpoint, which can't be marked as `is_search_action`
But still needs pagination
"""
if self._is_page_view:
return hasattr(self.view, "paginator")

return super().should_page()

@property
def _is_page_view(self) -> bool:
if not getattr(self.view, "action", None):
return False

action = getattr(self.view, self.view.action)
return getattr(action, "is_page_action", False)

0 comments on commit bb7427a

Please sign in to comment.