Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1859] Replace e-suite subject with OIP subject in contactmomenten #945

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/open_inwoner/accounts/views/contactmoments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from datetime import datetime
from typing import List, TypedDict

Expand All @@ -13,14 +14,16 @@

from open_inwoner.openklant.api_models import KlantContactMoment
from open_inwoner.openklant.constants import Status
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.models import ContactFormSubject, OpenKlantConfig
from open_inwoner.openklant.wrap import (
fetch_klantcontactmoment,
fetch_klantcontactmomenten,
get_fetch_parameters,
)
from open_inwoner.utils.views import CommonPageMixin

logger = logging.getLogger(__name__)


class KlantContactMomentAccessMixin(AccessMixin):
"""
Expand Down Expand Up @@ -77,10 +80,33 @@ def get_kcm_data(self, kcm: KlantContactMoment) -> KCMDict:
# eSuite extra
"identificatie": kcm.contactmoment.identificatie,
"type": kcm.contactmoment.type,
"onderwerp": kcm.contactmoment.onderwerp,
"status": Status.safe_label(kcm.contactmoment.status, _("Onbekend")),
"antwoord": kcm.contactmoment.antwoord,
}

# replace e_suite_subject_code with OIP configured subject, if applicable
e_suite_subject_code = getattr(kcm.contactmoment, "onderwerp", None)

if not e_suite_subject_code:
data["onderwerp"] = None
else:
try:
subject = ContactFormSubject.objects.get(
subject_code=e_suite_subject_code
)
except (
ContactFormSubject.DoesNotExist,
ContactFormSubject.MultipleObjectsReturned,
) as e:
logger.warning(
"Could not determine subject ('onderwerp') for contactmoment %s (%s)",
kcm.contactmoment.url,
e,
)
data["onderwerp"] = None
else:
data["onderwerp"] = subject.subject

return data

def get_context_data(self, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/openklant/tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def __init__(self):
kanaal="MAIL",
status=Status.afgehandeld,
antwoord="",
onderwerp="e_suite_subject_code",
)
self.contactmoment2 = generate_oas_component(
"cmc",
Expand All @@ -146,6 +147,7 @@ def __init__(self):
kanaal="MAIL",
status=Status.afgehandeld,
antwoord="",
onderwerp="e_suite_subject_code",
)
self.klant_contactmoment = generate_oas_component(
"cmc",
Expand Down
17 changes: 12 additions & 5 deletions src/open_inwoner/openklant/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django_webtest import WebTest

from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.models import ContactFormSubject, OpenKlantConfig
from open_inwoner.openklant.tests.data import MockAPIReadData
from open_inwoner.utils.test import ClearCachesMixin, DisableRequestLogMixin

Expand All @@ -27,6 +27,13 @@ def setUpTestData(cls):
super().setUpTestData()
MockAPIReadData.setUpServices()

# for testing replacement of e-suite "onderwerp" code with OIP configured subject
cls.contactformsubject = ContactFormSubject.objects.create(
subject="oip_subject",
subject_code="e_suite_subject_code",
config=OpenKlantConfig.get_solo(),
)

def test_list_for_bsn(self, m):
data = MockAPIReadData().install_mocks(m)

Expand All @@ -48,7 +55,7 @@ def test_list_for_bsn(self, m):
),
"channel": data.contactmoment["kanaal"].title(),
"text": data.contactmoment["tekst"],
"onderwerp": data.contactmoment["onderwerp"],
"onderwerp": self.contactformsubject.subject,
"antwoord": data.contactmoment["antwoord"],
"identificatie": data.contactmoment["identificatie"],
"type": data.contactmoment["type"],
Expand Down Expand Up @@ -88,7 +95,7 @@ def test_list_for_kvk_or_rsin(self, m):
),
"channel": data.contactmoment2["kanaal"].title(),
"text": data.contactmoment2["tekst"],
"onderwerp": data.contactmoment2["onderwerp"],
"onderwerp": self.contactformsubject.subject,
"antwoord": data.contactmoment2["antwoord"],
"identificatie": data.contactmoment2["identificatie"],
"type": data.contactmoment2["type"],
Expand All @@ -115,7 +122,7 @@ def test_show_detail_for_bsn(self, m):
),
"channel": data.contactmoment["kanaal"].title(),
"text": data.contactmoment["tekst"],
"onderwerp": data.contactmoment["onderwerp"],
"onderwerp": self.contactformsubject.subject,
"antwoord": data.contactmoment["antwoord"],
"identificatie": data.contactmoment["identificatie"],
"type": data.contactmoment["type"],
Expand Down Expand Up @@ -152,7 +159,7 @@ def test_show_detail_for_kvk_or_rsin(self, m):
),
"channel": data.contactmoment2["kanaal"].title(),
"text": data.contactmoment2["tekst"],
"onderwerp": data.contactmoment2["onderwerp"],
"onderwerp": self.contactformsubject.subject,
"antwoord": data.contactmoment2["antwoord"],
"identificatie": data.contactmoment2["identificatie"],
"type": data.contactmoment2["type"],
Expand Down
Loading