-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [#4789] ConfigurationStep for ZGW API registration config
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
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
48 changes: 48 additions & 0 deletions
48
src/openforms/registrations/contrib/zgw_apis/setup_configuration/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
53 changes: 53 additions & 0 deletions
53
src/openforms/registrations/contrib/zgw_apis/setup_configuration/steps.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |