Skip to content

Commit

Permalink
✨ [maykinmedia/archiefbeheercomponent#340] Add models for destruction…
Browse files Browse the repository at this point in the history
… list
  • Loading branch information
SilviaAmAm committed May 1, 2024
1 parent 5706ed3 commit ed8a0fd
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/src/openarchiefbeheer/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"simple_certmanager",
# Project applications.
"openarchiefbeheer.accounts",
"openarchiefbeheer.destruction",
"openarchiefbeheer.utils",
]

Expand Down
Empty file.
16 changes: 16 additions & 0 deletions backend/src/openarchiefbeheer/destruction/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.db import models
from django.utils.translation import gettext_lazy as _


class ListStatus(models.TextChoices):
in_progress = "in_progress", _("in progress")
processing = "processing", _("processing")
completed = "completed", _("completed")


class ListItemStatus(models.TextChoices):
suggested = "suggested", _("suggested for destruction")
removed = "removed", _("removed from the destruction list during review")
processing = "processing", _("is currently being destroyed")
destroyed = "destroyed", _("successfully destroyed")
failed = "failed", _("destruction did not succeed")
163 changes: 163 additions & 0 deletions backend/src/openarchiefbeheer/destruction/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Generated by Django 4.2.11 on 2024-05-01 10:48

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="DestructionList",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"name",
models.CharField(max_length=200, unique=True, verbose_name="name"),
),
("created", models.DateTimeField(auto_now_add=True)),
(
"end",
models.DateTimeField(
blank=True,
help_text="The timestamp at which all the cases in the list have been deleted.",
null=True,
verbose_name="end",
),
),
(
"contains_sensitive_info",
models.BooleanField(
default=True,
help_text="Specify whether this destruction list contains privacy sensitive data. If set to true, the report of destruction will NOT contain case descriptions or the remarks by the reviewers.",
verbose_name="contains sensitive information",
),
),
(
"status",
models.CharField(
choices=[
("in_progress", "in progress"),
("processing", "processing"),
("completed", "completed"),
],
default="in_progress",
max_length=80,
verbose_name="status",
),
),
(
"zaak_destruction_report_url",
models.URLField(
blank=True,
help_text="The URL of the case containing the destruction report for this destruction list.",
verbose_name="zaak destruction report URL",
),
),
(
"assignee",
models.ForeignKey(
blank=True,
help_text="Currently assigned user.",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="assigned_lists",
to=settings.AUTH_USER_MODEL,
verbose_name="assignee",
),
),
(
"author",
models.ForeignKey(
help_text="Creator of destruction list.",
on_delete=django.db.models.deletion.CASCADE,
related_name="created_lists",
to=settings.AUTH_USER_MODEL,
verbose_name="author",
),
),
],
options={
"verbose_name": "destruction list",
"verbose_name_plural": "destruction lists",
},
),
migrations.CreateModel(
name="DestructionListItem",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"zaak",
models.URLField(
db_index=True,
help_text="URL-reference to the ZAAK (in Zaken API), which is planned to be destroyed.",
verbose_name="zaak",
),
),
(
"status",
models.CharField(
choices=[
("suggested", "suggested for destruction"),
(
"removed",
"removed from the destruction list during review",
),
("processing", "is currently being destroyed"),
("destroyed", "successfully destroyed"),
("failed", "destruction did not succeed"),
],
default="suggested",
max_length=80,
verbose_name="status",
),
),
(
"extra_zaak_data",
models.JSONField(
blank=True,
help_text="Additional information of the zaak",
null=True,
verbose_name="extra zaak data",
),
),
(
"destruction_list",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="items",
to="destruction.destructionlist",
verbose_name="destruction list",
),
),
],
options={
"verbose_name": "destruction list item",
"verbose_name_plural": "destruction list items",
"unique_together": {("destruction_list", "zaak")},
},
),
]
Empty file.
98 changes: 98 additions & 0 deletions backend/src/openarchiefbeheer/destruction/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from openarchiefbeheer.destruction.constants import ListItemStatus, ListStatus


class DestructionList(models.Model):
name = models.CharField(_("name"), max_length=200, unique=True)
author = models.ForeignKey(
"accounts.User",
on_delete=models.CASCADE,
related_name="created_lists",
verbose_name=_("author"),
help_text=_("Creator of destruction list."),
)
created = models.DateTimeField(auto_now_add=True)
end = models.DateTimeField(
_("end"),
blank=True,
null=True,
help_text=_(
"The timestamp at which all the cases in the list have been deleted."
),
)
contains_sensitive_info = models.BooleanField(
verbose_name=_("contains sensitive information"),
help_text=_(
"Specify whether this destruction list contains privacy sensitive data. "
"If set to true, the report of destruction will NOT contain case "
"descriptions or the remarks by the reviewers."
),
default=True,
)
assignee = models.ForeignKey(
"accounts.User",
blank=True,
null=True,
on_delete=models.SET_NULL,
related_name="assigned_lists",
verbose_name=_("assignee"),
help_text=_("Currently assigned user."),
)
status = models.CharField(
_("status"),
default=ListStatus.in_progress,
choices=ListStatus.choices,
max_length=80,
)
zaak_destruction_report_url = models.URLField(
_("zaak destruction report URL"),
help_text=_(
"The URL of the case containing the destruction report for this destruction list."
),
blank=True,
)

class Meta:
verbose_name = _("destruction list")
verbose_name_plural = _("destruction lists")

def __str__(self):
return self.name


class DestructionListItem(models.Model):
destruction_list = models.ForeignKey(
DestructionList,
on_delete=models.CASCADE,
related_name="items",
verbose_name=_("destruction list"),
)
zaak = models.URLField(
_("zaak"),
db_index=True,
help_text=_(
"URL-reference to the ZAAK (in Zaken API), which is planned to be destroyed."
),
)
status = models.CharField(
_("status"),
default=ListItemStatus.suggested,
choices=ListItemStatus.choices,
max_length=80,
)
extra_zaak_data = models.JSONField(
verbose_name=_("extra zaak data"),
help_text=_("Additional information of the zaak"),
null=True,
blank=True,
)

class Meta:
verbose_name = _("destruction list item")
verbose_name_plural = _("destruction list items")
unique_together = ("destruction_list", "zaak")

def __str__(self):
return f"{self.destruction_list}: {self.zaak}"
16 changes: 16 additions & 0 deletions backend/src/openarchiefbeheer/destruction/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from zgw_consumers.concurrent import parallel

from openarchiefbeheer.destruction.models import DestructionListItem


# TODO optimise once we have a better idea of the numbers of zaken / destruction lists
def process_zaken(zaken: list[dict]) -> list[dict]:

def check_zaak_already_in_list(zaak: dict) -> dict | None:
if not DestructionListItem.objects.filter(zaak=zaak["url"]).exists():
return zaak

with parallel() as executor:
results = executor.map(check_zaak_already_in_list, zaken)

return [result for result in results if result is not None]

0 comments on commit ed8a0fd

Please sign in to comment.