From a796b1aab88c6bbc584aefb14ac94c5fbe83bd96 Mon Sep 17 00:00:00 2001
From: Eva Bardou <ebardou@teklia.com>
Date: Mon, 30 Nov 2020 15:54:47 +0100
Subject: [PATCH] Start working on selected elements deletion

---
 arkindex/documents/api/elements.py | 11 +++++++++++
 arkindex/project/api_v1.py         |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/arkindex/documents/api/elements.py b/arkindex/documents/api/elements.py
index a0aee4ec2c..2d4e56cbb8 100644
--- a/arkindex/documents/api/elements.py
+++ b/arkindex/documents/api/elements.py
@@ -1168,3 +1168,14 @@ class ElementBulkCreate(CreateAPIView):
         ])
 
         return [{'id': element_data['element'].id} for element_data in elements]
+
+
+class CorpusDeleteSelection(ElementsListMixin, SelectionMixin, DestroyAPIView):
+    """
+    Delete selected elements on a corpus
+    """
+
+    def get_queryset(self):
+        # Should not be possible due to the URL
+        assert self.selected_corpus, 'Missing corpus ID'
+        return self.get_selection(corpus_id=self.selected_corpus.id)
diff --git a/arkindex/project/api_v1.py b/arkindex/project/api_v1.py
index 38063bb11b..eab6c01e1d 100644
--- a/arkindex/project/api_v1.py
+++ b/arkindex/project/api_v1.py
@@ -35,6 +35,7 @@ from arkindex.dataimport.api import (
 from arkindex.documents.api.admin import ReindexStart
 from arkindex.documents.api.elements import (
     CorpusAllowedMetaData,
+    CorpusDeleteSelection,
     CorpusElements,
     CorpusList,
     CorpusRetrieve,
@@ -144,6 +145,7 @@ api = [
     path('corpus/<uuid:pk>/ml-stats/', CorpusMLStats.as_view(), name='corpus-ml-stats'),
     path('corpus/<uuid:pk>/allowed-metadata/', CorpusAllowedMetaData.as_view(), name='corpus-allowed-metadata'),
     path('corpus/<uuid:pk>/versions/', CorpusWorkerVersionList.as_view(), name='corpus-versions'),
+    path('corpus/<uuid:corpus>/selection/', CorpusDeleteSelection.as_view(), name='corpus-delete-selection'),
 
     # Moderation
     path('ml-classes/', MLClassList.as_view(), name='mlclass-list'),
-- 
GitLab