Skip to content

Commit

Permalink
Merge pull request #826 from maykinmedia/feature/1792-zaaktype-result…
Browse files Browse the repository at this point in the history
…aattype-config

✨ [#1792] Add ZaakTypeResultaatType config
  • Loading branch information
alextreme authored Nov 1, 2023
2 parents 206893d + fecd956 commit 88ae2db
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 24 deletions.
27 changes: 27 additions & 0 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
UserCaseStatusNotification,
ZaakTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
ZaakTypeResultaatTypeConfig,
ZaakTypeStatusTypeConfig,
)
from .resources.import_resource import StatusTranslationImportResource
Expand Down Expand Up @@ -202,11 +203,37 @@ def has_delete_permission(self, request, obj=None):
return request.user.is_superuser


class ZaakTypeResultaattypeConfigInline(admin.TabularInline):
model = ZaakTypeResultaatTypeConfig
fields = [
"omschrijving",
"resultaattype_url",
"zaaktype_uuids",
"description",
]
readonly_fields = [
"omschrijving",
"resultaattype_url",
"zaaktype_uuids",
]
ordering = (
"zaaktype_uuids",
"omschrijving",
)

def has_add_permission(self, request, obj):
return False

def has_delete_permission(self, request, obj=None):
return request.user.is_superuser


@admin.register(ZaakTypeConfig)
class ZaakTypeConfigAdmin(admin.ModelAdmin):
inlines = [
ZaakTypeInformatieObjectTypeConfigInline,
ZaakTypeStatusTypeConfigInline,
ZaakTypeResultaattypeConfigInline,
]
actions = [
"mark_as_notify_status_changes",
Expand Down
20 changes: 20 additions & 0 deletions src/open_inwoner/openzaak/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ def fetch_single_status_type(status_type_url: str) -> Optional[StatusType]:
return status_type


@cache_result(
"resultaat_type:{resultaat_type_url}", timeout=settings.CACHE_ZGW_CATALOGI_TIMEOUT
)
def fetch_single_resultaat_type(resultaat_type_url: str) -> Optional[ResultaatType]:
client = build_client("catalogi")

if client is None:
return

try:
response = client.retrieve("resultaattype", url=resultaat_type_url)
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

resultaat_type = factory(ResultaatType, response)

return resultaat_type


# not cached because only used by tools,
# and because caching (stale) listings can break lookups
def fetch_zaaktypes_no_cache() -> List[ZaakType]:
Expand Down
64 changes: 43 additions & 21 deletions src/open_inwoner/openzaak/management/commands/zgw_import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import_catalog_configs,
import_zaaktype_configs,
import_zaaktype_informatieobjecttype_configs,
import_zaaktype_resultaattype_configs,
import_zaaktype_statustype_configs,
)

Expand All @@ -15,7 +16,38 @@
class Command(BaseCommand):
help = "Import ZGW catalog data"

def log_supplement_imports_to_stdout(
self, import_func: callable, config_type: str
) -> None:
"""
Convenience function for logging zaaktype config types to stdout
Example input:
import_func=import_zaaktype_informatieobjecttype_configs
config_type="informatiebjecttype"
Example output:
imported 3 new zaaktype-informatiebjecttype configs
AAA - zaaktype-aaa
info-aaa-1
info-aaa-2
BBB - zaaktype-bbb
info-bbb
"""
imported = import_func()

count = sum(len(t[1]) for t in imported)
self.stdout.write(f"imported {count} new zaaktype-{config_type} configs")

for ztc, config_types in sorted(imported, key=lambda t: str(t[0])):
self.stdout.write(str(ztc))
for c in sorted(map(str, config_types)):
self.stdout.write(f" {c}")

self.stdout.write("")

def handle(self, *args, **options):
# catalogus config
imported = import_catalog_configs()

self.stdout.write(f"imported {len(imported)} new catalogus configs")
Expand All @@ -24,6 +56,7 @@ def handle(self, *args, **options):

self.stdout.write("")

# zaaktype config
imported = import_zaaktype_configs()

self.stdout.write(f"imported {len(imported)} new zaaktype configs")
Expand All @@ -32,24 +65,13 @@ def handle(self, *args, **options):

self.stdout.write("")

imported = import_zaaktype_informatieobjecttype_configs()

count = sum(len(t[1]) for t in imported)

self.stdout.write(f"imported {count} new zaaktype-informatiebjecttype configs")
for ztc, info_types in sorted(imported, key=lambda t: str(t[0])):
self.stdout.write(str(ztc))
for c in sorted(map(str, info_types)):
self.stdout.write(f" {c}")

self.stdout.write("")

imported = import_zaaktype_statustype_configs()

count = sum(len(t[1]) for t in imported)

self.stdout.write(f"imported {count} new zaaktype-statustype configs")
for ztc, status_types in sorted(imported, key=lambda t: str(t[0])):
self.stdout.write(str(ztc))
for c in sorted(map(str, status_types)):
self.stdout.write(f" {c}")
# supplemental configs
self.log_supplement_imports_to_stdout(
import_zaaktype_informatieobjecttype_configs, "informatiebjecttype"
)
self.log_supplement_imports_to_stdout(
import_zaaktype_statustype_configs, "statustype"
)
self.log_supplement_imports_to_stdout(
import_zaaktype_resultaattype_configs, "resultaattype"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Generated by Django 3.2.20 on 2023-10-26 10:05

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


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0026_zaaktypestatustypeconfig_document_upload_description"),
]

