Skip to content

Commit

Permalink
✨ [#558] Add delete endpoint for new lists
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Dec 20, 2024
1 parent 802feed commit 4236b52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/src/openarchiefbeheer/destruction/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def has_object_permission(self, request, view, destruction_list):

class CanTriggerDeletion(permissions.BasePermission):
message = _(
"You are either not allowed to delete this destruction list or "
"You are either not allowed to queue the deletion of this destruction list or "
"the destruction list can currently not be deleted."
)

Expand All @@ -70,6 +70,19 @@ def has_object_permission(self, request, view, destruction_list):
return destruction_list.status == ListStatus.ready_to_delete


class CanDeleteList(permissions.BasePermission):
message = _(
"You are either not allowed to delete this destruction list or "
"the destruction list does not have the status '%(status)s'."
) % {"status": ListStatus.new}

def has_permission(self, request, view):
return request.user.has_perm("accounts.can_start_destruction")

def has_object_permission(self, request, view, destruction_list):
return destruction_list.status == ListStatus.new


class CanReassignDestructionList(permissions.BasePermission):
message = _("You are not allowed to reassign the destruction list.")

Expand Down
12 changes: 12 additions & 0 deletions backend/src/openarchiefbeheer/destruction/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from .permissions import (
CanAbortDestruction,
CanCoReviewPermission,
CanDeleteList,
CanMarkAsReadyToReview,
CanMarkListAsFinal,
CanReassignDestructionList,
Expand Down Expand Up @@ -168,6 +169,15 @@
description=_("Retrieve details about a destruction list."),
responses={200: DestructionListReadSerializer},
),
destroy=extend_schema(
tags=["Destruction list"],
summary=_("Delete destruction list"),
description=_(
"Delete a destruction list. Can only be used for lists with status 'new'."
),
request=None,
responses={204: None},
),
queue_destruction=extend_schema(
tags=["Destruction list"],
summary=_("Queue destruction list destruction"),
Expand Down Expand Up @@ -238,6 +248,8 @@ def get_permissions(self):
permission_classes = [IsAuthenticated & CanStartDestructionPermission]
elif self.action == "update":
permission_classes = [IsAuthenticated & CanUpdateDestructionList]
elif self.action == "destroy":
permission_classes = [IsAuthenticated & CanDeleteList]
elif self.action == "queue_destruction":
permission_classes = [IsAuthenticated & CanTriggerDeletion]
elif self.action == "make_final":
Expand Down

0 comments on commit 4236b52

Please sign in to comment.