Enhancement: rename and move files when storage path deleted
Revert "Enhancement: rename and move files when storage path deleted" This reverts commit 86602a3bc23dcc9ba328a71419a328f75b27ab89. yes this
This commit is contained in:
parent
37c4545444
commit
c1633ef37a
@ -224,6 +224,35 @@ class TestApiStoragePaths(DirectoriesMixin, APITestCase):
|
||||
|
||||
self.assertCountEqual([document.pk], args[0])
|
||||
|
||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
||||
def test_api_delete_storage_path(self, bulk_update_mock):
|
||||
"""
|
||||
GIVEN:
|
||||
- API request to delete a storage
|
||||
WHEN:
|
||||
- API is called
|
||||
THEN:
|
||||
- Documents using the storage path are updated
|
||||
"""
|
||||
document = Document.objects.create(
|
||||
mime_type="application/pdf",
|
||||
storage_path=self.sp1,
|
||||
)
|
||||
response = self.client.delete(
|
||||
f"{self.ENDPOINT}{self.sp1.pk}/",
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
||||
|
||||
# sp with no documents
|
||||
sp2 = StoragePath.objects.create(name="sp2", path="Something2/{checksum}")
|
||||
response = self.client.delete(
|
||||
f"{self.ENDPOINT}{sp2.pk}/",
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
||||
|
||||
# only called once
|
||||
bulk_update_mock.assert_called_once_with([document.pk])
|
||||
|
||||
|
||||
class TestBulkEditObjects(APITestCase):
|
||||
# See test_api_permissions.py for bulk tests on permissions
|
||||
|
@ -1211,6 +1211,22 @@ class StoragePathViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
filterset_class = StoragePathFilterSet
|
||||
ordering_fields = ("name", "path", "matching_algorithm", "match", "document_count")
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
"""
|
||||
When a storage path is deleted, see if documents
|
||||
using it require a rename/move
|
||||
"""
|
||||
instance = self.get_object()
|
||||
doc_ids = [doc.id for doc in instance.documents.all()]
|
||||
|
||||
# perform the deletion so renaming/moving can happen
|
||||
response = super().destroy(request, *args, **kwargs)
|
||||
|
||||
if len(doc_ids):
|
||||
bulk_edit.bulk_update_documents.delay(doc_ids)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
class UiSettingsView(GenericAPIView):
|
||||
queryset = UiSettings.objects.all()
|
||||
|
Loading…
x
Reference in New Issue
Block a user