operations = [
migrations.CreateModel(
name="ZaakTypeResultaatTypeConfig",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"resultaattype_url",
models.URLField(max_length=1000, verbose_name="Resultaattype URL"),
),
(
"omschrijving",
models.CharField(max_length=20, verbose_name="Omschrijving"),
),
(
"zaaktype_uuids",
django_better_admin_arrayfield.models.fields.ArrayField(
base_field=models.UUIDField(verbose_name="Zaaktype UUID"),
default=list,
size=None,
),
),
(
"description",
models.TextField(
blank=True,
default="",
help_text="Determines the text that will be shown to the user if a case is set to this result",
verbose_name="Frontend description",
),
),
(
"zaaktype_config",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="openzaak.zaaktypeconfig",
),
),
],
options={
"verbose_name": "Zaaktype Resultaattype Configuration",
},
),
migrations.AddConstraint(
model_name="zaaktyperesultaattypeconfig",
constraint=models.UniqueConstraint(
fields=("zaaktype_config", "resultaattype_url"),
name="unique_zaaktype_config_resultaattype_url",
),
),
]
44 changes: 44 additions & 0 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,50 @@ def __str__(self):
return f"{self.zaaktype_config.identificatie} - {self.omschrijving}"


class ZaakTypeResultaatTypeConfig(models.Model):
zaaktype_config = models.ForeignKey(
"openzaak.ZaakTypeConfig",
on_delete=models.CASCADE,
)
resultaattype_url = models.URLField(
verbose_name=_("Resultaattype URL"),
max_length=1000,
)
omschrijving = models.CharField(
verbose_name=_("Omschrijving"),
max_length=20,
)
zaaktype_uuids = ArrayField(
models.UUIDField(
verbose_name=_("Zaaktype UUID"),
),
default=list,
)

# configuration
description = models.TextField(
blank=True,
default="",
verbose_name=_("Frontend description"),
help_text=_(
"Determines the text that will be shown to the user if a case is set to this result"
),
)

class Meta:
verbose_name = _("Zaaktype Resultaattype Configuration")

constraints = [
UniqueConstraint(
name="unique_zaaktype_config_resultaattype_url",
fields=["zaaktype_config", "resultaattype_url"],
)
]

def __str__(self):
return f"{self.zaaktype_config.identificatie} - {self.omschrijving}"


class UserCaseStatusNotificationBase(models.Model):
user = models.ForeignKey(
"accounts.User",
Expand Down
23 changes: 22 additions & 1 deletion src/open_inwoner/openzaak/tests/test_zgw_imports_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
OpenZaakConfig,
ZaakTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
ZaakTypeResultaatTypeConfig,
ZaakTypeStatusTypeConfig,
)
from open_inwoner.openzaak.tests.factories import ServiceFactory
Expand Down Expand Up @@ -49,6 +50,7 @@ def test_zgw_import_data_command(self, m):
self.assertEqual(ZaakTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeInformatieObjectTypeConfig.objects.count(), 3)
self.assertEqual(ZaakTypeStatusTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeResultaatTypeConfig.objects.count(), 2)

stdout = out.getvalue().strip()

Expand All @@ -73,6 +75,12 @@ def test_zgw_import_data_command(self, m):
AAA - zaaktype-aaa
AAA - status-aaa-1
AAA - status-aaa-2
imported 2 new zaaktype-resultaattype configs
AAA - zaaktype-aaa
AAA - test
BBB - zaaktype-bbb
BBB - test
"""
).strip()

Expand All @@ -87,6 +95,7 @@ def test_zgw_import_data_command(self, m):
self.assertEqual(ZaakTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeInformatieObjectTypeConfig.objects.count(), 3)
self.assertEqual(ZaakTypeStatusTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeResultaatTypeConfig.objects.count(), 2)

stdout = out.getvalue().strip()

Expand All @@ -99,6 +108,8 @@ def test_zgw_import_data_command(self, m):
imported 0 new zaaktype-informatiebjecttype configs
imported 0 new zaaktype-statustype configs
imported 0 new zaaktype-resultaattype configs
"""
).strip()

Expand All @@ -111,14 +122,15 @@ def test_zgw_import_data_command_without_catalog(self, m):
)
InformationObjectTypeMockData().install_mocks(m, with_catalog=False)

# run it to import our data
# # run it to import our data
out = StringIO()
call_command("zgw_import_data", stdout=out)

self.assertEqual(CatalogusConfig.objects.count(), 0)
self.assertEqual(ZaakTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeInformatieObjectTypeConfig.objects.count(), 3)
self.assertEqual(ZaakTypeStatusTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeResultaatTypeConfig.objects.count(), 2)

stdout = out.getvalue().strip()

Expand All @@ -141,6 +153,12 @@ def test_zgw_import_data_command_without_catalog(self, m):
AAA - zaaktype-aaa
AAA - status-aaa-1
AAA - status-aaa-2
imported 2 new zaaktype-resultaattype configs
AAA - zaaktype-aaa
AAA - test
BBB - zaaktype-bbb
BBB - test
"""
).strip()

Expand All @@ -155,6 +173,7 @@ def test_zgw_import_data_command_without_catalog(self, m):
self.assertEqual(ZaakTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeInformatieObjectTypeConfig.objects.count(), 3)
self.assertEqual(ZaakTypeStatusTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeResultaatTypeConfig.objects.count(), 2)

stdout = out.getvalue().strip()

Expand All @@ -167,6 +186,8 @@ def test_zgw_import_data_command_without_catalog(self, m):
imported 0 new zaaktype-informatiebjecttype configs
imported 0 new zaaktype-statustype configs
imported 0 new zaaktype-resultaattype configs
"""
).strip()

Expand Down
Loading

0 comments on commit 88ae2db

Please sign in to comment.