Skip to content

Commit

Permalink
[#2975] Add enum for klant backend to ZGW API groups
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Jan 29, 2025
1 parent 86ac24a commit 7ed2ecc
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 4.2.16 on 2025-01-16 14:41

from django.db import migrations, models

import open_inwoner.openklant.models


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.18 on 2025-01-29 09:03

from django.db import migrations, models

import open_inwoner.openklant.models


class Migration(migrations.Migration):

dependencies = [
("openklant", "0023_remove_esuiteklantconfig_register_contact_moment_and_more"),
]

operations = [
migrations.AlterField(
model_name="klantensysteemconfig",
name="primary_backend",
field=models.CharField(
choices=[("esuite", "ESUITE"), ("openklant2", "OPENKLANT2")],
help_text="Choose the primary backend for retrieving klanten data. Changes to klanten data will be saved to both backends (if configured).",
max_length=10,
validators=[open_inwoner.openklant.models.validate_backend_choice],
verbose_name="Primary backend",
),
),
]
32 changes: 28 additions & 4 deletions src/open_inwoner/openklant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,26 +217,50 @@ class Meta:
verbose_name = _("OpenKlant2 configuration")


# Deprecated in favor of `validate_backend_choice`, which has more general use
def validate_primary_backend(value):
if value == KlantenServiceType.OPENKLANT2.value:
config = OpenKlant2Config.get_solo()
if not config.service:
raise ValidationError(
"OpenKlant2 must be configured with a Klanten API service before it can be selected "
"as primary backend"
"as backend"
)
return

config = ESuiteKlantConfig.get_solo()
if not config.klanten_service:
raise ValidationError(
"The Esuite klant system must be configured with a Klanten API service before it can be selected "
"as primary backend"
"as backend"
)
if not config.contactmomenten_service:
raise ValidationError(
"The Esuite klant system must be configured with a Contactmomenten API service service before "
"it can be selected as primary backend"
"it can be selected as backend"
)


def validate_backend_choice(value):
if value == KlantenServiceType.OPENKLANT2.value:
config = OpenKlant2Config.get_solo()
if not config.service:
raise ValidationError(
"OpenKlant2 must be configured with a Klanten API service before it can be selected "
"as backend"
)
return

config = ESuiteKlantConfig.get_solo()
if not config.klanten_service:
raise ValidationError(
"The Esuite klant system must be configured with a Klanten API service before it can be selected "
"as backend"
)
if not config.contactmomenten_service:
raise ValidationError(
"The Esuite klant system must be configured with a Contactmomenten API service service before "
"it can be selected as backend"
)


Expand All @@ -249,7 +273,7 @@ class KlantenSysteemConfig(SingletonModel):
"Choose the primary backend for retrieving klanten data. "
"Changes to klanten data will be saved to both backends (if configured)."
),
validators=[validate_primary_backend],
validators=[validate_backend_choice],
)
register_contact_via_api = models.BooleanField(
verbose_name=_("Registreer op API"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.18 on 2025-01-28 16:08

from django.db import migrations, models

import open_inwoner.openklant.models


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0061_merge_20250124_1149"),
]

operations = [
migrations.AddField(
model_name="zgwapigroupconfig",
name="klant_backend",
field=models.CharField(
choices=[("esuite", "ESUITE"), ("openklant2", "OPENKLANT2")],
default="esuite",
help_text="Choose the API backend for retrieving klanten data.",
max_length=10,
validators=[open_inwoner.openklant.models.validate_backend_choice],
verbose_name="Klant API backend",
),
),
]
13 changes: 13 additions & 0 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from zgw_consumers.constants import APITypes
from zgw_consumers.models import Service

from open_inwoner.openklant.constants import KlantenServiceType
from open_inwoner.openklant.models import validate_backend_choice
from open_inwoner.openzaak.managers import (
CatalogusConfigManager,
UserCaseInfoObjectNotificationManager,
Expand Down Expand Up @@ -252,6 +254,7 @@ def forms_client(self):
if self.form_service:
return cast(FormClient, self._build_client_from_attr("form_service"))

# backend-specific flags
fetch_eherkenning_zaken_with_rsin = models.BooleanField(
verbose_name=_(
"Fetch Zaken for users authenticated with eHerkenning using RSIN"
Expand All @@ -263,6 +266,16 @@ def forms_client(self):
default=False,
)

# flags related to other services
klant_backend = models.CharField(
verbose_name=_("Klant API backend"),
max_length=10,
choices=[(service.value, service.name) for service in KlantenServiceType],
default=KlantenServiceType.ESUITE.value,
help_text=_("Choose the API backend for retrieving klanten data."),
validators=[validate_backend_choice],
)

class Meta:
verbose_name = _("ZGW API set")
verbose_name_plural = _("ZGW API sets")
Expand Down

0 comments on commit 7ed2ecc

Please sign in to comment.