Skip to content

Commit

Permalink
✨ [#397] Add mechanism to save zaak metadata before deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Oct 11, 2024
1 parent 5853832 commit 7bf56d0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
6 changes: 5 additions & 1 deletion backend/src/openarchiefbeheer/destruction/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
from openarchiefbeheer.accounts.models import User
from openarchiefbeheer.logging import logevent
from openarchiefbeheer.zaken.api.filtersets import ZaakFilter
from openarchiefbeheer.zaken.api.serializers import ZaakSerializer
from openarchiefbeheer.zaken.api.serializers import (
ZaakMetadataSerializer,
ZaakSerializer,
)
from openarchiefbeheer.zaken.models import Zaak
from openarchiefbeheer.zaken.utils import retrieve_selectielijstklasse_resultaat

Expand Down Expand Up @@ -132,6 +135,7 @@ def validate(self, attrs: dict) -> dict:

class DestructionListItemReadSerializer(serializers.ModelSerializer):
zaak = ZaakSerializer(allow_null=True, read_only=True)
extra_zaak_data = ZaakMetadataSerializer(read_only=True, allow_null=True)

class Meta:
model = DestructionListItem
Expand Down
6 changes: 5 additions & 1 deletion backend/src/openarchiefbeheer/destruction/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
from openarchiefbeheer.accounts.models import User
from openarchiefbeheer.config.models import ArchiveConfig
from openarchiefbeheer.utils.results_store import ResultStore
from openarchiefbeheer.zaken.utils import delete_zaak_and_related_objects
from openarchiefbeheer.zaken.utils import (
delete_zaak_and_related_objects,
get_zaak_metadata,
)

from .assignment_logic import STATE_MANAGER
from .constants import (
Expand Down Expand Up @@ -276,6 +279,7 @@ def _delete_zaak(self):

def process_deletion(self) -> None:
self.processing_status = InternalStatus.processing
self.extra_zaak_data = get_zaak_metadata(self.zaak)
self.save()

try:
Expand Down
28 changes: 28 additions & 0 deletions backend/src/openarchiefbeheer/zaken/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.utils.translation import gettext_lazy as _

from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_framework_gis.fields import GeometryField
Expand Down Expand Up @@ -120,3 +121,30 @@ def validate(self, attrs):
_("Multiple query parameters at the same time are not supported.")
)
return attrs


class ZaakMetadataSerializer(serializers.ModelSerializer):
zaaktype = serializers.SerializerMethodField()

class Meta:
model = Zaak
fields = (
"url",
"einddatum",
"resultaat",
"startdatum",
"omschrijving",
"identificatie",
"zaaktype",
)

@extend_schema_field(serializers.JSONField)
def get_zaaktype(self, zaak: Zaak) -> dict | None:
zaaktype = zaak._expand["zaaktype"]
return {
"url": zaaktype["url"],
"omschrijving": zaaktype["omschrijving"],
"selectielijst_procestype": {
"nummer": zaaktype["selectielijst_procestype"]["nummer"]
},
}
7 changes: 7 additions & 0 deletions backend/src/openarchiefbeheer/zaken/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,10 @@ def format_choice(item: dict) -> DropDownChoice:
results += [format_choice(result) for result in page["results"]]

return results


def get_zaak_metadata(zaak: Zaak) -> dict:
from .api.serializers import ZaakMetadataSerializer

serializer = ZaakMetadataSerializer(instance=zaak)
return serializer.data

0 comments on commit 7bf56d0

Please sign in to comment.