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

[#2966] Refactor logic for registering contactmomenten in eSuite #1552

Merged
merged 3 commits into from
Jan 22, 2025
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
71 changes: 38 additions & 33 deletions src/open_inwoner/cms/cases/tests/test_contactform.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
DigidUserFactory,
eHerkenningUserFactory,
)
from open_inwoner.openklant.constants import Status
from open_inwoner.openklant.models import ESuiteKlantConfig
from open_inwoner.openklant.constants import KlantenServiceType, Status
from open_inwoner.openklant.models import ESuiteKlantConfig, KlantenSysteemConfig
from open_inwoner.openklant.services import eSuiteVragenService
from open_inwoner.openklant.tests.data import CONTACTMOMENTEN_ROOT, KLANTEN_ROOT
from open_inwoner.openzaak.models import CatalogusConfig, OpenZaakConfig
Expand Down Expand Up @@ -82,21 +82,25 @@ def setUp(self):
)
self.oz_config.save()

# klant config
self.klant_config = ESuiteKlantConfig.get_solo()
# klant configurations
self.klant_config = KlantenSysteemConfig.get_solo()
self.klant_config.primary_backend = KlantenServiceType.ESUITE.value
self.klant_config.register_contact_via_api = True
self.klant_config.send_email_confirmation = True
self.klant_config.register_contact_moment = True
self.klant_config.register_bronorganisatie_rsin = "123456788"
self.klant_config.register_type = "Melding"
self.klant_config.register_employee_id = "FooVonBar"
self.klant_config.register_channel = "the-designated-channel"
self.klant_config.klanten_service = ServiceFactory(
self.klant_config.save()

self.esuite_config = ESuiteKlantConfig.get_solo()
self.esuite_config.register_bronorganisatie_rsin = "123456788"
self.esuite_config.register_type = "Melding"
self.esuite_config.register_employee_id = "FooVonBar"
self.esuite_config.register_channel = "the-designated-channel"
self.esuite_config.klanten_service = ServiceFactory(
api_root=KLANTEN_ROOT, api_type=APITypes.kc
)
self.klant_config.contactmomenten_service = ServiceFactory(
self.esuite_config.contactmomenten_service = ServiceFactory(
api_root=CONTACTMOMENTEN_ROOT, api_type=APITypes.cmc
)
self.klant_config.save()
self.esuite_config.save()

self.zaak = generate_oas_component_cached(
"zrc",
Expand Down Expand Up @@ -371,7 +375,7 @@ def test_form_is_shown_if_open_klant_api_configured(
self._setUpMocks(m)
self._setUpExtraMocks(m)

self.assertTrue(self.klant_config.has_api_configuration())
self.assertTrue(self.klant_config.has_api_configuration)

response = self.app.get(self.case_detail_url, user=self.user)
contact_form = response.pyquery("#contact-form")
Expand All @@ -387,12 +391,14 @@ def test_form_is_shown_if_open_klant_email_configured(
self._setUpMocks(m)
self._setUpExtraMocks(m)

self.klant_config.register_email = "example@example.com"
self.klant_config.register_contact_moment = False
self.esuite_config.klanten_service = None
self.esuite_config.save()

self.klant_config.register_contact_email = "example@example.com"
self.klant_config.save()

self.assertFalse(self.klant_config.has_api_configuration())
self.assertTrue(self.klant_config.has_register())
self.assertFalse(self.klant_config.has_api_configuration)
self.assertTrue(self.klant_config.contact_registration_enabled)

response = self.app.get(self.case_detail_url, user=self.user)
contact_form = response.pyquery("#contact-form")
Expand All @@ -411,8 +417,8 @@ def test_form_is_shown_if_open_klant_email_and_api_configured(
self.klant_config.register_email = "example@example.com"
self.klant_config.save()

self.assertTrue(self.klant_config.has_api_configuration())
self.assertTrue(self.klant_config.has_register())
self.assertTrue(self.klant_config.has_api_configuration)
self.assertTrue(self.klant_config.contact_registration_enabled)

response = self.app.get(self.case_detail_url, user=self.user)
contact_form = response.pyquery("#contact-form")
Expand All @@ -428,15 +434,14 @@ def test_no_form_shown_if_open_klant_not_configured(
self._setUpMocks(m)

# reset
self.klant_config.klanten_service = None
self.klant_config.contactmomenten_service = None
self.klant_config.register_email = ""
self.klant_config.register_contact_moment = False
self.klant_config.register_bronorganisatie_rsin = ""
self.klant_config.register_type = ""
self.klant_config.register_employee_id = ""
self.klant_config.save()
self.assertFalse(self.klant_config.has_api_configuration())
self.esuite_config.klanten_service = None
self.esuite_config.contactmomenten_service = None
self.esuite_config.register_bronorganisatie_rsin = ""
self.esuite_config.register_type = ""
self.esuite_config.register_employee_id = ""
self.esuite_config.save()

self.assertFalse(self.klant_config.has_api_configuration)

response = self.app.get(self.case_detail_url, user=self.user)
contact_form = response.pyquery("#contact-form")
Expand Down Expand Up @@ -665,8 +670,8 @@ def test_form_success_with_email(self, m, mock_contactmoment, mock_send_confirm)
self._setUpMocks(m)
self._setUpExtraMocks(m)

self.klant_config.register_email = "example@example.com"
self.klant_config.register_contact_moment = False
self.klant_config.register_contact_email = "example@example.com"
self.klant_config.register_contact_via_api = False
self.klant_config.save()

response = self.app.get(self.case_detail_url, user=self.user)
Expand Down Expand Up @@ -708,7 +713,7 @@ def test_form_success_with_both_email_and_api(
self._setUpMocks(m)
self._setUpExtraMocks(m)

self.klant_config.register_email = "example@example.com"
self.klant_config.register_contact_email = "example@example.com"
self.klant_config.save()

response = self.app.get(self.case_detail_url, user=self.user)
Expand Down Expand Up @@ -746,7 +751,7 @@ def test_send_email_confirmation_is_configurable__send_enabled(
self._setUpMocks(m)
self._setUpExtraMocks(m)

config = ESuiteKlantConfig.get_solo()
config = KlantenSysteemConfig.get_solo()
config.send_email_confirmation = True
config.save()

Expand All @@ -766,7 +771,7 @@ def test_send_email_confirmation_is_configurable__send_disabled(
self._setUpMocks(m)
self._setUpExtraMocks(m)

config = ESuiteKlantConfig.get_solo()
config = KlantenSysteemConfig.get_solo()
config.send_email_confirmation = False
config.save()

Expand Down
25 changes: 15 additions & 10 deletions src/open_inwoner/cms/cases/tests/test_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from open_inwoner.accounts.tests.factories import DigidUserFactory
from open_inwoner.cms.tests import cms_tools
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.openklant.constants import Status
from open_inwoner.openklant.models import ESuiteKlantConfig
from open_inwoner.openklant.constants import KlantenServiceType, Status
from open_inwoner.openklant.models import ESuiteKlantConfig, KlantenSysteemConfig
from open_inwoner.openklant.services import eSuiteVragenService
from open_inwoner.openklant.tests.data import CONTACTMOMENTEN_ROOT, KLANTEN_ROOT
from open_inwoner.openzaak.models import OpenZaakConfig
Expand Down Expand Up @@ -89,18 +89,23 @@ def setUp(self) -> None:
self.oz_config.save()

# klant config
self.klant_config = ESuiteKlantConfig.get_solo()
self.klant_config.register_contact_moment = True
self.klant_config.register_bronorganisatie_rsin = "123456788"
self.klant_config.register_type = "Melding"
self.klant_config.register_employee_id = "FooVonBar"
self.klant_config.klanten_service = ServiceFactory(
self.klant_config = KlantenSysteemConfig.get_solo()
self.klant_config.primary_backend = KlantenServiceType.ESUITE.value
self.klant_config.register_contact_via_api = True
self.klant_config.send_email_confirmation = True
self.klant_config.save()

self.esuite_config = ESuiteKlantConfig.get_solo()
self.esuite_config.register_bronorganisatie_rsin = "123456788"
self.esuite_config.register_type = "Melding"
self.esuite_config.register_employee_id = "FooVonBar"
self.esuite_config.klanten_service = ServiceFactory(
api_root=KLANTEN_ROOT, api_type=APITypes.kc
)
self.klant_config.contactmomenten_service = ServiceFactory(
self.esuite_config.contactmomenten_service = ServiceFactory(
api_root=CONTACTMOMENTEN_ROOT, api_type=APITypes.cmc
)
self.klant_config.save()
self.esuite_config.save()

self.zaak = generate_oas_component_cached(
"zrc",
Expand Down
35 changes: 25 additions & 10 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
from open_inwoner.accounts.models import User
from open_inwoner.mail.service import send_contact_confirmation_mail
from open_inwoner.openklant.constants import KlantenServiceType
from open_inwoner.openklant.models import ESuiteKlantConfig
from open_inwoner.openklant.models import (
ESuiteKlantConfig,
KlantenSysteemConfig,
OpenKlant2Config,
)
from open_inwoner.openklant.services import (
OpenKlant2Service,
Question,
Expand Down Expand Up @@ -513,7 +517,7 @@ def get_upload_info_context(self, case: Zaak):
if not case:
return {}

open_klant_config = ESuiteKlantConfig.get_solo()
klanten_config = KlantenSysteemConfig.get_solo()

case_type_config_description = ""
case_type_document_upload_description = ""
Expand Down Expand Up @@ -558,7 +562,7 @@ def get_upload_info_context(self, case: Zaak):
and not getattr(self.case, "einddatum", None),
"external_upload_url": external_upload_url,
"contact_form_enabled": (
contact_form_enabled and open_klant_config.has_register()
contact_form_enabled and klanten_config.contact_registration_enabled
),
}

Expand Down Expand Up @@ -909,23 +913,25 @@ def post(self, request, *args, **kwargs):
form = self.get_form()

if form.is_valid():
config = ESuiteKlantConfig.get_solo()
klant_config = KlantenSysteemConfig.get_solo()

email_success = False
api_success = False
send_confirmation = False

if config.register_email:
if klant_config.register_contact_email:
form.cleaned_data[
"question"
] += f"\n\nCase number: {self.case.identificatie}"
email_success = self.register_by_email(form, config.register_email)
email_success = self.register_by_email(
form, klant_config.register_contact_email
)
send_confirmation = email_success

if config.register_contact_moment:
api_success = self.register_by_api(form, config)
if klant_config.register_contact_via_api:
api_success = self.register_by_api(form, config=klant_config)
if api_success:
send_confirmation = config.send_email_confirmation
send_confirmation = klant_config.send_email_confirmation
# else keep the send_confirmation if email set it

if send_confirmation:
Expand Down Expand Up @@ -990,7 +996,16 @@ def register_by_email(self, form, recipient_email):
)
return False

def register_by_api(self, form, config: ESuiteKlantConfig):
def register_by_api(self, form, config: KlantenSysteemConfig):
if config.primary_backend == KlantenServiceType.ESUITE.value:
return self._register_via_esuite(form, config=ESuiteKlantConfig.get_solo())
return self._register_via_openklant2(form, config=OpenKlant2Config.get_solo())

# TODO
def _register_via_openklant2(self, form, config: OpenKlant2Config):
raise NotImplementedError

def _register_via_esuite(self, form, config: ESuiteKlantConfig):
assert config.has_api_configuration()

try:
Expand Down
6 changes: 3 additions & 3 deletions src/open_inwoner/cms/footer/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from cms.plugin_pool import plugin_pool

from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.openklant.models import ESuiteKlantConfig
from open_inwoner.openklant.models import KlantenSysteemConfig


@plugin_pool.register_plugin
Expand All @@ -17,7 +17,7 @@ class FooterPagesPlugin(CMSPluginBase):
def render(self, context, instance, placeholder):
# TODO move options to plugin model
config = SiteConfiguration.get_solo()
ok_config = ESuiteKlantConfig.get_solo()
klant_config = KlantenSysteemConfig.get_solo()
context["flatpages"] = config.get_ordered_flatpages
context["has_form_configuration"] = ok_config.has_form_configuration()
context["has_form_configuration"] = klant_config.has_contactform_configuration
return context
43 changes: 23 additions & 20 deletions src/open_inwoner/cms/footer/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,48 @@

from open_inwoner.cms.footer.cms_plugins import FooterPagesPlugin
from open_inwoner.cms.tests import cms_tools
from open_inwoner.openklant.models import ESuiteKlantConfig
from open_inwoner.openklant.constants import KlantenServiceType
from open_inwoner.openklant.models import ESuiteKlantConfig, KlantenSysteemConfig
from open_inwoner.openklant.tests.factories import ContactFormSubjectFactory
from open_inwoner.utils.test import ClearCachesMixin


class ContactFormTestCase(ClearCachesMixin, TestCase):
def setUp(self):
super().setUp()
# clear config
config = ESuiteKlantConfig.get_solo()
config.klanten_service = None
config.contactmomenten_service = None
config.register_email = ""
config.register_contact_moment = False
config.register_bronorganisatie_rsin = ""
config.register_type = ""
config.register_employee_id = ""
config.send_email_confirmation = True
config.save()
# clear esuite_config
esuite_config = ESuiteKlantConfig.get_solo()
esuite_config.klanten_service = None
esuite_config.contactmomenten_service = None
esuite_config.register_bronorganisatie_rsin = ""
esuite_config.register_type = ""
esuite_config.register_employee_id = ""
esuite_config.send_email_confirmation = True
esuite_config.save()

def test_no_form_link_shown_in_footer_if_not_has_configuration(self):
# set nothing
config = ESuiteKlantConfig.get_solo()
self.assertFalse(config.has_form_configuration())
klant_config = KlantenSysteemConfig.get_solo()
self.assertFalse(klant_config.has_contactform_configuration)

html, context = cms_tools.render_plugin(FooterPagesPlugin)

self.assertNotIn(_("Contact formulier"), html)

def test_form_link_is_shown_in_footer_when_has_configuration(self):
ok_config = ESuiteKlantConfig.get_solo()
self.assertFalse(ok_config.has_form_configuration())
klant_config = KlantenSysteemConfig.get_solo()
klant_config.primary_backend = KlantenServiceType.ESUITE.value
klant_config.save()

ContactFormSubjectFactory(config=ok_config)
self.assertFalse(klant_config.has_contactform_configuration)

ok_config.register_email = "example@example.com"
ok_config.save()
esuite_config = ESuiteKlantConfig.get_solo()
ContactFormSubjectFactory(config=esuite_config)

self.assertTrue(ok_config.has_form_configuration())
klant_config.register_contact_email = "example@example.com"
klant_config.save()

self.assertTrue(klant_config.has_contactform_configuration)

html, context = cms_tools.render_plugin(FooterPagesPlugin)

Expand Down
Loading
Loading