Skip to content

Commit

Permalink
Merge pull request #1532 from maykinmedia/ok2-setup-configuration
Browse files Browse the repository at this point in the history
[#1468] Add configuration step for OpenKlant2 connectivity
  • Loading branch information
swrichards authored Dec 19, 2024
2 parents 2429bd2 + 833c1ab commit 90d0d6c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 3 deletions.
12 changes: 12 additions & 0 deletions docker/setup_configuration/data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ zgw_consumers:
client_id: test-vcr
secret: test-vcr

# Openzaak
openzaak_config_enable: true
openzaak_config:
zaak_max_confidentiality: openbaar
Expand All @@ -108,6 +109,7 @@ openzaak_config:
documenten_api_identifier: documenten-test
catalogi_api_identifier: catalogi-test

# OpenKlant (v1, i.e. eSuite)
openklant_config_enable: true
openklant_config:
klanten_service_identifier: klanten-test
Expand All @@ -121,3 +123,13 @@ openklant_config:
register_employee_id: '1234'
use_rsin_for_innNnpId_query_parameter: true
send_email_confirmation: false

# OpenKlant2
openklant2_config_enable: true
openklant2_config:
service_identifier: klanten-service
mijn_vragen_kanaal: formulier
mijn_vragen_organisatie_naam: De Gemeente
mijn_vragen_actor: e412c6f6-bc31-4fd4-b883-0fb5e88d3f5b
interne_taak_gevraagde_handeling: Vraag beantwoorden
interne_taak_toelichting: Vraag via OIP, graag beantwoorden
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 UUID4, 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")
mijn_vragen_actor: UUID4 = DjangoModelRef(OpenKlant2Config, "mijn_vragen_actor")

class Meta:
django_model_refs = {
OpenKlant2Config: (
"mijn_vragen_kanaal",
"mijn_vragen_organisatie_naam",
"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 OpenKlant2 settings.
"""

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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
openklant2_config_enable: true
openklant2_config:
service_identifier: klanten-service
mijn_vragen_kanaal: formulier
mijn_vragen_organisatie_naam: De Gemeente
mijn_vragen_actor: e412c6f6-bc31-4fd4-b883-0fb5e88d3f5b
interne_taak_gevraagde_handeling: Vraag beantwoorden
interne_taak_toelichting: Vraag via OIP, graag beantwoorden
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
from django_setup_configuration.test_utils import execute_single_step
from zgw_consumers.constants import APITypes

from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.models import OpenKlant2Config, OpenKlantConfig
from open_inwoner.openzaak.tests.factories import ServiceFactory

from ...bootstrap.openklant import OpenKlantConfigurationStep
from ...bootstrap.openklant import (
OpenKlant2ConfigurationStep,
OpenKlantConfigurationStep,
)

KLANTEN_SERVICE_API_ROOT = "https://openklant.local/klanten/api/v1/"
CONTACTMOMENTEN_SERVICE_API_ROOT = "https://openklant.local/contactmomenten/api/v1/"

BASE_DIR = Path(__file__).parent / "files"
OPENKLANT_CONFIG_STEP_FULL_YAML = str(BASE_DIR / "openklant_config_step_full.yaml")
OPENKLANT2_CONFIG_STEP_FULL_YAML = str(BASE_DIR / "openklant2_config_step_full.yaml")


class OpenKlantConfigurationStepTestCase(TestCase):
Expand Down Expand Up @@ -171,3 +175,30 @@ def assert_values():
)

assert_values()


class OpenKlant2ConfigurationStepTestCase(TestCase):
def test_configure(self):
kc = ServiceFactory(
slug="klanten-service",
api_root=KLANTEN_SERVICE_API_ROOT,
api_type=APITypes.kc,
)

execute_single_step(
OpenKlant2ConfigurationStep, yaml_source=OPENKLANT2_CONFIG_STEP_FULL_YAML
)

config = OpenKlant2Config.objects.get()

self.assertEqual(config.service, kc)
self.assertEqual(config.mijn_vragen_kanaal, "formulier")

self.assertEqual(config.mijn_vragen_organisatie_naam, "De Gemeente")
self.assertEqual(
config.mijn_vragen_actor, "e412c6f6-bc31-4fd4-b883-0fb5e88d3f5b"
)
self.assertEqual(config.interne_taak_gevraagde_handeling, "Vraag beantwoorden")
self.assertEqual(
config.interne_taak_toelichting, "Vraag via OIP, graag beantwoorden"
)

0 comments on commit 90d0d6c

Please sign in to comment.