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

Make case title description explicitly configurable from the source ZGW fields #1573

Merged
merged 1 commit into from
Jan 23, 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
2 changes: 1 addition & 1 deletion src/open_inwoner/configurations/bootstrap/zgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Meta:
"skip_notification_statustype_informeren",
"reformat_esuite_zaak_identificatie",
"fetch_eherkenning_zaken_with_rsin",
"use_zaak_omschrijving_as_title",
"derive_zaak_titel_from",
"order_statuses_by_date_set",
"title_text",
"enable_categories_filtering_with_zaken",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ openzaak_config:
skip_notification_statustype_informeren: false
reformat_esuite_zaak_identificatie: true
fetch_eherkenning_zaken_with_rsin: false
use_zaak_omschrijving_as_title: 'true'
derive_zaak_titel_from: zaaktype_omschrijving
order_statuses_by_date_set: false
title_text: title text from setup configuration
enable_categories_filtering_with_zaken: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ openzaak_config:
skip_notification_statustype_informeren: false
reformat_esuite_zaak_identificatie: true
fetch_eherkenning_zaken_with_rsin: false
use_zaak_omschrijving_as_title: 'true'
derive_zaak_titel_from: zaaktype_omschrijving
order_statuses_by_date_set: false
title_text: title text from setup configuration
enable_categories_filtering_with_zaken: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ openzaak_config:
skip_notification_statustype_informeren: false
reformat_esuite_zaak_identificatie: true
fetch_eherkenning_zaken_with_rsin: false
use_zaak_omschrijving_as_title: 'true'
derive_zaak_titel_from: zaaktype_omschrijving
order_statuses_by_date_set: false
title_text: title text from setup configuration
enable_categories_filtering_with_zaken: true
Expand All @@ -16,5 +16,5 @@ openzaak_config:
- .pdf
- .txt
# Empty api_groups should not raise a missing exception, but should raise a
#
#
api_groups: []
18 changes: 11 additions & 7 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class OpenZaakConfigAdmin(SingletonModelAdmin):
"fields": (
"enable_categories_filtering_with_zaken",
"zaken_filter_enabled",
"use_zaak_omschrijving_as_title",
"order_statuses_by_date_set",
),
},
Expand All @@ -78,6 +77,7 @@ class OpenZaakConfigAdmin(SingletonModelAdmin):
"skip_notification_statustype_informeren",
"reformat_esuite_zaak_identificatie",
"fetch_eherkenning_zaken_with_rsin",
"derive_zaak_titel_from",
],
},
),
Expand Down Expand Up @@ -177,9 +177,11 @@ def process_file_view(self, request):
"error_rows": len(import_result.import_errors),
}
),
messages.SUCCESS
if not import_result.import_errors
else messages.WARNING,
(
messages.SUCCESS
if not import_result.import_errors
else messages.WARNING
),
)
if errors := import_result.import_errors:
msgs_deduped = set(error.__str__() for error in errors)
Expand Down Expand Up @@ -485,9 +487,11 @@ def process_file_view(self, request):
"error_rows": len(import_result.import_errors),
}
),
messages.SUCCESS
if not import_result.import_errors
else messages.WARNING,
(
messages.SUCCESS
if not import_result.import_errors
else messages.WARNING
),
)
if errors := import_result.import_errors:
msgs_deduped = set(error.__str__() for error in errors)
Expand Down
21 changes: 18 additions & 3 deletions src/open_inwoner/openzaak/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from open_inwoner.utils.glom import glom_multiple

from .constants import ZaakTitleDisplayChoices

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -105,9 +107,22 @@ def description(self) -> str:

zaak_config = OpenZaakConfig.get_solo()

description = self.zaaktype.omschrijving
if zaak_config.use_zaak_omschrijving_as_title and self.omschrijving:
description = self.omschrijving
description = ""
match zaak_config.derive_zaak_titel_from:
case ZaakTitleDisplayChoices.zaak_omschrijving:
description = self.omschrijving
case ZaakTitleDisplayChoices.zaaktype_omschrijving:
description = self.zaaktype.omschrijving
case ZaakTitleDisplayChoices.zaaktype_onderwerp:
description = self.zaaktype.onderwerp
case _:
raise ValueError(
"Invalid choice `{zaak_config.derive_zaak_titel_from}` for "
" `OpenZaakConfig.derive_zaak_titel_from`"
)

if not description:
logger.error("No valid description found for zaak: %s", self.identificatie)

return description

Expand Down
12 changes: 12 additions & 0 deletions src/open_inwoner/openzaak/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ class StatusIndicators(models.TextChoices):
warning = "warning", _("Warning")
failure = "failure", _("Failure")
success = "success", _("Success")


