diff --git a/src/open_inwoner/openklant/admin.py b/src/open_inwoner/openklant/admin.py index bca5941f29..9f156cfb30 100644 --- a/src/open_inwoner/openklant/admin.py +++ b/src/open_inwoner/openklant/admin.py @@ -5,7 +5,13 @@ from ordered_model.admin import OrderedInlineModelAdminMixin, OrderedTabularInline from solo.admin import SingletonModelAdmin -from .models import ContactFormSubject, KlantContactMomentAnswer, OpenKlantConfig +from .models import ( + ContactFormSubject, + KlantContactMomentAnswer, + KlantenInteractiesConfig, + OpenKlant2Config, + OpenKlantConfig, +) class ContactFormSubjectForm(forms.ModelForm): @@ -108,3 +114,50 @@ class KlantContactMomentAnswerAdmin(admin.ModelAdmin): ] list_filter = ["is_seen"] list_display = ["user", "contactmoment_url", "is_seen"] + + +# +# OpenKlant2 +# + + +class OpenKlant2ConfigAdminForm(forms.ModelForm): + class Meta: + model = OpenKlantConfig + fields = "__all__" + + +@admin.register(OpenKlant2Config) +class OpenKlant2Config2Admin(admin.ModelAdmin): + model = OpenKlant2Config + form = OpenKlant2ConfigAdminForm + fieldsets = [ + ( + _("API configuration"), + { + "fields": [ + "service", + ] + }, + ), + ( + _("Vragen"), + { + "fields": [ + "mijn_vragen_kanaal", + "mijn_vragen_organisatie_naam", + "mijn_vragen_actor", + "interne_taak_gevraagde_handeling", + "interne_taak_toelichting", + ] + }, + ), + ] + + +@admin.register(KlantenInteractiesConfig) +class KlantenInteractiesConfigAdmin(SingletonModelAdmin): + change_form_template = "admin/openklant/klanteninteractiesconfig/change_form.html" + + class Meta: + model = KlantenInteractiesConfig diff --git a/src/open_inwoner/openklant/migrations/0016_klanteninteractiesconfig.py b/src/open_inwoner/openklant/migrations/0016_klanteninteractiesconfig.py new file mode 100644 index 0000000000..c408601b9e --- /dev/null +++ b/src/open_inwoner/openklant/migrations/0016_klanteninteractiesconfig.py @@ -0,0 +1,38 @@ +# Generated by Django 4.2.16 on 2025-01-07 11:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("openklant", "0015_openklant2config"), + ] + + operations = [ + migrations.CreateModel( + name="KlantenInteractiesConfig", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "primary_backend", + models.CharField( + choices=[("esuite", "ESUITE"), ("openklant2", "OPENKLANT2")], + max_length=10, + help_text="Choose the primary backend for retrieving klanten data. Changes to klanten data will be saved to both backends (if configured).", + ), + ), + ], + options={ + "verbose_name": "Configuratie Klanten Interacties", + }, + ), + ] diff --git a/src/open_inwoner/openklant/models.py b/src/open_inwoner/openklant/models.py index 2f20e55502..1849b2c08a 100644 --- a/src/open_inwoner/openklant/models.py +++ b/src/open_inwoner/openklant/models.py @@ -8,6 +8,8 @@ from open_inwoner.utils.validators import validate_array_contents_non_empty +from .constants import KlantenServiceType + class OpenKlantConfigManager(models.Manager): def get_queryset(self): @@ -17,7 +19,7 @@ def get_queryset(self): class OpenKlantConfig(SingletonModel): """ - Global configuration and defaults for Klant & Contactmomenten APIs + Configuration and defaults for eSuite Klant & Contactmomenten APIs """ klanten_service = models.OneToOneField( @@ -132,51 +134,6 @@ def has_api_configuration(self): return all(getattr(self, f, "") for f in self.register_api_required_fields) -class OpenKlant2ConfigManager(models.Manager): - def get_queryset(self): - qs = super().get_queryset() - return qs.select_related("service") - - -class OpenKlant2Config(models.Model): - service = models.OneToOneField( - "zgw_consumers.Service", - verbose_name=_("Klanten API"), - on_delete=models.PROTECT, - related_name="+", - ) - - # Vragen - mijn_vragen_kanaal = models.CharField( - verbose_name=_("Mijn vragen kanaal"), - default="", - blank=True, - ) - mijn_vragen_organisatie_naam = models.CharField( - verbose_name=_("Mijn vragen organisatie naam"), - default="", - blank=True, - ) - mijn_vragen_actor = models.CharField( - verbose_name=_("Mijn vragen actor"), - default="", - blank=True, - ) - interne_taak_gevraagde_handeling = models.CharField( - verbose_name=_("Interne taak gevraagde handeling"), - default="", - blank=True, - ) - interne_taak_toelichting = models.CharField( - verbose_name=_("Interne taak toelichting"), - default="", - blank=True, - ) - - class Meta: - verbose_name = _("OpenKlant2 configuration") - - class ContactFormSubject(OrderedModel): subject = models.CharField( verbose_name=_("Onderwerp"), @@ -187,9 +144,8 @@ class ContactFormSubject(OrderedModel): max_length=255, blank=True, ) - # FK for easy inline admins config = models.ForeignKey( - OpenKlantConfig, + "OpenKlantConfig", on_delete=models.CASCADE, ) @@ -229,3 +185,62 @@ class Meta: verbose_name = _("KlantContactMoment") verbose_name_plural = _("KlantContactMomenten") unique_together = [["user", "contactmoment_url"]] + + +class OpenKlant2ConfigManager(models.Manager): + def get_queryset(self): + qs = super().get_queryset() + return qs.select_related("service") + + +class OpenKlant2Config(models.Model): + service = models.OneToOneField( + "zgw_consumers.Service", + verbose_name=_("Klanten API"), + on_delete=models.PROTECT, + related_name="+", + ) + + # Vragen + mijn_vragen_kanaal = models.CharField( + verbose_name=_("Mijn vragen kanaal"), + default="", + blank=True, + ) + mijn_vragen_organisatie_naam = models.CharField( + verbose_name=_("Mijn vragen organisatie naam"), + default="", + blank=True, + ) + mijn_vragen_actor = models.CharField( + verbose_name=_("Mijn vragen actor"), + default="", + blank=True, + ) + interne_taak_gevraagde_handeling = models.CharField( + verbose_name=_("Interne taak gevraagde handeling"), + default="", + blank=True, + ) + interne_taak_toelichting = models.CharField( + verbose_name=_("Interne taak toelichting"), + default="", + blank=True, + ) + + class Meta: + verbose_name = _("OpenKlant2 configuration") + + +class KlantenInteractiesConfig(SingletonModel): + primary_backend = models.CharField( + max_length=10, + choices=[(service.value, service.name) for service in KlantenServiceType], + help_text=_( + "Choose the primary backend for retrieving klanten data. " + "Changes to klanten data will be saved to both backends (if configured)." + ), + ) + + class Meta: + verbose_name = _("Configuratie Klanten Interacties") diff --git a/src/open_inwoner/templates/admin/openklant/klanteninteractiesconfig/change_form.html b/src/open_inwoner/templates/admin/openklant/klanteninteractiesconfig/change_form.html new file mode 100644 index 0000000000..4c6d8f049b --- /dev/null +++ b/src/open_inwoner/templates/admin/openklant/klanteninteractiesconfig/change_form.html @@ -0,0 +1,10 @@ +{% extends "admin/solo/change_form.html" %} + +{% block content %} +
Configure the backends for retrieving Klanten data:
+ + {{ block.super }} +{% endblock content %}