Commit 511be40d authored by davelopez's avatar davelopez
Browse files

Raise error when bulk undeleting

Instead of doing nothing and treating the item as successful, we now raise a specific error.
This helps to determine if the bulk operation will trigger a history update when an item succeeds.
Otherwise, the UI will keep waiting for a history update that may never occur.
For the same reason, when purging an already purged item, we will touch the `update_time` but do nothing, so we notify the history to expect a *change*.
parent ae7dbbaf
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -1602,11 +1602,15 @@ class HistoryItemOperator:

    def _undelete(self, item: HistoryItemModel):
        if getattr(item, "purged", False):
            return
            raise exceptions.ItemDeletionException("This item has been permanently deleted and cannot be recovered.")
        manager = self._get_item_manager(item)
        manager.undelete(item, flush=self.flush)

    def _purge(self, item: HistoryItemModel, trans: ProvidesHistoryContext):
        if getattr(item, "purged", False):
            # TODO: remove this `update` when we can properly track the operation results to notify the history
            item.update()
            return
        if isinstance(item, HistoryDatasetCollectionAssociation):
            return self.dataset_collection_manager.delete(trans, "history", item.id, recursive=True, purge=True)
        self.hda_manager.purge(item, flush=self.flush)
+5 −2
Original line number Diff line number Diff line
@@ -1122,7 +1122,7 @@ class HistoryContentsApiBulkOperationTestCase(ApiTestCase):
            # collections don't have a `purged` attribute but they should be marked deleted on purge
            assert purged_collection["deleted"] is True

            # Un-deleting a purged dataset should not have any effect
            # Un-deleting a purged dataset should not have any effect and raise an error
            payload = {
                "operation": "undelete",
                "items": [
@@ -1134,7 +1134,10 @@ class HistoryContentsApiBulkOperationTestCase(ApiTestCase):
            }
            bulk_operation_result = self._apply_bulk_operation(history_id, payload)
            history_contents = self._get_history_contents(history_id)
            self._assert_bulk_success(bulk_operation_result, 1)
            assert bulk_operation_result["success_count"] == 0
            assert len(bulk_operation_result["errors"]) == 1
            error = bulk_operation_result["errors"][0]
            assert error["item"]["id"] == datasets_ids[0]
            purged_dataset = self._get_dataset_with_id_from_history_contents(history_contents, datasets_ids[0])
            assert purged_dataset["deleted"] is True
            assert purged_dataset["purged"] is True