Skip to content

Commit

Permalink
⚡ [#4695] Do not fetch all IOtypen for objects API validation
Browse files Browse the repository at this point in the history
Backport-Of: #4700
  • Loading branch information
stevenbal committed Sep 24, 2024
1 parent c3ba281 commit f5189d7
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 47 deletions.
53 changes: 34 additions & 19 deletions src/openforms/registrations/contrib/objects_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.utils.translation import gettext_lazy as _

from drf_spectacular.utils import OpenApiExample, extend_schema_serializer
from furl import furl
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

Expand Down Expand Up @@ -288,26 +289,40 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:

objects_api_group: ObjectsAPIGroupConfig = attrs["objects_api_group"]
with get_catalogi_client(objects_api_group) as catalogi_client:
informatieobjecttypen = catalogi_client.get_all_informatieobjecttypen()

for field in (
"informatieobjecttype_submission_report",
"informatieobjecttype_submission_csv",
"informatieobjecttype_attachment",
):
url = attrs.get(field)
if url is not None and not any(
informatieobjecttype["url"] == url
for informatieobjecttype in informatieobjecttypen
for field in (
"informatieobjecttype_submission_report",
"informatieobjecttype_submission_csv",
"informatieobjecttype_attachment",
):
raise serializers.ValidationError(
{
field: _(
"The provided {field} does not exist in the Catalogi API."
).format(field=field)
},
code="not-found",
)
url = attrs.get(field)
if not url:
continue

err_tpl = _("The provided {field} does not exist in the Catalogi API.")
err_msg = err_tpl.format(field=field)

assert objects_api_group.catalogi_service
iotypen_endpoint = (
furl(objects_api_group.catalogi_service.api_root)
/ "informatieobjecttypen/"
).url

if not url.startswith(iotypen_endpoint):
raise serializers.ValidationError(
{field: err_msg}, code="not-found"
)

response = catalogi_client.get(url)

if response.status_code != 200:
raise serializers.ValidationError(
{
field: _(
"The provided {field} does not exist in the Catalogi API."
).format(field=field)
},
code="not-found",
)

with get_objecttypes_client(objects_api_group) as objecttypes_client:
objecttypes = objecttypes_client.list_objecttypes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,24 @@ interactions:
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyMDE2MTMxOSwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.EIhr3lC5cFN7RGh1p8kDbr3oGIciuQj_0mvVT6QtiAM
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyNzE4MTY4MiwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.jZQcTti_0vMXYji_RrDsl6k-oxvx5zwcnru1Qd1cTkk
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.2
method: GET
uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen
uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen/5e48c3a3-9b12-4692-98ee-5c4576b13465
response:
body:
string: '{"count":3,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"Attachment
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc"],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"CSV
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null}]}'
string: '{"type":"http://localhost:8003/ref/fouten/NotFound/","code":"not_found","title":"Niet
gevonden.","status":404,"detail":"Niet gevonden.","instance":"urn:uuid:4aac74dd-63d1-436c-ad87-d44a664def30"}'
headers:
API-version:
- 1.3.1
Allow:
- GET, POST, HEAD, OPTIONS
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Length:
- '2517'
- '195'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
Expand All @@ -43,6 +38,6 @@ interactions:
X-Frame-Options:
- DENY
status:
code: 200
message: OK
code: 404
message: Not Found
version: 1
Loading

0 comments on commit f5189d7

Please sign in to comment.