Skip to content

Commit

Permalink
[#2940] Add OpenKlant2 configuration model
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Schilling committed Dec 17, 2024
1 parent 1645f79 commit 4fab1ef
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 67 deletions.
102 changes: 101 additions & 1 deletion src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import requests_mock
from django_webtest import WebTest
from pyquery import PyQuery as PQ
from simple_certmanager.constants import CertificateTypes
from simple_certmanager.models import Certificate
from webtest import Upload
from zgw_consumers.constants import APITypes
from zgw_consumers.models import Service

from open_inwoner.accounts.choices import NotificationChannelChoice, StatusChoices
from open_inwoner.accounts.signals import update_user_from_klant_on_login
Expand All @@ -22,7 +26,7 @@
from open_inwoner.haalcentraal.tests.mixins import HaalCentraalMixin
from open_inwoner.laposta.models import LapostaConfig
from open_inwoner.laposta.tests.factories import LapostaListFactory, MemberFactory
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.models import OpenKlant2Config, OpenKlantConfig
from open_inwoner.pdc.tests.factories import CategoryFactory
from open_inwoner.plans.tests.factories import PlanFactory
from open_inwoner.qmatic.tests.data import QmaticMockData
Expand Down Expand Up @@ -62,6 +66,8 @@
)
class ProfileViewTests(WebTest):
def setUp(self):
signals.user_logged_in.disconnect(update_user_from_klant_on_login)

self.url = reverse("profile:detail")
self.return_url = reverse("logout")
self.user = UserFactory(
Expand All @@ -84,6 +90,36 @@ def setUp(self):
)
cms_tools.create_apphook_page(ProfileApphook)

server_certificate, _ = Certificate.objects.get_or_create(
label="test-server-cert",
defaults={
"type": CertificateTypes.cert_only,
},
)
zgw_service, _ = Service.objects.update_or_create(
api_root="http://localhost:8338/klantinteracties/api/v1",
defaults={
"label": "Klanten API service",
"slug": "klanten-api-service",
"api_type": APITypes.kc,
"oas": "",
"auth_type": "",
"client_id": "",
"secret": "",
"user_id": "",
"user_representation": "",
"server_certificate": server_certificate,
},
)
self.openklant2_config = OpenKlant2Config.objects.create(
zgw_service=zgw_service,
mijn_vragen_kanaal="oip_mijn_vragen",
mijn_vragen_organisatie_naam="Open Inwoner Platform",
mijn_vragen_actor="ca0783a1-1d74-4e07-b3e0-185b1d2fccd4",
interne_taak_gevraagde_handeling="Beantwoorden vraag Mijn Omgeving",
interne_taak_toelichting="Beantwoorden vraag",
)

def test_login_required(self):
login_url = reverse("login")
response = self.app.get(self.url)
Expand Down Expand Up @@ -750,8 +786,40 @@ class ProfileDeleteTest(WebTest):

@classmethod
def setUpTestData(cls):
signals.user_logged_in.disconnect(update_user_from_klant_on_login)

cls.url = reverse("profile:detail")

server_certificate, _ = Certificate.objects.get_or_create(
label="test-server-cert",
defaults={
"type": CertificateTypes.cert_only,
},
)
zgw_service, _ = Service.objects.update_or_create(
api_root="http://localhost:8338/klantinteracties/api/v1",
defaults={
"label": "Klanten API service",
"slug": "klanten-api-service",
"api_type": APITypes.kc,
"oas": "",
"auth_type": "",
"client_id": "",
"secret": "",
"user_id": "",
"user_representation": "",
"server_certificate": server_certificate,
},
)
cls.openklant2_config = OpenKlant2Config.objects.create(
zgw_service=zgw_service,
mijn_vragen_kanaal="oip_mijn_vragen",
mijn_vragen_organisatie_naam="Open Inwoner Platform",
mijn_vragen_actor="ca0783a1-1d74-4e07-b3e0-185b1d2fccd4",
interne_taak_gevraagde_handeling="Beantwoorden vraag Mijn Omgeving",
interne_taak_toelichting="Beantwoorden vraag",
)

def test_delete_regular_user_success(self):
user = UserFactory()

Expand Down Expand Up @@ -986,6 +1054,38 @@ def test_preselected_values(self):
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
@patch("open_inwoner.cms.utils.page_display._is_published", return_value=True)
class EditNotificationsTests(AssertTimelineLogMixin, WebTest):
@classmethod
def setUpTestData(cls):
server_certificate, _ = Certificate.objects.get_or_create(
label="test-server-cert",
defaults={
"type": CertificateTypes.cert_only,
},
)
zgw_service, _ = Service.objects.update_or_create(
api_root="http://localhost:8338/klantinteracties/api/v1",
defaults={
"label": "Klanten API service",
"slug": "klanten-api-service",
"api_type": APITypes.kc,
"oas": "",
"auth_type": "",
"client_id": "",
"secret": "",
"user_id": "",
"user_representation": "",
"server_certificate": server_certificate,
},
)
cls.openklant2_config = OpenKlant2Config.objects.create(
zgw_service=zgw_service,
mijn_vragen_kanaal="oip_mijn_vragen",
mijn_vragen_organisatie_naam="Open Inwoner Platform",
mijn_vragen_actor="ca0783a1-1d74-4e07-b3e0-185b1d2fccd4",
interne_taak_gevraagde_handeling="Beantwoorden vraag Mijn Omgeving",
interne_taak_toelichting="Beantwoorden vraag",
)

