Skip to content

Commit

Permalink
Merge pull request #4876 from open-formulieren/feature/4789-zgw-setup…
Browse files Browse the repository at this point in the history
…-config

✨ [#4789] ConfigurationStep for ZGW API registration config
  • Loading branch information
sergei-maertens authored Dec 9, 2024
2 parents 9407679 + 6635402 commit a25d84b
Show file tree
Hide file tree
Showing 18 changed files with 538 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,6 @@ jobs:
run: npm install -g @openapitools/[email protected]
- name: Validate schema
run: openapi-generator-cli validate -i ./openapi.yaml
- name: Set the version of openapi-generator which gets used
run: |
openapi-generator-cli version-manager set 7.0.0
- name: Generate Java client
run:
openapi-generator-cli generate -i ./openapi.yaml
Expand Down
31 changes: 31 additions & 0 deletions docker/setup_configuration/data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ zgw_consumers:
auth_type: api_key
header_key: Authorization
header_value: Token 7657474c3d75f56ae0abd0d1bf7994b09964dca9
- identifier: zaken-test
label: Zaken API test
api_root: http://openzaak-web.local:8000/zaken/api/v1/
api_type: zrc
auth_type: zgw
client_id: test_client_id
secret: test_secret_key
- identifier: documenten-test
label: Documenten API test
api_root: http://openzaak-web.local:8000/documenten/api/v1/
Expand Down Expand Up @@ -54,3 +61,27 @@ objects_api:
catalogue_domain: OTHER
catalogue_rsin: "000000000"
organisatie_rsin: "000000000"

zgw_api_config_enable: True
zgw_api:
groups:
- name: Config 1
identifier: config-1
zaken_service_identifier: zaken-test
documenten_service_identifier: documenten-test
catalogi_service_identifier: catalogi-test
catalogue_domain: TEST
catalogue_rsin: "000000000"
organisatie_rsin: "000000000"
zaak_vertrouwelijkheidaanduiding: zaakvertrouwelijk
doc_vertrouwelijkheidaanduiding: openbaar
auteur: John Doe
objects_api_json_content_template: |
{
"data": {% json_summary %},
"type": "{{ productaanvraag_type }}",
"bsn": "{{ variables.auth_bsn }}",
"submission_id": "{{ submission.kenmerk }}",
"language_code": "{{ submission.language_code }}",
"custom_field": "foo"
}
7 changes: 7 additions & 0 deletions openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.0.0"
}
}
1 change: 1 addition & 0 deletions src/openforms/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@
SETUP_CONFIGURATION_STEPS = [
"zgw_consumers.contrib.setup_configuration.steps.ServiceConfigurationStep",
"openforms.contrib.objects_api.setup_configuration.steps.ObjectsAPIConfigurationStep",
"openforms.registrations.contrib.zgw_apis.setup_configuration.steps.ZGWApiConfigurationStep",
]

#
Expand Down
18 changes: 15 additions & 3 deletions src/openforms/registrations/contrib/zgw_apis/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@

@admin.register(ZGWApiGroupConfig)
class ZGWApiGroupConfigAdmin(admin.ModelAdmin):
list_display = ("name", "zrc_service", "drc_service", "ztc_service")
list_display = ("name", "identifier", "zrc_service", "drc_service", "ztc_service")
list_select_related = ("zrc_service", "drc_service", "ztc_service")
search_fields = ("name",)
search_fields = (
"name",
"identifier",
)
raw_id_fields = ("zrc_service", "drc_service", "ztc_service")
prepopulated_fields = {"identifier": ["name"]}
ordering = ("name",)

