Skip to content

Commit 6d0c76f

Browse files
Merge pull request #4443 from open-formulieren/feature/4414-remove-zgw-default-config
[#4414] Remove default ZGW API group
2 parents 8da2af6 + ec7e66d commit 6d0c76f

18 files changed

+382
-163
lines changed

bin/check_zgw_groups.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python
2+
from __future__ import annotations
3+
4+
import sys
5+
from pathlib import Path
6+
7+
import django
8+
9+
import click
10+
from tabulate import tabulate
11+
12+
SRC_DIR = Path(__file__).parent.parent / "src"
13+
sys.path.insert(0, str(SRC_DIR.resolve()))
14+
15+
16+
def check_zgw_groups() -> bool:
17+
from openforms.forms.models import FormRegistrationBackend
18+
from openforms.registrations.contrib.zgw_apis.models import ZgwConfig
19+
20+
zgw_config = ZgwConfig.get_solo()
21+
default_group = zgw_config.default_zgw_api_group
22+
23+
problems: list[list[str]] = []
24+
25+
for backend in FormRegistrationBackend.objects.filter(backend="zgw-create-zaak"):
26+
zgw_api_group = backend.options.get("zgw_api_group")
27+
if zgw_api_group is None and default_group is None:
28+
problems.append(
29+
[
30+
backend.form.admin_name,
31+
backend.name,
32+
backend.key,
33+
"No ZGW API group set and no default group available",
34+
]
35+
)
36+
continue
37+
38+
if not problems:
39+
click.echo(click.style("No problems found.", fg="green"))
40+
return True
41+
42+
click.echo(click.style("Found problems in form registration backends.", fg="red"))
43+
click.echo("")
44+
click.echo(
45+
tabulate(
46+
problems,
47+
headers=(
48+
"Form",
49+
"Registration backend name",
50+
"Regisration backend key",
51+
"Problem",
52+
),
53+
)
54+
)
55+
56+
return False
57+
58+
59+
def main(skip_setup: bool = False) -> bool:
60+
from openforms.setup import setup_env
61+
62+
if not skip_setup:
63+
setup_env()
64+
django.setup()
65+
66+
return check_zgw_groups()
67+
68+
69+
@click.command()
70+
def cli():
71+
return main()
72+
73+
74+
if __name__ == "__main__":
75+
cli()

src/openapi.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -3836,9 +3836,8 @@ paths:
38363836
schema:
38373837
type: integer
38383838
title: ZGW API set
3839-
description: The primary key of the ZGW API set to use. If provided, the informatieobjecttypen
3840-
from the Catalogi API in this set will be returned. Otherwise, the Catalogi
3841-
API in the default ZGW API set will be used to find informatieobjecttypen.
3839+
description: The primary key of the ZGW API set to use. The informatieobjecttypen
3840+
from the Catalogi API in this set will be returned.
38423841
tags:
38433842
- registration
38443843
security:

src/openforms/fixtures/admin_index_unlisted.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@
2727
"stuf_zds.StufZDSConfig",
2828
"suwinet.SuwinetConfig",
2929
"upgrades.VersionInfo",
30-
"zgw_apis.ZGWApiGroupConfig",
31-
"zgw_apis.ZgwConfig"
30+
"zgw_apis.ZGWApiGroupConfig"
3231
]

src/openforms/fixtures/default_groups.json