def setUp(self):
self.config = SiteConfiguration.get_solo()
self.config.notifications_messages_enabled = True
Expand Down
5 changes: 1 addition & 4 deletions src/open_inwoner/accounts/views/signals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

Expand All @@ -23,9 +22,7 @@ def get_or_create_klant_for_new_user(
user = instance

# OpenKlant2
# TODO: replace with proper config and refactor branching
use_ok2 = getattr(settings, "OPENKLANT2_CONFIG", None)
if use_ok2 and (openklant2_config := OpenKlant2Config.from_django_settings()):
if openklant2_config := OpenKlant2Config.get_solo():
try:
service = OpenKlant2Service(config=openklant2_config)
except RuntimeError:
Expand Down
39 changes: 38 additions & 1 deletion src/open_inwoner/cms/cases/tests/test_contactform.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
from unittest.mock import ANY, patch

from django.conf import settings
from django.contrib.auth.signals import user_logged_in
from django.core import mail
from django.test import override_settings
from django.urls import reverse
from django.utils.translation import gettext as _

import requests_mock
from django_webtest import WebTest
from simple_certmanager.constants import CertificateTypes
from simple_certmanager.models import Certificate
from zgw_consumers.api_models.constants import (
RolOmschrijving,
RolTypes,
VertrouwelijkheidsAanduidingen,
)
from zgw_consumers.constants import APITypes
from zgw_consumers.models import Service

from open_inwoner.accounts.signals import update_user_from_klant_on_login
from open_inwoner.accounts.tests.factories import (
DigidUserFactory,
eHerkenningUserFactory,
)
from open_inwoner.openklant.constants import Status
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.models import OpenKlant2Config, OpenKlantConfig
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 @@ -62,6 +67,38 @@ class CasesContactFormTestCase(AssertMockMatchersMixin, ClearCachesMixin, WebTes
def setUp(self):
super().setUp()

user_logged_in.disconnect(update_user_from_klant_on_login)

server_certificate, _ = Certificate.objects.get_or_create(
label="test-server-cert",
defaults={
"type": CertificateTypes.cert_only,
},
)
zgw_service, _ = Service.objects.update_or_create(
api_root="http://localhost:8338/klantinteracties/api/v1",
defaults={
"label": "Klanten API service",
"slug": "klanten-api-service",
"api_type": APITypes.kc,
"oas": "",
"auth_type": "",
"client_id": "",
"secret": "",
"user_id": "",
"user_representation": "",
"server_certificate": server_certificate,
},
)
self.openklant2_config = OpenKlant2Config.objects.create(
zgw_service=zgw_service,
mijn_vragen_kanaal="oip_mijn_vragen",
mijn_vragen_organisatie_naam="Open Inwoner Platform",
mijn_vragen_actor="ca0783a1-1d74-4e07-b3e0-185b1d2fccd4",
interne_taak_gevraagde_handeling="Beantwoorden vraag Mijn Omgeving",
interne_taak_toelichting="Beantwoorden vraag",
)

self.user = DigidUserFactory(bsn="900222086")

# services
Expand Down
70 changes: 70 additions & 0 deletions src/open_inwoner/openklant/migrations/0015_openklant2config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Generated by Django 4.2.16 on 2024-12-16 15:09

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("zgw_consumers", "0022_set_default_service_slug"),
("openklant", "0014_contactformconfig"),
]

operations = [
migrations.CreateModel(
name="OpenKlant2Config",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"mijn_vragen_kanaal",
models.CharField(blank=True, verbose_name="Mijn vragen kanaal"),
),
(
"mijn_vragen_organisatie_naam",
models.CharField(
blank=True, verbose_name="Mijn vragen organisatie naam"
),
),
(
"mijn_vragen_actor",
models.CharField(blank=True, verbose_name="Mijn vragen actor"),
),
(
"interne_taak_gevraagde_handeling",
models.CharField(
blank=True, verbose_name="Interne taak gevraagde handeling"
),
),
(
"interne_taak_toelichting",
models.CharField(
blank=True, verbose_name="Interne taak toelichting"
),
),
(
"service_config",
models.OneToOneField(
blank=True,
limit_choices_to={"api_type": "kc"},
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="zgw_consumers.service",
verbose_name="Klanten API",
),
),
],
options={
"verbose_name": "Open Klant configuration",
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 4.2.16 on 2024-12-17 07:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("openklant", "0015_openklant2config"),
]

operations = [
migrations.RenameField(
model_name="openklant2config",
old_name="service_config",
new_name="zgw_service",
),
migrations.AlterField(
model_name="openklant2config",
name="interne_taak_gevraagde_handeling",
field=models.CharField(
blank=True, default="", verbose_name="Interne taak gevraagde handeling"
),
),
migrations.AlterField(
model_name="openklant2config",
name="interne_taak_toelichting",
field=models.CharField(
blank=True, default="", verbose_name="Interne taak toelichting"
),
),
migrations.AlterField(
model_name="openklant2config",
name="mijn_vragen_actor",
field=models.CharField(
blank=True, default="", verbose_name="Mijn vragen actor"
),
),
migrations.AlterField(
model_name="openklant2config",
name="mijn_vragen_kanaal",
field=models.CharField(
blank=True, default="", verbose_name="Mijn vragen kanaal"
),
),
migrations.AlterField(
model_name="openklant2config",
name="mijn_vragen_organisatie_naam",
field=models.CharField(
blank=True, default="", verbose_name="Mijn vragen organisatie naam"
),
),
]
Loading

0 comments on commit 4fab1ef

Please sign in to comment.