class ZaakTitleDisplayChoices(models.TextChoices):
zaak_omschrijving = "zaak_omschrijving", _(
"The description of the case (`zaak.omschrijving`)"
)
zaaktype_omschrijving = "zaaktype_omschrijving", _(
"The description of the case's type (`zaaktype.omschrijving`)"
)
zaaktype_onderwerp = "zaaktype_onderwerp", _(
"The subject of the case's type (`zaaktype.onderwerp`)"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Generated by Django 4.2.18 on 2025-01-22 12:06
import logging

from django.db import migrations, models

logger = logging.getLogger(__name__)


def migrate_use_zaak_omschrijving_as_title(apps, _):
from open_inwoner.openzaak.constants import ZaakTitleDisplayChoices

OpenZaakConfig = apps.get_model("openzaak", "OpenZaakConfig")

if config := OpenZaakConfig.objects.first():
if config.use_zaak_omschrijving_as_title:
logger.info(
"Setting OpenZaakConfig.derive_zaak_titel_from to %s because "
"OpenZaakConfig.use_zaak_omschrijving_as_title = True",
ZaakTitleDisplayChoices.zaak_omschrijving,
)
config.derive_zaak_titel_from = ZaakTitleDisplayChoices.zaak_omschrijving
else:
logger.info(
"Setting OpenZaakConfig.derive_zaak_titel_from to %s because "
"OpenZaakConfig.use_zaak_omschrijving_as_title = False",
ZaakTitleDisplayChoices.zaaktype_omschrijving,
)
config.derive_zaak_titel_from = (
ZaakTitleDisplayChoices.zaaktype_omschrijving
)

config.save()

# ZaakTitleDisplayChoices.zaaktype_omschrijving is a newly added option, so it won't
# be the default for anybody.


def reverse_migrate_use_zaak_omschrijving_as_title(apps, _):
from open_inwoner.openzaak.constants import ZaakTitleDisplayChoices

OpenZaakConfig = apps.get_model("openzaak", "OpenZaakConfig")

if config := OpenZaakConfig.objects.first():
if config.derive_zaak_titel_from == ZaakTitleDisplayChoices.zaak_omschrijving:
config.use_zaak_omschrijving_as_title = True
else:
config.use_zaak_omschrijving_as_title = False

config.save()


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0059_openzaakconfig_show_cases_without_status"),
]

operations = [
migrations.AddField(
model_name="openzaakconfig",
name="derive_zaak_titel_from",
field=models.CharField(
choices=[
(
"zaak_omschrijving",
"The description of the case (`zaak.omschrijving`)",
),
(
"zaaktype_omschrijving",
"The description of the case's type (`zaaktype.omschrijving`)",
),
(
"zaaktype_onderwerp",
"The subject of the case's type (`zaaktype.onderwerp`)",
),
],
default="zaaktype_omschrijving",
help_text="Which field from the underlying zaaksysteem to use to display the title for a zaak (e.g. on the Mijn Aanvragen page).",
verbose_name="Derive the case title from",
),
),
migrations.RunPython(
code=migrate_use_zaak_omschrijving_as_title,
reverse_code=reverse_migrate_use_zaak_omschrijving_as_title,
),
migrations.RemoveField(
model_name="openzaakconfig",
name="use_zaak_omschrijving_as_title",
),
]
18 changes: 7 additions & 11 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ZaakTypeStatusTypeConfigQuerySet,
)

from .constants import StatusIndicators
from .constants import StatusIndicators, ZaakTitleDisplayChoices

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -411,18 +411,14 @@ def form_service(self, service):
),
default=False,
)

use_zaak_omschrijving_as_title = models.BooleanField(
verbose_name=_(
"Make use of zaak.omschrijving for the title of the cases instead of "
"zaaktype.omschrijving (eSuite)"
),
derive_zaak_titel_from = models.CharField(
choices=ZaakTitleDisplayChoices.choices,
default=ZaakTitleDisplayChoices.zaaktype_omschrijving,
verbose_name=_("Derive the case title from"),
help_text=_(
"If enabled, we use zaak.omschrijving for the title of the cases, and use "
"zaaktype.omschrijving as a fallback in case it is not filled in. "
"If not enabled, we ignore zaak.omschrijving and always use zaaktype.omschrijving."
"Which field from the underlying zaaksysteem to use to display the title "
" for a zaak (e.g. on the Mijn Aanvragen page)."
),
default=False,
)
order_statuses_by_date_set = models.BooleanField(
verbose_name=_(
Expand Down
18 changes: 15 additions & 3 deletions src/open_inwoner/openzaak/tests/test_api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from zgw_consumers.api_models.base import factory

from open_inwoner.openzaak.api_models import Zaak, ZaakType
from open_inwoner.openzaak.constants import ZaakTitleDisplayChoices
from open_inwoner.openzaak.models import OpenZaakConfig


Expand Down Expand Up @@ -111,7 +112,18 @@ def test_zaak_omschrijving(self):
self.assertEqual(case.description, "Vergunning")

zaak_config = OpenZaakConfig.get_solo()
zaak_config.use_zaak_omschrijving_as_title = True
zaak_config.save()

self.assertEqual(case.description, "Vergunning voor Joeri")
expected = {
ZaakTitleDisplayChoices.zaak_omschrijving: self.zaak_data["omschrijving"],
ZaakTitleDisplayChoices.zaaktype_omschrijving: zaaktype.omschrijving,
ZaakTitleDisplayChoices.zaaktype_onderwerp: zaaktype.onderwerp,
}
# Guard against new values
assert all(choice in expected.keys() for choice in ZaakTitleDisplayChoices)

for config_setting, expected_value in expected.items():
with self.subTest(config_setting):
zaak_config.derive_zaak_titel_from = config_setting
zaak_config.save()

self.assertEqual(case.description, expected_value)
Loading