diff --git a/docker/setup_configuration/data.yaml b/docker/setup_configuration/data.yaml index e848fce648..4627027f2b 100644 --- a/docker/setup_configuration/data.yaml +++ b/docker/setup_configuration/data.yaml @@ -86,6 +86,7 @@ zgw_consumers: client_id: test-vcr secret: test-vcr +# Openzaak openzaak_config_enable: true openzaak_config: zaak_max_confidentiality: openbaar @@ -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 @@ -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 diff --git a/src/open_inwoner/configurations/bootstrap/openklant.py b/src/open_inwoner/configurations/bootstrap/openklant.py index ea30ed505d..a44986bfe4 100644 --- a/src/open_inwoner/configurations/bootstrap/openklant.py +++ b/src/open_inwoner/configurations/bootstrap/openklant.py @@ -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): @@ -19,6 +36,7 @@ class KlantenApiConfigurationModel(ConfigurationModel): "exclude_contactmoment_kanalen", default=None, ) + openklant2_config: OpenKlant2Configuration | None = Field(default=None) class Meta: django_model_refs = { @@ -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() diff --git a/src/open_inwoner/configurations/tests/bootstrap/files/openklant2_config_step_full.yaml b/src/open_inwoner/configurations/tests/bootstrap/files/openklant2_config_step_full.yaml new file mode 100644 index 0000000000..e59c5ec9ad --- /dev/null +++ b/src/open_inwoner/configurations/tests/bootstrap/files/openklant2_config_step_full.yaml @@ -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 diff --git a/src/open_inwoner/configurations/tests/bootstrap/test_setup_openklant_config.py b/src/open_inwoner/configurations/tests/bootstrap/test_setup_openklant_config.py index 3291bb3d7f..6f142692f4 100644 --- a/src/open_inwoner/configurations/tests/bootstrap/test_setup_openklant_config.py +++ b/src/open_inwoner/configurations/tests/bootstrap/test_setup_openklant_config.py @@ -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): @@ -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" + )