Skip to content

Commit 02383a6

Browse files
SilviaAmAmsvenvandescheur
authored andcommittedAug 9, 2024
✨ [#263] Add ordering of assignees to the destruction list endpoint
1 parent f3660d9 commit 02383a6

File tree

2 files changed

+3
-24
lines changed

2 files changed

+3
-24
lines changed
 

‎backend/src/openarchiefbeheer/destruction/api/viewsets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class DestructionListViewSet(
188188
"assignees",
189189
queryset=DestructionListAssignee.objects.select_related(
190190
"user", "user__role"
191-
),
191+
).order_by("pk"),
192192
)
193193
)
194194
)

‎backend/src/openarchiefbeheer/destruction/utils.py

+2-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from django.conf import settings
55
from django.core.mail import send_mail
66
from django.db import transaction
7-
from django.db.models import Q
87

98
from openarchiefbeheer.accounts.models import User
109
from openarchiefbeheer.emails.models import EmailConfig
@@ -133,30 +132,10 @@ def process_new_assignees(
133132
assignees: list[dict],
134133
role: str,
135134
) -> list[DestructionListAssignee]:
136-
"""
137-
Remove any assignees that are not present in the new assignees and create the new ones.
138-
139-
Example:
140-
Before reassigning there are reviewerA, reviewerB and reviewerC.
141-
The record manager requests that the new reviewers are reviewerB and reviewerD.
142-
This function deletes reviewerA and reviewerC and creates reviewerD.
143-
"""
144-
users = [assignee["user"] for assignee in assignees]
145-
146135
with transaction.atomic():
147-
destruction_list.assignees.filter(~Q(user__in=users), role=role).delete()
148-
149-
existing_assignees_users = [
150-
assignee.user.pk
151-
for assignee in destruction_list.assignees.filter(role=role)
152-
]
153-
assignees_to_create = []
154-
for assignee in assignees:
155-
if assignee["user"].pk not in existing_assignees_users:
156-
assignees_to_create.append(assignee)
157-
136+
destruction_list.assignees.filter(role=role).delete()
158137
new_assignees = destruction_list.bulk_create_assignees(
159-
assignees_to_create,
138+
assignees,
160139
role,
161140
)
162141

0 commit comments

Comments
 (0)