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 9, 2024
1 parent b1bbb84 commit 10e0750
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 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.registrations.contrib.zgw_apis.setup_configuration.steps.ZGWApiConfigurationStep",
]

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

0 comments on commit 10e0750

Please sign in to comment.