-40
Original file line numberDiff line numberDiff line change
@@ -229,26 +229,6 @@
229229
"timeline_logger",
230230
"timelinelog"
231231
],
232-
[
233-
"add_zgwconfig",
234-
"zgw_apis",
235-
"zgwconfig"
236-
],
237-
[
238-
"change_zgwconfig",
239-
"zgw_apis",
240-
"zgwconfig"
241-
],
242-
[
243-
"delete_zgwconfig",
244-
"zgw_apis",
245-
"zgwconfig"
246-
],
247-
[
248-
"view_zgwconfig",
249-
"zgw_apis",
250-
"zgwconfig"
251-
],
252232
[
253233
"add_service",
254234
"zgw_consumers",
@@ -1508,26 +1488,6 @@
15081488
"timeline_logger",
15091489
"timelinelog"
15101490
],
1511-
[
1512-
"add_zgwconfig",
1513-
"zgw_apis",
1514-
"zgwconfig"
1515-
],
1516-
[
1517-
"change_zgwconfig",
1518-
"zgw_apis",
1519-
"zgwconfig"
1520-
],
1521-
[
1522-
"delete_zgwconfig",
1523-
"zgw_apis",
1524-
"zgwconfig"
1525-
],
1526-
[
1527-
"view_zgwconfig",
1528-
"zgw_apis",
1529-
"zgwconfig"
1530-
],
15311491
[
15321492
"add_nlxconfig",
15331493
"zgw_consumers",

src/openforms/fixtures/demo_zgw_apis.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@
5454
}
5555
},
5656
{
57-
"model": "zgw_apis.zgwconfig",
57+
"model": "zgw_apis.zgwapigroupconfig",
5858
"pk": 1,
5959
"fields": {
60+
"name": "test ZGW API group",
6061
"zrc_service": 1,
6162
"drc_service": 2,
6263
"ztc_service": 3,
63-
"zaaktype": "https://test.openzaak.nl/catalogi/api/v1/zaaktypen/53340e34-7581-4b04-884f-8ff7e6a73c2c",
64-
"informatieobjecttype": "https://test.openzaak.nl/catalogi/api/v1/informatieobjecttypen/1db73aba-cef4-42ec-bdf0-cd4c7c4f2514",
6564
"organisatie_rsin": "000000000"
6665
}
6766
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate, br
9+
Authorization:
10+
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcxOTkyMTgwMSwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.fn0AHRxUSOammPxgql-z-nznW95J0poa2bPwjoY7qBk
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- python-requests/2.32.3
15+
method: GET
16+
uri: http://localhost:8003/catalogi/api/v1/catalogussen
17+
response:
18+
body:
19+
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","domein":"TEST","rsin":"000000000","contactpersoonBeheerNaam":"Test
20+
name","contactpersoonBeheerTelefoonnummer":"","contactpersoonBeheerEmailadres":"","zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc"],"besluittypen":[],"informatieobjecttypen":["http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7"],"naam":"Test
21+
catalog","versie":"","begindatumVersie":null}]}'
22+
headers:
23+
API-version:
24+
- 1.3.1
25+
Allow:
26+
- GET, POST, HEAD, OPTIONS
27+
Content-Length:
28+
- '799'
29+
Content-Type:
30+
- application/json
31+
Referrer-Policy:
32+
- same-origin
33+
Vary:
34+
- Accept, Origin
35+
X-Content-Type-Options:
36+
- nosniff
37+
X-Frame-Options:
38+
- DENY
39+
X-XSS-Protection:
40+
- 1; mode=block
41+
status:
42+
code: 200
43+
message: OK
44+
version: 1

src/openforms/forms/tests/test_import_export.py

+107-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from textwrap import dedent
77
from unittest.mock import patch
88

9-
from django.core.management import call_command
9+
from django.core.management import CommandError, call_command
1010
from django.test import TestCase, override_settings, tag
1111
from django.utils import translation
1212

@@ -22,6 +22,9 @@
2222
from openforms.payments.contrib.ogone.tests.factories import OgoneMerchantFactory
2323
from openforms.products.tests.factories import ProductFactory
2424
from openforms.registrations.contrib.objects_api.models import ObjectsAPIGroupConfig
25+
from openforms.registrations.contrib.zgw_apis.tests.factories import (
26+
ZGWApiGroupConfigFactory,
27+
)
2528
from openforms.translations.tests.utils import make_translated
2629
from openforms.utils.tests.vcr import OFVCRMixin
2730
from openforms.variables.constants import FormVariableSources
@@ -1521,3 +1524,106 @@ def test_import_form_with_objecttype_uuid_objects_api_registration_backend(self)
15211524
registration_backend.options["objecttype"],
15221525
"8e46e0a5-b1b4-449b-b9e9-fa3cea655f48",
15231526
)
1527+
1528+
1529+
class ImportZGWAPITests(TempdirMixin, OFVCRMixin, TestCase):
1530+
"""This test case requires the Open Zaak Docker Compose to be running.
1531+
1532+
See the relevant Docker compose in the ``docker/`` folder.
1533+
"""
1534+
1535+
VCR_TEST_FILES = PATH / "files"
1536+
1537+
def test_import_form_with_zgw_registration_backend_no_available_group(self):
1538+
1539+
resources = {
1540+
"forms": [
1541+
{
1542+
"active": True,
1543+
"name": "Test Form 1",
1544+
"internal_name": "Test Form Internal 1",
1545+
"slug": "zgw-no-group",
1546+
"uuid": "324cadce-a627-4e3f-b117-37ca232f16b2",
1547+
"registration_backends": [
1548+
{
1549+
"key": "test-backend",
1550+
"name": "Test backend",
1551+
"backend": "zgw-create-zaak",
1552+
"options": {
1553+
"zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1",
1554+
"informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1",
1555+
},
1556+
}
1557+
],
1558+
}
1559+
]
1560+
}
1561+
1562+
with zipfile.ZipFile(self.filepath, "w") as zip_file:
1563+
for name, data in resources.items():
1564+
zip_file.writestr(f"{name}.json", json.dumps(data))
1565+
1566+
with self.assertRaises(CommandError):
1567+
call_command("import", import_file=self.filepath)
1568+
1569+
def test_import_form_with_zgw_registration_backend_available_group(self):
1570+
resources = {
1571+
"forms": [
1572+
{
1573+
"active": True,
1574+
"name": "Test Form 1",
1575+
"internal_name": "Test Form Internal 1",
1576+
"slug": "zgw-no-group",
1577+
"uuid": "324cadce-a627-4e3f-b117-37ca232f16b2",
1578+
"registration_backends": [
1579+
{
1580+
"key": "test-backend",
1581+
"name": "Test backend",
1582+
"backend": "zgw-create-zaak",
1583+
"options": {
1584+
"zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc",
1585+
"informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7",
1586+
},
1587+
}
1588+
],
1589+
}
1590+
]
1591+
}
1592+
1593+
_credentials = {
1594+
"auth_type": AuthTypes.zgw,
1595+
"client_id": "test_client_id",
1596+
"secret": "test_secret_key",
1597+
}
1598+
zaken_service = ServiceFactory.create(
1599+
api_root="http://localhost:8003/zaken/api/v1/",
1600+
api_type=APITypes.zrc,
1601+
**_credentials,
1602+
)
1603+
documenten_service = ServiceFactory.create(
1604+
api_root="http://localhost:8003/documenten/api/v1/",
1605+
api_type=APITypes.drc,
1606+
**_credentials,
1607+
)
1608+
catalogi_service = ServiceFactory.create(
1609+
api_root="http://localhost:8003/catalogi/api/v1/",
1610+
api_type=APITypes.ztc,
1611+
**_credentials,
1612+
)
1613+
zgw_group = ZGWApiGroupConfigFactory.create(
1614+
zrc_service=zaken_service,
1615+
drc_service=documenten_service,
1616+
ztc_service=catalogi_service,
1617+
)
1618+
1619+
with zipfile.ZipFile(self.filepath, "w") as zip_file:
1620+
for name, data in resources.items():
1621+
zip_file.writestr(f"{name}.json", json.dumps(data))
1622+
1623+
call_command("import", import_file=self.filepath)
1624+
1625+
registration_backend = FormRegistrationBackend.objects.get(key="test-backend")
1626+
self.assertEqual(
1627+
registration_backend.options["zgw_api_group"],
1628+
zgw_group.pk,
1629+
)

