Skip to content

Commit

Permalink
Merge pull request #77 from maykinmedia/feature/76-add-uuids-to-lists
Browse files Browse the repository at this point in the history
[#76] Add uuids to destruction lists
  • Loading branch information
SilviaAmAm authored Jun 6, 2024
2 parents 269e8df + 7a1782c commit 6ae5de5
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 8 deletions.
1 change: 1 addition & 0 deletions backend/src/openarchiefbeheer/destruction/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class DestructionListAdmin(admin.ModelAdmin):
list_display = ("name", "status", "created", "end")
list_filter = ("status", "assignee")
search_fields = ("name",)
readonly_fields = ("uuid",)


@admin.register(DestructionListItem)
Expand Down
9 changes: 7 additions & 2 deletions backend/src/openarchiefbeheer/destruction/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ class DestructionListSerializer(serializers.ModelSerializer):
class Meta:
model = DestructionList
fields = (
"uuid",
"name",
"author",
"contains_sensitive_info",
"assignees",
"items",
"status",
)
extra_kwargs = {"status": {"read_only": True}, "author": {"read_only": True}}
extra_kwargs = {
"uuid": {"read_only": True},
"status": {"read_only": True},
"author": {"read_only": True},
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -151,7 +156,7 @@ class DestructionListResponseSerializer(serializers.ModelSerializer):
class Meta:
model = DestructionList
fields = (
"pk",
"uuid",
"name",
"author",
"contains_sensitive_info",
Expand Down
1 change: 1 addition & 0 deletions backend/src/openarchiefbeheer/destruction/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class DestructionListViewSet(
):
serializer_class = DestructionListSerializer
queryset = DestructionList.objects.all()
lookup_field = "uuid"
filter_backends = (DjangoFilterBackend,)
filterset_class = DestructionListFilterset

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.11 on 2024-06-06 09:17

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [
("destruction", "0003_destructionlist_status_changed"),
]

operations = [
migrations.AddField(
model_name="destructionlist",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, null=True, verbose_name="uuid"),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.11 on 2024-06-06 09:17

from django.db import migrations
import uuid


def generate_uuid(apps, schema_editor):
DestructionList = apps.get_model("destruction", "DestructionList")
for destruction_list in DestructionList.objects.all():
destruction_list.uuid = uuid.uuid4()
destruction_list.save(update_fields=["uuid"])


class Migration(migrations.Migration):

dependencies = [
("destruction", "0004_destructionlist_uuid"),
]

operations = [
migrations.RunPython(generate_uuid, reverse_code=migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.11 on 2024-06-06 09:17

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [
("destruction", "0005_populate_uuid_values"),
]

operations = [
migrations.AlterField(
model_name="destructionlist",
name="uuid",
field=models.UUIDField(
default=uuid.uuid4, unique=True, verbose_name="uuid"
),
),
]
2 changes: 2 additions & 0 deletions backend/src/openarchiefbeheer/destruction/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import uuid as _uuid

from django.db import models
from django.utils import timezone
Expand All @@ -16,6 +17,7 @@

class DestructionList(models.Model):
name = models.CharField(_("name"), max_length=200, unique=True)
uuid = models.UUIDField(_("uuid"), default=_uuid.uuid4, unique=True)
author = models.ForeignKey(
"accounts.User",
on_delete=models.CASCADE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_update_destruction_list(self):
}
self.client.force_authenticate(user=record_manager)
endpoint = reverse(
"api:destructionlist-detail", kwargs={"pk": destruction_list.pk}
"api:destructionlist-detail", kwargs={"uuid": destruction_list.uuid}
)

response = self.client.put(
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_partially_update_destruction_list(self):
}
self.client.force_authenticate(user=record_manager)
endpoint = reverse(
"api:destructionlist-detail", kwargs={"pk": destruction_list.pk}
"api:destructionlist-detail", kwargs={"uuid": destruction_list.uuid}
)

response = self.client.patch(
Expand Down Expand Up @@ -287,8 +287,8 @@ def test_destruction_list_filter_on_assignee(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.json()), 2)
self.assertEqual(
[destruction_list["pk"] for destruction_list in response.json()].sort(),
[lists[0].pk, lists[1].pk].sort(),
[destruction_list["uuid"] for destruction_list in response.json()].sort(),
[lists[0].uuid, lists[1].uuid].sort(),
)


Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/api/destructionLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { request } from "./request";
import { User } from "./reviewers";

export type DestructionList = {
pk: number;
uuid: string;
name: string;
assignees: DestructionListAssignee[];
items: DestructionListItem[];
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/landing/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const Landing = () => {
title: list.name,
days: timeAgo(list.created),
assigneeNames: constructAssigneeNames(list.assignees),
href: `/destruction-list/${list.pk}`,
href: `/destruction-list/${list.uuid}`,
})),
) as unknown as AttributeData[][];

Expand Down

0 comments on commit 6ae5de5

Please sign in to comment.