Skip to content

Commit 899a637

Browse files
committed
👔 [#377] Add action validation
Now we check that an item that is being kept in a list cannot be changed. We also check that when extending the bewaartermijn, the selectielijstklasse cannot be updated
1 parent 1899acd commit 899a637

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

Diff for: backend/src/openarchiefbeheer/destruction/api/serializers.py

+44
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
from openarchiefbeheer.zaken.models import Zaak
1919

2020
from ..constants import (
21+
DestructionListItemAction,
2122
InternalStatus,
2223
ListItemStatus,
2324
ListRole,
2425
ListStatus,
2526
ReviewDecisionChoices,
27+
ZaakActionType,
2628
)
2729
from ..models import (
2830
DestructionList,
@@ -502,11 +504,53 @@ class Meta:
502504
"pk",
503505
"review_item",
504506
"action_item",
507+
"action_zaak_type",
505508
"action_zaak",
506509
"created",
507510
"comment",
508511
)
509512

513+
def validate(self, attrs: dict) -> dict:
514+
action_zaak = attrs.get("action_zaak", {})
515+
if attrs["action_item"] == DestructionListItemAction.keep and action_zaak:
516+
raise ValidationError(
517+
{
518+
"action_zaak": _(
519+
"The case cannot be changed if it is kept in the destruction list."
520+
)
521+
}
522+
)
523+
524+
zaak_action_type = attrs.get("action_zaak_type")
525+
selectielijstklasse = action_zaak.get("selectielijstklasse")
526+
if (
527+
attrs["action_item"] == DestructionListItemAction.remove
528+
and zaak_action_type == ZaakActionType.bewaartermijn
529+
and selectielijstklasse
530+
):
531+
raise ValidationError(
532+
{
533+
"action_zaak_type": _(
534+
"The selectielijstklasse cannot be changed if the case action type is 'bewaartermijn'."
535+
)
536+
}
537+
)
538+
539+
if (
540+
attrs["action_item"] == DestructionListItemAction.remove
541+
and zaak_action_type == ZaakActionType.selectielijstklasse_and_bewaartermijn
542+
and not selectielijstklasse
543+
):
544+
raise ValidationError(
545+
{
546+
"selectielijstklasse": _(
547+
"The selectielijstklasse is required for action type is 'selectielijstklasse_and_bewaartermijn'."
548+
)
549+
}
550+
)
551+
552+
return attrs
553+
510554

511555
class ReviewResponseSerializer(serializers.ModelSerializer):
512556
items_responses = ReviewItemResponseSerializer(many=True)

Diff for: backend/src/openarchiefbeheer/destruction/constants.py

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class DestructionListItemAction(models.TextChoices):
3333
remove = "remove", _("remove")
3434

3535

36+
class ZaakActionType(models.TextChoices):
37+
selectielijstklasse_and_bewaartermijn = "selectielijstklasse_and_bewaartermijn", _(
38+
"selectielijstklasse and bewaartermijn"
39+
)
40+
bewaartermijn = "bewaartermijn", _("bewaartermijn")
41+
42+
3643
class InternalStatus(models.TextChoices):
3744
new = "new", _("new")
3845
queued = "queued", _("queued")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 4.2.15 on 2024-09-23 13:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("destruction", "0021_destructionlist_planned_destruction_date"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="reviewitemresponse",
15+
name="action_zaak_type",
16+
field=models.CharField(
17+
blank=True,
18+
choices=[
19+
(
20+
"selectielijstklasse_and_bewaartermijn",
21+
"selectielijstklasse and bewaartermijn",
22+
),
23+
("bewaartermijn", "bewaartermijn"),
24+
],
25+
help_text="What type of change to do on the case. ",
26+
max_length=80,
27+
verbose_name="action zaak type",
28+
),
29+
),
30+
]

Diff for: backend/src/openarchiefbeheer/destruction/models.py

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ListRole,
2525
ListStatus,
2626
ReviewDecisionChoices,
27+
ZaakActionType,
2728
)
2829
from .exceptions import ZaakArchiefactiedatumInFuture, ZaakNotFound
2930

@@ -468,6 +469,13 @@ class ReviewItemResponse(models.Model):
468469
choices=DestructionListItemAction.choices,
469470
max_length=80,
470471
)
472+
action_zaak_type = models.CharField(
473+
_("action zaak type"),
474+
choices=ZaakActionType.choices,
475+
max_length=80,
476+
help_text=_("What type of change to do on the case. "),
477+
blank=True,
478+
)
471479
action_zaak = models.JSONField(
472480
_("action case"),
473481
blank=True,

0 commit comments

Comments
 (0)