Skip to content

Commit

Permalink
✨ [#4789] ConfigurationStep for ZGW API registration config
Browse files Browse the repository at this point in the history
this step relies on the previously added ServiceConfigurationStep and can be used to set up the necessary configuration for the ZGW API registration backend
  • Loading branch information
stevenbal committed Dec 6, 2024
1 parent b1bbb84 commit a9486c1
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 12 deletions.
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.contrib.zgw.setup_configuration.steps.ZGWApiConfigurationStep",
]

#
Expand Down
13 changes: 1 addition & 12 deletions src/openforms/contrib/objects_api/setup_configuration/steps.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
from django_setup_configuration.configuration import BaseConfigurationStep
from zgw_consumers.models import Service

from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig
from openforms.utils.services import get_service

from .models import ObjectsAPIGroupConfigModel, SingleObjectsAPIGroupConfigModel


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 ObjectsAPIConfigurationStep(BaseConfigurationStep[ObjectsAPIGroupConfigModel]):
"""
Configure configuration groups for the Objects API backend
Expand Down
Empty file.
48 changes: 48 additions & 0 deletions src/openforms/contrib/zgw/setup_configuration/models.py
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)
42 changes: 42 additions & 0 deletions src/openforms/contrib/zgw/setup_configuration/steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django_setup_configuration.configuration import BaseConfigurationStep

from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig
from openforms.utils.services import get_service

from .models import SingleZGWApiGroupConfigModel, ZGWApiGroupConfigModel


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,
defaults=defaults,
)
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 a9486c1

Please sign in to comment.