-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ [#4789] ConfigurationStep for ZGW API registration config #4876
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b1bbb84
:sparkles: [#4789] Add identifier field to ZGWAPIGroupConfig
stevenbal 680438a
:sparkles: [#4789] ConfigurationStep for ZGW API registration config
stevenbal 49a4051
:white_check_mark: [#4789] Add tests for ZGWApiConfigurationStep
stevenbal df117af
:whale: [#4789] Add example data for ZGW config step
stevenbal 6635402
:green_heart: Fix failing CI due to openapitools issue
stevenbal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only now realize you can't specify an objects API group at the model level 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the same issue as previously with objects API registration where it would always use the group with the lowest pk?