Skip to content

Commit

Permalink
[#2821] Implement provisional configuration for OpenKlant2 service + …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
pi-sigma authored and swrichards committed Oct 24, 2024
1 parent 0862012 commit d4965e0
Show file tree
Hide file tree
Showing 16 changed files with 469 additions and 332 deletions.
29 changes: 29 additions & 0 deletions src/open_inwoner/openklant/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import uuid
from dataclasses import dataclass
from urllib.parse import urljoin

from django.db import models
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -184,3 +188,28 @@ class Meta:
verbose_name = _("KlantContactMoment")
verbose_name_plural = _("KlantContactMomenten")
unique_together = [["user", "contactmoment_url"]]


@dataclass
class OpenKlant2Config:
api_root: str
api_path: str
api_token: str

# Question/Answer settings
mijn_vragen_kanaal: str
mijn_vragen_organisatie_naam: str
mijn_vragen_actor: str | uuid.UUID | None
interne_taak_gevraagde_handeling: str
interne_taak_toelichting: str

@property
def api_url(self):
return urljoin(self.api_root, self.api_path)

@classmethod
def from_django_settings(cls):
from django.conf import settings

if config := getattr(settings, "OPENKLANT2_CONFIG", None):
return cls(**config)
41 changes: 25 additions & 16 deletions src/open_inwoner/openklant/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.openklant.api_models import Klant
from open_inwoner.openklant.clients import build_klanten_client
from open_inwoner.openklant.models import OpenKlant2Config
from open_inwoner.utils.logentry import system_action
from openklant2.client import OpenKlant2Client
from openklant2.types.resources.digitaal_adres import DigitaalAdres
Expand Down Expand Up @@ -147,20 +148,16 @@ def from_klantcontact_and_answer(


class OpenKlant2Service:

config: OpenKlant2Config
client: OpenKlant2Client
mijn_vragen_actor: uuid.UUID | None
MIJN_VRAGEN_KANAAL: str = "oip_mijn_vragen"

def __init__(
self, client: OpenKlant2Client, mijn_vragen_actor: str | uuid.UUID | None = None
):
if not isinstance(client, OpenKlant2Client):
raise ValueError(
f"`client` must be an instance of {type(OpenKlant2Client)}"
)
self.client = client
if mijn_vragen_actor:

def __init__(self, config: OpenKlant2Config | None = None):
self.config = config or OpenKlant2Config.from_django_settings()
self.client = OpenKlant2Client(
api_url=self.config.api_url,
api_token=self.config.api_token,
)
if mijn_vragen_actor := getattr(config, "mijn_vragen_actor", None):
self.mijn_vragen_actor = (
uuid.UUID(mijn_vragen_actor)
if isinstance(mijn_vragen_actor, str)
Expand Down Expand Up @@ -465,7 +462,7 @@ def create_question(
"inhoud": question,
"onderwerp": subject,
"taal": "nld",
"kanaal": self.MIJN_VRAGEN_KANAAL,
"kanaal": self.config.mijn_vragen_kanaal,
"vertrouwelijk": False,
"plaatsgevondenOp": timezone.now().isoformat(),
}
Expand Down Expand Up @@ -512,7 +509,7 @@ def create_answer(
"inhoud": answer,
"onderwerp": question_klantcontact["onderwerp"],
"taal": "nld",
"kanaal": self.MIJN_VRAGEN_KANAAL,
"kanaal": self.config.mijn_vragen_kanaal,
"vertrouwelijk": False,
"plaatsgevondenOp": timezone.now().isoformat(),
}
Expand Down Expand Up @@ -561,6 +558,18 @@ def klantcontacten_for_partij(
# Partij (see https://github.com/maykinmedia/open-klant/issues/256). So
# unfortunately, we have to fetch all rows and do the filtering client
# side.
klantcontacten = self.client.klant_contact.list_iter(
params={
"expand": [
"leiddeTotInterneTaken",
"gingOverOnderwerpobjecten",
"hadBetrokkenen",
"hadBetrokkenen.wasPartij",
],
"kanaal": self.config.mijn_vragen_kanaal,
}
)

klantcontacten_for_partij = filter(
lambda row: partij_uuid
in glom.glom(
Expand All @@ -578,7 +587,7 @@ def questions_for_partij(self, partij_uuid: str) -> list[OpenKlant2Question]:
klantcontact_uuid_to_klantcontact_object = {}

for klantcontact in self.klantcontacten_for_partij(
partij_uuid, kanaal=self.MIJN_VRAGEN_KANAAL
partij_uuid, kanaal=self.config.mijn_vragen_kanaal
):
klantcontact_uuid_to_klantcontact_object[
klantcontact["uuid"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
uri: http://localhost:8338/klantinteracties/api/v1/partijen
response:
body:
string: '{"uuid":"199ab61c-d0cf-4531-9dd5-54c17116f7ec","url":"http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec","nummer":"0000000001","interneNotitie":"","betrokkenen":[],"categorieRelaties":[],"digitaleAdressen":[],"voorkeursDigitaalAdres":null,"vertegenwoordigden":[],"rekeningnummers":[],"voorkeursRekeningnummer":null,"partijIdentificatoren":[],"soortPartij":"persoon","indicatieGeheimhouding":false,"voorkeurstaal":"crp","indicatieActief":true,"bezoekadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"correspondentieadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"partijIdentificatie":{"contactnaam":{"voorletters":"Dr.","voornaam":"Test
string: '{"uuid":"89424a8a-fc4e-41f2-81ed-d5cc21675c2b","url":"http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b","nummer":"0000000001","interneNotitie":"","betrokkenen":[],"categorieRelaties":[],"digitaleAdressen":[],"voorkeursDigitaalAdres":null,"vertegenwoordigden":[],"rekeningnummers":[],"voorkeursRekeningnummer":null,"partijIdentificatoren":[],"soortPartij":"persoon","indicatieGeheimhouding":false,"voorkeurstaal":"crp","indicatieActief":true,"bezoekadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"correspondentieadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"partijIdentificatie":{"contactnaam":{"voorletters":"Dr.","voornaam":"Test
Persoon","voorvoegselAchternaam":"Mrs.","achternaam":"Gamble"},"volledigeNaam":"Test
Persoon Mrs. Gamble"}}'
headers:
Expand All @@ -31,7 +31,7 @@ interactions:
Cross-Origin-Opener-Policy:
- same-origin
Location:
- http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec
- http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b
Referrer-Policy:
- same-origin
Vary:
Expand All @@ -44,7 +44,7 @@ interactions:
code: 201
message: Created
- request:
body: '{"identificeerdePartij": {"uuid": "199ab61c-d0cf-4531-9dd5-54c17116f7ec"},
body: '{"identificeerdePartij": {"uuid": "89424a8a-fc4e-41f2-81ed-d5cc21675c2b"},
"partijIdentificator": {"codeObjecttype": "bsn", "codeSoortObjectId": "inp",
"objectId": "123456789", "codeRegister": "brp"}, "anderePartijIdentificator":
"optional_identifier_123"}'
Expand All @@ -59,7 +59,7 @@ interactions:
uri: http://localhost:8338/klantinteracties/api/v1/partij-identificatoren
response:
body:
string: '{"uuid":"ac00fd3b-c89e-450d-a36a-67dd632bea7e","url":"http://localhost:8338/klantinteracties/api/v1/partij-identificatoren/ac00fd3b-c89e-450d-a36a-67dd632bea7e","identificeerdePartij":{"uuid":"199ab61c-d0cf-4531-9dd5-54c17116f7ec","url":"http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec"},"anderePartijIdentificator":"optional_identifier_123","partijIdentificator":{"codeObjecttype":"bsn","codeSoortObjectId":"inp","objectId":"123456789","codeRegister":"brp"}}'
string: '{"uuid":"350ed1a7-7551-4ed5-8fdf-cc95942d67e2","url":"http://localhost:8338/klantinteracties/api/v1/partij-identificatoren/350ed1a7-7551-4ed5-8fdf-cc95942d67e2","identificeerdePartij":{"uuid":"89424a8a-fc4e-41f2-81ed-d5cc21675c2b","url":"http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b"},"anderePartijIdentificator":"optional_identifier_123","partijIdentificator":{"codeObjecttype":"bsn","codeSoortObjectId":"inp","objectId":"123456789","codeRegister":"brp"}}'
headers:
API-version:
- 0.0.3
Expand All @@ -72,7 +72,7 @@ interactions:
Cross-Origin-Opener-Policy:
- same-origin
Location:
- http://localhost:8338/klantinteracties/api/v1/partij-identificatoren/ac00fd3b-c89e-450d-a36a-67dd632bea7e
- http://localhost:8338/klantinteracties/api/v1/partij-identificatoren/350ed1a7-7551-4ed5-8fdf-cc95942d67e2
Referrer-Policy:
- same-origin
Vary:
Expand All @@ -90,10 +90,10 @@ interactions:
Authorization:
- Token b2eb1da9861da88743d72a3fb4344288fe2cba44
method: GET
uri: http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec?expand=digitaleAdressen
uri: http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b?expand=digitaleAdressen
response:
body:
string: '{"uuid":"199ab61c-d0cf-4531-9dd5-54c17116f7ec","url":"http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec","nummer":"0000000001","interneNotitie":"","betrokkenen":[],"categorieRelaties":[],"digitaleAdressen":[],"voorkeursDigitaalAdres":null,"vertegenwoordigden":[],"rekeningnummers":[],"voorkeursRekeningnummer":null,"partijIdentificatoren":[{"uuid":"ac00fd3b-c89e-450d-a36a-67dd632bea7e","url":"http://localhost:8338/klantinteracties/api/v1/partij-identificatoren/ac00fd3b-c89e-450d-a36a-67dd632bea7e"}],"soortPartij":"persoon","indicatieGeheimhouding":false,"voorkeurstaal":"crp","indicatieActief":true,"bezoekadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"correspondentieadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"partijIdentificatie":{"contactnaam":{"voorletters":"Dr.","voornaam":"Test
string: '{"uuid":"89424a8a-fc4e-41f2-81ed-d5cc21675c2b","url":"http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b","nummer":"0000000001","interneNotitie":"","betrokkenen":[],"categorieRelaties":[],"digitaleAdressen":[],"voorkeursDigitaalAdres":null,"vertegenwoordigden":[],"rekeningnummers":[],"voorkeursRekeningnummer":null,"partijIdentificatoren":[{"uuid":"350ed1a7-7551-4ed5-8fdf-cc95942d67e2","url":"http://localhost:8338/klantinteracties/api/v1/partij-identificatoren/350ed1a7-7551-4ed5-8fdf-cc95942d67e2"}],"soortPartij":"persoon","indicatieGeheimhouding":false,"voorkeurstaal":"crp","indicatieActief":true,"bezoekadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"correspondentieadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"partijIdentificatie":{"contactnaam":{"voorletters":"Dr.","voornaam":"Test
Persoon","voorvoegselAchternaam":"Mrs.","achternaam":"Gamble"},"volledigeNaam":"Test
Persoon Mrs. Gamble"}}'
headers:
Expand All @@ -120,7 +120,7 @@ interactions:
message: OK
- request:
body: '{"adres": "another-user@foo.com", "soortDigitaalAdres": "email", "verstrektDoorPartij":
{"uuid": "199ab61c-d0cf-4531-9dd5-54c17116f7ec"}, "verstrektDoorBetrokkene":
{"uuid": "89424a8a-fc4e-41f2-81ed-d5cc21675c2b"}, "verstrektDoorBetrokkene":
null, "omschrijving": "OIP profiel"}'
headers:
Authorization:
Expand All @@ -133,7 +133,7 @@ interactions:
uri: http://localhost:8338/klantinteracties/api/v1/digitaleadressen
response:
body:
string: '{"uuid":"35849def-1649-4ee7-874d-a807ea0f4da4","url":"http://localhost:8338/klantinteracties/api/v1/digitaleadressen/35849def-1649-4ee7-874d-a807ea0f4da4","verstrektDoorBetrokkene":null,"verstrektDoorPartij":{"uuid":"199ab61c-d0cf-4531-9dd5-54c17116f7ec","url":"http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec"},"adres":"another-user@foo.com","soortDigitaalAdres":"email","omschrijving":"OIP
string: '{"uuid":"3cc1c616-a8dc-4d23-9ce4-8a3d15871309","url":"http://localhost:8338/klantinteracties/api/v1/digitaleadressen/3cc1c616-a8dc-4d23-9ce4-8a3d15871309","verstrektDoorBetrokkene":null,"verstrektDoorPartij":{"uuid":"89424a8a-fc4e-41f2-81ed-d5cc21675c2b","url":"http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b"},"adres":"another-user@foo.com","soortDigitaalAdres":"email","omschrijving":"OIP
profiel"}'
headers:
API-version:
Expand All @@ -147,7 +147,7 @@ interactions:
Cross-Origin-Opener-Policy:
- same-origin
Location:
- http://localhost:8338/klantinteracties/api/v1/digitaleadressen/35849def-1649-4ee7-874d-a807ea0f4da4
- http://localhost:8338/klantinteracties/api/v1/digitaleadressen/3cc1c616-a8dc-4d23-9ce4-8a3d15871309
Referrer-Policy:
- same-origin
Vary:
Expand All @@ -165,12 +165,12 @@ interactions:
Authorization:
- Token b2eb1da9861da88743d72a3fb4344288fe2cba44
method: GET
uri: http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec?expand=digitaleAdressen
uri: http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b?expand=digitaleAdressen
response:
body:
string: '{"uuid":"199ab61c-d0cf-4531-9dd5-54c17116f7ec","url":"http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec","nummer":"0000000001","interneNotitie":"","betrokkenen":[],"categorieRelaties":[],"digitaleAdressen":[{"uuid":"35849def-1649-4ee7-874d-a807ea0f4da4","url":"http://localhost:8338/klantinteracties/api/v1/digitaleadressen/35849def-1649-4ee7-874d-a807ea0f4da4"}],"voorkeursDigitaalAdres":null,"vertegenwoordigden":[],"rekeningnummers":[],"voorkeursRekeningnummer":null,"partijIdentificatoren":[{"uuid":"ac00fd3b-c89e-450d-a36a-67dd632bea7e","url":"http://localhost:8338/klantinteracties/api/v1/partij-identificatoren/ac00fd3b-c89e-450d-a36a-67dd632bea7e"}],"soortPartij":"persoon","indicatieGeheimhouding":false,"voorkeurstaal":"crp","indicatieActief":true,"bezoekadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"correspondentieadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"partijIdentificatie":{"contactnaam":{"voorletters":"Dr.","voornaam":"Test
string: '{"uuid":"89424a8a-fc4e-41f2-81ed-d5cc21675c2b","url":"http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b","nummer":"0000000001","interneNotitie":"","betrokkenen":[],"categorieRelaties":[],"digitaleAdressen":[{"uuid":"3cc1c616-a8dc-4d23-9ce4-8a3d15871309","url":"http://localhost:8338/klantinteracties/api/v1/digitaleadressen/3cc1c616-a8dc-4d23-9ce4-8a3d15871309"}],"voorkeursDigitaalAdres":null,"vertegenwoordigden":[],"rekeningnummers":[],"voorkeursRekeningnummer":null,"partijIdentificatoren":[{"uuid":"350ed1a7-7551-4ed5-8fdf-cc95942d67e2","url":"http://localhost:8338/klantinteracties/api/v1/partij-identificatoren/350ed1a7-7551-4ed5-8fdf-cc95942d67e2"}],"soortPartij":"persoon","indicatieGeheimhouding":false,"voorkeurstaal":"crp","indicatieActief":true,"bezoekadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"correspondentieadres":{"nummeraanduidingId":"","adresregel1":"","adresregel2":"","adresregel3":"","land":""},"partijIdentificatie":{"contactnaam":{"voorletters":"Dr.","voornaam":"Test
Persoon","voorvoegselAchternaam":"Mrs.","achternaam":"Gamble"},"volledigeNaam":"Test
Persoon Mrs. Gamble"},"_expand":{"digitaleAdressen":[{"uuid":"35849def-1649-4ee7-874d-a807ea0f4da4","url":"http://localhost:8338/klantinteracties/api/v1/digitaleadressen/35849def-1649-4ee7-874d-a807ea0f4da4","verstrektDoorBetrokkene":null,"verstrektDoorPartij":{"uuid":"199ab61c-d0cf-4531-9dd5-54c17116f7ec","url":"http://localhost:8338/klantinteracties/api/v1/partijen/199ab61c-d0cf-4531-9dd5-54c17116f7ec"},"adres":"another-user@foo.com","soortDigitaalAdres":"email","omschrijving":"OIP
Persoon Mrs. Gamble"},"_expand":{"digitaleAdressen":[{"uuid":"3cc1c616-a8dc-4d23-9ce4-8a3d15871309","url":"http://localhost:8338/klantinteracties/api/v1/digitaleadressen/3cc1c616-a8dc-4d23-9ce4-8a3d15871309","verstrektDoorBetrokkene":null,"verstrektDoorPartij":{"uuid":"89424a8a-fc4e-41f2-81ed-d5cc21675c2b","url":"http://localhost:8338/klantinteracties/api/v1/partijen/89424a8a-fc4e-41f2-81ed-d5cc21675c2b"},"adres":"another-user@foo.com","soortDigitaalAdres":"email","omschrijving":"OIP
profiel"}]}}'
headers:
API-version:
Expand Down
Loading

0 comments on commit d4965e0

Please sign in to comment.