From 680dee3a517b5f992c78bec256257c824103fbda Mon Sep 17 00:00:00 2001 From: monsieurswag Date: Tue, 14 May 2024 17:31:00 +0200 Subject: [PATCH] Make the custom stored libraries deletable --- backend/library/views.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/library/views.py b/backend/library/views.py index b0b702ac4..54aab536c 100644 --- a/backend/library/views.py +++ b/backend/library/views.py @@ -53,6 +53,22 @@ def content(self, request, pk): lib = StoredLibrary.objects.get(id=pk) return Response(lib.content) + def destroy(self, request, *args, pk, **kwargs): + if not RoleAssignment.is_access_allowed( + user=request.user, + perm=Permission.objects.get(codename="delete_storedlibrary"), + folder=Folder.get_root_folder(), + ): + return Response(status=status.HTTP_403_FORBIDDEN) + + try: + lib = StoredLibrary.objects.get(urn=pk) + except: + return Response(data="Library not found.", status=status.HTTP_404_NOT_FOUND) + + lib.delete() + return Response(status=status.HTTP_204_NO_CONTENT) + @action(detail=True, methods=["get"], url_path="import") def import_library(self, request, pk): if not RoleAssignment.is_access_allowed(