diff --git a/src/open_inwoner/openzaak/admin.py b/src/open_inwoner/openzaak/admin.py index bd3bcea166..5f2cdcfb87 100644 --- a/src/open_inwoner/openzaak/admin.py +++ b/src/open_inwoner/openzaak/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin, messages from django.core.exceptions import ValidationError -from django.db.models import Count +from django.db.models import BooleanField, Count, Exists, ExpressionWrapper, Q from django.forms.models import BaseInlineFormSet from django.utils.translation import gettext_lazy as _, ngettext @@ -42,6 +42,25 @@ class CatalogusConfigAdmin(admin.ModelAdmin): ordering = ("domein", "rsin") +class HasDocNotifyListFilter(admin.SimpleListFilter): + title = _("notify document attachment") + parameter_name = "doc_notify" + + def lookups(self, request, model_admin): + return [ + ("yes", _("Yes")), + ("no", _("No")), + ] + + def queryset(self, request, queryset): + v = self.value() + if v == "yes": + queryset = queryset.filter(has_doc_notify=True) + elif v == "no": + queryset = queryset.filter(has_doc_notify=False) + return queryset + + class CatalogUsedListFilter(admin.SimpleListFilter): title = _("Catalogus") parameter_name = "catalogus" @@ -129,6 +148,7 @@ class ZaakTypeConfigAdmin(admin.ModelAdmin): "omschrijving", "catalogus", "notify_status_changes", + "has_doc_notify", "document_upload_enabled", "num_infotypes", ] @@ -138,6 +158,7 @@ class ZaakTypeConfigAdmin(admin.ModelAdmin): ] list_filter = [ "notify_status_changes", + HasDocNotifyListFilter, CatalogUsedListFilter, ] search_fields = [ @@ -157,6 +178,19 @@ def has_delete_permission(self, request, obj=None): def get_queryset(self, request): qs = super().get_queryset(request) qs = qs.annotate(num_infotypes=Count("zaaktypeinformatieobjecttypeconfig")) + qs = qs.annotate( + num_doc_notify=Count( + "zaaktypeinformatieobjecttypeconfig", + filter=Q( + zaaktypeinformatieobjecttypeconfig__document_notification_enabled=True + ), + ) + ) + qs = qs.annotate( + has_doc_notify=ExpressionWrapper( + Q(num_doc_notify__gt=0), output_field=BooleanField() + ) + ) return qs def num_infotypes(self, obj=None): @@ -165,6 +199,17 @@ def num_infotypes(self, obj=None): else: return getattr(obj, "num_infotypes", 0) + num_infotypes.admin_order_field = "num_infotypes" + + def has_doc_notify(self, obj=None): + if not obj or not obj.pk: + return False + else: + return getattr(obj, "has_doc_notify", False) + + has_doc_notify.boolean = True + has_doc_notify.admin_order_field = "has_doc_notify" + @admin.action(description="Set selected Zaaktypes to notify on status changes") def mark_as_notify_status_changes(self, request, qs): count = qs.update(notify_status_changes=True) diff --git a/src/open_inwoner/openzaak/migrations/0012_zaaktypeinformatieobjecttypeconfig_document_notification_enabled.py b/src/open_inwoner/openzaak/migrations/0012_zaaktypeinformatieobjecttypeconfig_document_notification_enabled.py index 3ddaf410da..9aada59ba9 100644 --- a/src/open_inwoner/openzaak/migrations/0012_zaaktypeinformatieobjecttypeconfig_document_notification_enabled.py +++ b/src/open_inwoner/openzaak/migrations/0012_zaaktypeinformatieobjecttypeconfig_document_notification_enabled.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.15 on 2023-02-07 14:32 +# Generated by Django 3.2.15 on 2023-02-08 09:34 from django.db import migrations, models @@ -16,7 +16,7 @@ class Migration(migrations.Migration): field=models.BooleanField( default=False, help_text="When enabled the user will receive a notification when a visible document is added to the case", - verbose_name="Enable document notification", + verbose_name="Enable document notifications", ), ), ] diff --git a/src/open_inwoner/openzaak/models.py b/src/open_inwoner/openzaak/models.py index 5acad03cd9..7289e8a29d 100644 --- a/src/open_inwoner/openzaak/models.py +++ b/src/open_inwoner/openzaak/models.py @@ -248,9 +248,14 @@ class Meta: def informatieobjecttype_uuid(self): if self.informatieobjecttype_url: - s = furl(self.informatieobjecttype_url).path.segments - # handle trailing slash - return s[-1] or s[-2] or self.informatieobjecttype_url + segments = furl(self.informatieobjecttype_url).path.segments + # grab uuid as last bit of url, + # but handle trailing slash or weird urls from factories + while segments: + s = segments.pop() + if s: + return s + return self.informatieobjecttype_url return "" informatieobjecttype_uuid.short_description = _("Information object UUID") diff --git a/src/open_inwoner/openzaak/tests/test_models.py b/src/open_inwoner/openzaak/tests/test_models.py index 0110ece41d..7365e4cd11 100644 --- a/src/open_inwoner/openzaak/tests/test_models.py +++ b/src/open_inwoner/openzaak/tests/test_models.py @@ -16,13 +16,6 @@ from open_inwoner.openzaak.tests.shared import CATALOGI_ROOT -class Reminder(TestCase): - def test_admin(self): - self.fail( - "check ticket and update admin list view with a column to indicate which ZaakTypeConfig has info object types with upload" - ) - - class ZaakTypeConfigModelTestCase(TestCase): def test_queryset_filter_case_type_with_catalog(self): catalog = CatalogusConfigFactory( diff --git a/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py b/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py index 9cc285a78a..4f0283dea1 100644 --- a/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py +++ b/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py @@ -270,7 +270,7 @@ def test_zio_bails_when_zaak_type_info_object_type_config_is_found_not_marked_fo mock_handle.assert_not_called() self.assertTimelineLog( - f"ignored zaakinformatieobject notification: info_type configuration 'important documentl' {data.informatie_object['informatieobjecttype']} found but 'document_notification_enabled' is False for case https://", + f"ignored zaakinformatieobject notification: info_type configuration 'important document' {data.informatie_object['informatieobjecttype']} found but 'document_notification_enabled' is False for case https://", lookup=Lookups.startswith, level=logging.INFO, )