src/openforms/registrations/api/filters.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from openforms.contrib.zgw.clients.catalogi import CatalogiClient
1010
from openforms.registrations.contrib.objects_api.models import ObjectsAPIGroupConfig
1111
from openforms.registrations.contrib.zgw_apis.client import get_catalogi_client
12-
from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig, ZgwConfig
12+
from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig
1313

1414
from ..registry import register
1515

@@ -18,9 +18,8 @@ class ListInformatieObjectTypenQueryParamsSerializer(serializers.Serializer):
1818
zgw_api_group = PrimaryKeyRelatedAsChoicesField(
1919
queryset=ZGWApiGroupConfig.objects.all(),
2020
help_text=_(
21-
"The primary key of the ZGW API set to use. If provided, the informatieobjecttypen from the Catalogi API "
22-
"in this set will be returned. Otherwise, the Catalogi API in the default ZGW API set will be used to find "
23-
"informatieobjecttypen."
21+
"The primary key of the ZGW API set to use. The informatieobjecttypen from the Catalogi API "
22+
"in this set will be returned."
2423
),
2524
label=_("ZGW API set"),
2625
required=False,
@@ -51,6 +50,13 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
5150
)
5251
)
5352

53+
if registration_backend == "zgw-create-zaak" and "zgw_api_group" not in attrs:
54+
raise serializers.ValidationError(
55+
_(
56+
"'zgw_api_group' is required when 'registration_backend' is set to 'zgw-create-zaak'."
57+
)
58+
)
59+
5460
return attrs
5561

5662
def get_fields(self):
@@ -63,15 +69,8 @@ def get_ztc_client(self) -> CatalogiClient | None:
6369
registration_backend: str = self.validated_data.get("registration_backend")
6470

6571
if registration_backend == "zgw-create-zaak":
66-
zgw_api_group: ZGWApiGroupConfig | None = self.validated_data.get(
67-
"zgw_api_group"
68-
)
69-
if zgw_api_group is not None:
70-
return get_catalogi_client(zgw_api_group)
71-
config = ZgwConfig.get_solo()
72-
assert isinstance(config, ZgwConfig)
73-
if group := config.default_zgw_api_group:
74-
return get_catalogi_client(group)
72+
zgw_api_group: ZGWApiGroupConfig = self.validated_data["zgw_api_group"]
73+
return get_catalogi_client(zgw_api_group)
7574
elif registration_backend == "objects_api":
7675
objects_api_group: ObjectsAPIGroupConfig = self.validated_data[
7776
"objects_api_group"

0 commit comments

Comments
 (0)