-
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.
Merge pull request #4876 from open-formulieren/feature/4789-zgw-setup…
…-config ✨ [#4789] ConfigurationStep for ZGW API registration config
- Loading branch information
Showing
18 changed files
with
538 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
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
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,7 @@ | ||
{ | ||
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", | ||
"spaces": 2, | ||
"generator-cli": { | ||
"version": "7.0.0" | ||
} | ||
} |
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
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
43 changes: 43 additions & 0 deletions
43
src/openforms/registrations/contrib/zgw_apis/migrations/0016_zgwapigroupconfig_identifier.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,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, | ||
), | ||
] |
22 changes: 22 additions & 0 deletions
22
...orms/registrations/contrib/zgw_apis/migrations/0017_alter_zgwapigroupconfig_identifier.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,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", | ||
), | ||
), | ||
] |
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, # type: ignore | ||
defaults=defaults, | ||
) |
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.
32 changes: 32 additions & 0 deletions
32
...penforms/registrations/contrib/zgw_apis/tests/setup_configuration/files/setup_config.yaml
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,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 |
23 changes: 23 additions & 0 deletions
23
...gistrations/contrib/zgw_apis/tests/setup_configuration/files/setup_config_all_fields.yaml
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,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" | ||
} |
9 changes: 9 additions & 0 deletions
9
...ations/contrib/zgw_apis/tests/setup_configuration/files/setup_config_required_fields.yaml
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,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 |
Oops, something went wrong.