Skip to content

Commit afb1863

Browse files
committed
Add OpenKlantConfig configuration step
1 parent 448d864 commit afb1863

File tree

7 files changed

+278
-482
lines changed

7 files changed

+278
-482
lines changed

src/open_inwoner/conf/app/setup_configuration.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
SETUP_CONFIGURATION_STEPS = [
44
"zgw_consumers.contrib.setup_configuration.steps.ServiceConfigurationStep",
55
"open_inwoner.configurations.bootstrap.zgw.ZGWAPIsConfigurationStep",
6+
"open_inwoner.configurations.bootstrap.openklant.OpenKlantConfigurationStep",
67
]
78
OIP_ORGANIZATION = config("OIP_ORGANIZATION", "")
89

src/open_inwoner/configurations/bootstrap/kic.py

-276
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from django.core.exceptions import ValidationError
2+
3+
from django_setup_configuration.configuration import BaseConfigurationStep
4+
from django_setup_configuration.exceptions import ConfigurationRunFailed
5+
from django_setup_configuration.fields import DjangoModelRef
6+
from django_setup_configuration.models import ConfigurationModel
7+
from zgw_consumers.constants import APITypes
8+
from zgw_consumers.models import Service
9+
10+
from open_inwoner.configurations.bootstrap.utils import get_service
11+
from open_inwoner.openklant.models import OpenKlantConfig
12+
13+
14+
class KlantenApiConfigurationModel(ConfigurationModel):
15+
klanten_service_identifier: str
16+
contactmomenten_service_identifier: str
17+
exclude_contactmoment_kanalen: list[str] | None = DjangoModelRef(
18+
OpenKlantConfig,
19+
"exclude_contactmoment_kanalen",
20+
default=None,
21+
)
22+
23+
class Meta:
24+
django_model_refs = {
25+
OpenKlantConfig: (
26+
"register_email",
27+
"register_contact_moment",
28+
"register_bronorganisatie_rsin",
29+
"register_channel",
30+
"register_type",
31+
"register_employee_id",
32+
"use_rsin_for_innNnpId_query_parameter",
33+
"send_email_confirmation",
34+
)
35+
}
36+
37+
38+
class OpenKlantConfigurationStep(BaseConfigurationStep[KlantenApiConfigurationModel]):
39+
"""
40+
Configure the KIC settings and set any feature flags or other options if specified
41+
"""
42+
43+
verbose_name = "Klantinteractie APIs configuration"
44+
enable_setting = "openklant_config_enable"
45+
namespace = "openklant_config"
46+
config_model = KlantenApiConfigurationModel
47+
48+
def execute(self, model: KlantenApiConfigurationModel):
49+
config = OpenKlantConfig.get_solo()
50+
51+
try:
52+
kc = get_service(model.klanten_service_identifier)
53+
if kc.api_type != APITypes.kc:
54+
raise ConfigurationRunFailed(
55+
f"Found klanten service with identifier `{kc.slug}`, but expected"
56+
f" `api_type` to equal `{APITypes.kc}` and got `{kc.api_type}`"
57+
)
58+
config.klanten_service = kc
59+
60+
cm = get_service(model.contactmomenten_service_identifier)
61+
if cm.api_type != APITypes.cmc:
62+
raise ConfigurationRunFailed(
63+
f"Found contactmomenten service with identifier `{cm.slug}`, but"
64+
f" expected `api_type` to equal `{APITypes.cmc}` and got "
65+
f"`{cm.api_type}`"
66+
)
67+
68+
config.contactmomenten_service = cm
69+
except Service.DoesNotExist as exc:
70+
raise ConfigurationRunFailed(
71+
"Unable to retrieve `klanten_service` and/or `contactmomenten_service`"
72+
". Try first configuring the `zgw_consumers` configuration steps, and."
73+
" ensure that both the `identifier` and `api_type` fields match."
74+
) from exc
75+
76+
for key, val in model.model_dump(
77+
exclude={
78+
"klanten_service_identifier",
79+
"contactmomenten_service_identifier",
80+
}
81+
).items():
82+
setattr(config, key, val)
83+
84+
try:
85+
config.full_clean()
86+
config.save()
87+
except ValidationError as exc:
88+
raise ConfigurationRunFailed(
89+
"Unable to validate and save configuration"
90+
) from exc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
openklant_config_enable: true
2+
openklant_config:
3+
klanten_service_identifier: klanten-service
4+
contactmomenten_service_identifier: contactmomenten-service
5+
exclude_contactmoment_kanalen: []
6+
register_email: [email protected]
7+
register_contact_moment: true
8+
register_bronorganisatie_rsin: '837194569'
9+
register_channel: email
10+
register_type: bericht
11+
register_employee_id: '1234'
12+
use_rsin_for_innNnpId_query_parameter: true
13+
send_email_confirmation: false

src/open_inwoner/configurations/tests/bootstrap/test_setup_configuration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
CMSProductsConfigurationStep,
2222
CMSProfileConfigurationStep,
2323
)
24-
from open_inwoner.configurations.bootstrap.kic import (
24+
from open_inwoner.configurations.bootstrap.openklant import (
2525
ContactmomentenAPIConfigurationStep,
2626
KICAPIsConfigurationStep,
2727
KlantenAPIConfigurationStep,

0 commit comments

Comments
 (0)