Skip to content

Commit

Permalink
[#2966] Refactor logic for registering contactmomenten via general co…
Browse files Browse the repository at this point in the history
…ntactform
  • Loading branch information
Paul Schilling committed Jan 16, 2025
1 parent 0fb6313 commit 58976f2
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 144 deletions.
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
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
1 change: 1 addition & 0 deletions src/open_inwoner/openklant/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, user, request_session, *args, **kwargs):
self.user = user
self.request_session = request_session

# TODO: check for primary_backend? What in case of OK2?
config = ESuiteKlantConfig.get_solo()
self.fields["subject"].queryset = config.contactformsubject_set.all()

Expand Down
17 changes: 13 additions & 4 deletions src/open_inwoner/openklant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ class ESuiteKlantConfig(SingletonModel):
class Meta:
verbose_name = _("eSuite Klant configuration")

def has_form_configuration(self) -> bool:
return self.has_api_configuration() and self.contactformsubject_set.exists()

def has_api_configuration(self):
return all(getattr(self, f, "") for f in self.register_api_required_fields)

Expand Down Expand Up @@ -279,8 +276,20 @@ def has_api_configuration(self):
return esuite_config.has_api_configuration()

# TODO: support `has_api_configuration` check for OK2?
return True
return False

@property
def contact_registration_enabled(self) -> bool:
return self.register_contact_email or self.has_api_configuration

@property
def has_contactform_configuration(self):
if not self.contact_registration_enabled:
return False

if self.primary_backend == KlantenServiceType.ESUITE.value:
esuite_config = ESuiteKlantConfig.get_solo()
return esuite_config.contactformsubject_set.exists()

# TODO: check conditions for OK2
return False
Loading

0 comments on commit 58976f2

Please sign in to comment.