Skip to content

Commit

Permalink
[#2526] Allow for 0..n ZGW API groups to be configured
Browse files Browse the repository at this point in the history
This is a first step towards allowing multiple ZGW backends
throughout the platform. To maintain backwards compatibility
with the current datamodel, we proxy the current service
config fields to the new ZGWApiGroupConfig model as we
work our way towards making all ZGW client invocations
multi-backend aware.
  • Loading branch information
swrichards committed Jun 5, 2024
1 parent 54f2d72 commit caca0df
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 43 deletions.
19 changes: 8 additions & 11 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,20 @@
ZaakTypeInformatieObjectTypeConfig,
ZaakTypeResultaatTypeConfig,
ZaakTypeStatusTypeConfig,
ZGWApiGroupConfig,
)


class ZGWApiGroupConfig(admin.TabularInline):
model = ZGWApiGroupConfig
extra = 0


@admin.register(OpenZaakConfig)
class OpenZaakConfigAdmin(SingletonModelAdmin):
inlines = [ZGWApiGroupConfig]

fieldsets = (
(
None,
{
"fields": [
"zaak_service",
"catalogi_service",
"document_service",
"form_service",
]
},
),
(
"Advanced options",
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("zgw_consumers", "0019_alter_service_uuid"),
("openzaak", "0047_delete_statustranslation"),
]

operations = [
migrations.CreateModel(
name="ZGWApiGroupConfig",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"name",
models.CharField(
help_text="A recognisable name for this set of ZGW APIs.",
max_length=255,
verbose_name="name",
),
),
(
"drc_service",
models.ForeignKey(
limit_choices_to={"api_type": "drc"},
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="zgwset_drc_config",
to="zgw_consumers.service",
verbose_name="Documenten API",
),
),
(
"form_service",
models.OneToOneField(
limit_choices_to={"api_type": "orc"},
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="zgwset_orc_form_config",
to="zgw_consumers.service",
verbose_name="Form API",
),
),
(
"open_zaak_config",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="api_groups",
to="openzaak.openzaakconfig",
),
),
(
"zrc_service",
models.ForeignKey(
limit_choices_to={"api_type": "zrc"},
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="zgwset_zrc_config",
to="zgw_consumers.service",
verbose_name="Zaken API",
),
),
(
"ztc_service",
models.ForeignKey(
limit_choices_to={"api_type": "ztc"},
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="zgwset_ztc_config",
to="zgw_consumers.service",
verbose_name="Catalogi API",
),
),
],
options={
"verbose_name": "ZGW API set",
"verbose_name_plural": "ZGW API sets",
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import logging
from django.db import migrations


logger = logging.getLogger(__name__)


def migrate_zgw_service_config_to_default_group_config(apps, schema_editor):
ZGWApiGroupConfig = apps.get_model("openzaak", "ZGWApiGroupConfig")
OpenZaakConfig = apps.get_model("openzaak", "OpenZaakConfig")

for config in OpenZaakConfig.objects.all():
# OpenZaakConfig.objects.select_for_update().get(pk=config.pk) # Lock
ZGWApiGroupConfig.objects.create(
name="Migrated default config",
zrc_service=config.zaak_service,
drc_service=config.document_service,
ztc_service=config.catalogi_service,
form_service=config.form_service,
open_zaak_config=config,
)


def reverse_migrate_zgw_service_config_to_default_group_config(apps, schema_editor):
OpenZaakConfig = apps.get_model("openzaak", "OpenZaakConfig")

for config in OpenZaakConfig.objects.all():
if config.api_groups.count() == 0:
continue

if config.api_groups.count() > 1:
logger.warning("Multiple API groups to choose from, picking first")

group_config = config.api_groups.first()
config.zaak_service = group_config.zrc_service
config.document_service = group_config.drc_service
config.catalogi_service = group_config.ztc_service
config.form_service = group_config.form_service
config.save()


class Migration(migrations.Migration):

dependencies = [
("zgw_consumers", "0019_alter_service_uuid"),
("openzaak", "0049_add_multiple_zgw_backends_config"),
]

operations = [
migrations.RunPython(
migrate_zgw_service_config_to_default_group_config,
reverse_code=reverse_migrate_zgw_service_config_to_default_group_config,
atomic=True,
),
]
34 changes: 34 additions & 0 deletions src/open_inwoner/openzaak/migrations/0051_drop_root_zgw_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.11 on 2024-06-04 10:02

import logging
from django.db import migrations


logger = logging.getLogger(__name__)


class Migration(migrations.Migration):

dependencies = [
("zgw_consumers", "0019_alter_service_uuid"),
("openzaak", "0050_migrate_zgw_root_fields_to_multi_backend"),
]

operations = [
migrations.RemoveField(
model_name="openzaakconfig",
name="catalogi_service",
),
migrations.RemoveField(
model_name="openzaakconfig",
name="document_service",
),
migrations.RemoveField(
model_name="openzaakconfig",
name="form_service",
),
migrations.RemoveField(
model_name="openzaakconfig",
name="zaak_service",
),
]
Loading

0 comments on commit caca0df

Please sign in to comment.