fieldsets = (
(None, {"fields": ("name",)}),
(
None,
{
"fields": (
"name",
"identifier",
)
},
),
(
_("Services"),
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.2.16 on 2024-12-02 10:30

from django.db import migrations, models
from django.utils.text import slugify


def set_zgw_api_group_config_identifier_from_name(apps, schema_editor):
ZGWApiGroupConfig = apps.get_model("zgw_apis", "ZGWApiGroupConfig")

def generate_unique_identifier(original_identifier, count=0):
identifier = original_identifier + ("-" + str(count) if count else "")
if not ZGWApiGroupConfig.objects.filter(identifier=identifier).exists():
return identifier

return generate_unique_identifier(original_identifier, count + 1)

for row in ZGWApiGroupConfig.objects.all():
candidate_slug = slugify(row.name)
row.identifier = generate_unique_identifier(candidate_slug)
row.save(update_fields=["identifier"])


class Migration(migrations.Migration):

dependencies = [
("zgw_apis", "0015_explicit_objects_api_groups"),
]

operations = [
migrations.AddField(
model_name="zgwapigroupconfig",
name="identifier",
field=models.SlugField(
blank=True,
help_text="A unique, human-friendly identifier to identify this group.",
verbose_name="identifier",
),
),
migrations.RunPython(
set_zgw_api_group_config_identifier_from_name,
reverse_code=migrations.RunPython.noop,
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.16 on 2024-12-02 10:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("zgw_apis", "0016_zgwapigroupconfig_identifier"),
]

operations = [
migrations.AlterField(
model_name="zgwapigroupconfig",
name="identifier",
field=models.SlugField(
help_text="A unique, human-friendly identifier to identify this group.",
unique=True,
verbose_name="identifier",
),
),
]
7 changes: 7 additions & 0 deletions src/openforms/registrations/contrib/zgw_apis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class ZGWApiGroupConfig(models.Model):
max_length=255,
help_text=_("A recognisable name for this set of ZGW APIs."),
)
identifier = models.SlugField(
_("identifier"),
blank=False,
null=False,
unique=True,
help_text=_("A unique, human-friendly identifier to identify this group."),
)
zrc_service = models.ForeignKey(
"zgw_consumers.Service",
verbose_name=_("Zaken API"),
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from django_setup_configuration.fields import DjangoModelRef
from django_setup_configuration.models import ConfigurationModel
from pydantic import Field

from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig


class SingleZGWApiGroupConfigModel(ConfigurationModel):
zaken_service_identifier: str = DjangoModelRef(ZGWApiGroupConfig, "zrc_service")
documenten_service_identifier: str = DjangoModelRef(
ZGWApiGroupConfig,
"drc_service",
)
catalogi_service_identifier: str = DjangoModelRef(
ZGWApiGroupConfig,
"ztc_service",
)

# Slightly more descriptive name
objects_api_json_content_template: str = DjangoModelRef(
ZGWApiGroupConfig, "content_json"
)

# FIXME choices and blank=True doesn't seem to be picked up properly
zaak_vertrouwelijkheidaanduiding: str = DjangoModelRef(
ZGWApiGroupConfig,
"zaak_vertrouwelijkheidaanduiding",
default="",
)
doc_vertrouwelijkheidaanduiding: str = DjangoModelRef(
ZGWApiGroupConfig, "doc_vertrouwelijkheidaanduiding", default=""
)

class Meta:
django_model_refs = {
ZGWApiGroupConfig: [
"name",
"identifier",
"catalogue_domain",
"catalogue_rsin",
"organisatie_rsin",
"auteur",
]
}


class ZGWApiGroupConfigModel(ConfigurationModel):
groups: list[SingleZGWApiGroupConfigModel] = Field(default_factory=list)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from django_setup_configuration.configuration import BaseConfigurationStep
from zgw_consumers.models import Service

from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig

from .models import SingleZGWApiGroupConfigModel, ZGWApiGroupConfigModel


def get_service(slug: str) -> Service:
"""
Try to find a Service and re-raise DoesNotExist with the identifier to make debugging
easier
"""
try:
return Service.objects.get(slug=slug)
except Service.DoesNotExist as e:
raise Service.DoesNotExist(f"{str(e)} (identifier = {slug})")


class ZGWApiConfigurationStep(BaseConfigurationStep[ZGWApiGroupConfigModel]):
"""
Configure configuration groups for the ZGW API backend
"""

verbose_name = "Configuration to set up ZGW API registration backend services"
config_model = ZGWApiGroupConfigModel
namespace = "zgw_api"
enable_setting = "zgw_api_config_enable"

def execute(self, model: ZGWApiGroupConfigModel):
config: SingleZGWApiGroupConfigModel
for config in model.groups:
# setup_configuration typing doesn't work for `django_model_refs` yet,
# hence the type: ignores
# (https://github.com/maykinmedia/django-setup-configuration/issues/25)
defaults = {
"name": config.name, # type: ignore
"zrc_service": get_service(config.zaken_service_identifier),
"drc_service": get_service(config.documenten_service_identifier),
"ztc_service": get_service(config.catalogi_service_identifier),
"catalogue_domain": config.catalogue_domain, # type: ignore
"catalogue_rsin": config.catalogue_rsin, # type: ignore
"organisatie_rsin": config.organisatie_rsin, # type: ignore
"zaak_vertrouwelijkheidaanduiding": config.zaak_vertrouwelijkheidaanduiding,
"doc_vertrouwelijkheidaanduiding": config.doc_vertrouwelijkheidaanduiding,
"auteur": config.auteur, # type: ignore
"content_json": config.objects_api_json_content_template,
}

ZGWApiGroupConfig.objects.update_or_create(
identifier=config.identifier, # type: ignore
defaults=defaults,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class ZGWApiGroupConfigFactory(factory.django.DjangoModelFactory):
name = factory.Sequence(lambda n: "ZGW API set %03d" % n)
identifier = factory.Sequence(lambda n: f"zgw-api-group-{n}")
zrc_service = factory.SubFactory(
"zgw_consumers.test.factories.ServiceFactory", api_type=APITypes.zrc
)
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
zgw_api_config_enable: True
zgw_api:
groups:
- name: Config 1
identifier: config-1
zaken_service_identifier: zaken-test
documenten_service_identifier: documenten-test
catalogi_service_identifier: catalogi-test
catalogue_domain: TEST
catalogue_rsin: "000000000"
organisatie_rsin: "000000000"
zaak_vertrouwelijkheidaanduiding: zaakvertrouwelijk
doc_vertrouwelijkheidaanduiding: openbaar
auteur: John Doe
objects_api_json_content_template: |
{
"data": {% json_summary %},
"type": "{{ productaanvraag_type }}",
"bsn": "{{ variables.auth_bsn }}",
"submission_id": "{{ submission.kenmerk }}",
"language_code": "{{ submission.language_code }}",
"custom_field": "foo"
}
- name: Config 2
identifier: config-2
zaken_service_identifier: zaken-test
documenten_service_identifier: documenten-test
catalogi_service_identifier: catalogi-test
catalogue_domain: OTHER
catalogue_rsin: "000000000"
organisatie_rsin: "000000000"
auteur: Jane Doe
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
zgw_api_config_enable: True
zgw_api:
groups:
- name: Config 1
identifier: config-1
zaken_service_identifier: zaken-test
documenten_service_identifier: documenten-test
catalogi_service_identifier: catalogi-test
catalogue_domain: TEST
catalogue_rsin: "000000000"
organisatie_rsin: "000000000"
zaak_vertrouwelijkheidaanduiding: zaakvertrouwelijk
doc_vertrouwelijkheidaanduiding: openbaar
auteur: John Doe
objects_api_json_content_template: |
{
"data": {% json_summary %},
"type": "{{ productaanvraag_type }}",
"bsn": "{{ variables.auth_bsn }}",
"submission_id": "{{ submission.kenmerk }}",
"language_code": "{{ submission.language_code }}",
"custom_field": "foo"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
zgw_api_config_enable: True
zgw_api:
groups:
- name: Config 1
identifier: config-1
zaken_service_identifier: zaken-test
documenten_service_identifier: documenten-test
catalogi_service_identifier: catalogi-test
auteur: Jane Doe
Loading

0 comments on commit a25d84b

Please sign in to comment.