Skip to content

Commit

Permalink
[#1468] Add configuration step for OpenKlant2 connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Dec 18, 2024
1 parent 09dc738 commit f5eae76
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion src/open_inwoner/configurations/bootstrap/openklant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@
from django_setup_configuration.exceptions import ConfigurationRunFailed
from django_setup_configuration.fields import DjangoModelRef
from django_setup_configuration.models import ConfigurationModel
from pydantic import Field
from zgw_consumers.constants import APITypes
from zgw_consumers.models import Service

from open_inwoner.configurations.bootstrap.utils import get_service
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.models import OpenKlant2Config, OpenKlantConfig


class OpenKlant2Configuration(ConfigurationModel):

service_identifier: str = DjangoModelRef(OpenKlant2Config, "service")

class Meta:
django_model_refs = {
OpenKlant2Config: (
"mijn_vragen_kanaal",
"mijn_vragen_organisatie_naam",
"mijn_vragen_actor",
"interne_taak_gevraagde_handeling",
"interne_taak_toelichting",
)
}


class KlantenApiConfigurationModel(ConfigurationModel):
Expand All @@ -19,6 +36,7 @@ class KlantenApiConfigurationModel(ConfigurationModel):
"exclude_contactmoment_kanalen",
default=None,
)
openklant2_config: OpenKlant2Configuration | None = Field(default=None)

class Meta:
django_model_refs = {
Expand Down Expand Up @@ -88,3 +106,39 @@ def execute(self, model: KlantenApiConfigurationModel):
raise ConfigurationRunFailed(
"Unable to validate and save configuration"
) from exc


class OpenKlant2ConfigurationStep(BaseConfigurationStep[OpenKlant2Configuration]):
"""
Configure the KIC settings and set any feature flags or other options if specified
"""

verbose_name = "OpenKlant2 APIs configuration"
enable_setting = "openklant2_config_enable"
namespace = "openklant2_config"
config_model = OpenKlant2Configuration

def execute(self, model: OpenKlant2Configuration):
try:
service = get_service(model.service_identifier)
except Service.DoesNotExist as exc:
raise ConfigurationRunFailed(
"Unable to retrieve Service with identifier"
f" `{model.service_identifier}`. Try first configuring the `zgw_consum"
"ers` configuration steps."
) from exc

create_or_update_kwargs = model.model_dump(exclude={"service_identifier"}) | {
"service": service
}

try:
config = OpenKlant2Config.objects.get()
except OpenKlant2Config.DoesNotExist:
config = OpenKlant2Config()

for key, val in create_or_update_kwargs.items():
setattr(config, key, val)

config.full_clean()
config.save()

0 comments on commit f5eae76

Please sign in to comment.