From c9d06aeb41d9e15c07dddf4fff67630f2ee2237d Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 22 Mar 2017 12:23:29 -0400 Subject: [PATCH] Allow collection creation API to hide original datasets during creation. --- lib/galaxy/managers/collections.py | 8 ++++++++ lib/galaxy/managers/collections_util.py | 2 ++ test/api/test_history_contents.py | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/galaxy/managers/collections.py b/lib/galaxy/managers/collections.py index aadaf226439..43db8c1a39d 100644 --- a/lib/galaxy/managers/collections.py +++ b/lib/galaxy/managers/collections.py @@ -51,6 +51,7 @@ class DatasetCollectionManager( object ): elements=None, implicit_collection_info=None, trusted_identifiers=None, # Trust preloaded element objects + hide_source_items=False, ): """ """ @@ -66,6 +67,7 @@ class DatasetCollectionManager( object ): collection_type=collection_type, element_identifiers=element_identifiers, elements=elements, + hide_source_items=hide_source_items, ) if isinstance( parent, model.History ): @@ -114,6 +116,7 @@ class DatasetCollectionManager( object ): collection_type, element_identifiers=None, elements=None, + hide_source_items=False, ): if element_identifiers is None and elements is None: raise RequestParameterInvalidException( ERROR_INVALID_ELEMENTS_SPECIFICATION ) @@ -133,11 +136,16 @@ class DatasetCollectionManager( object ): elements = self.__load_elements(trans, element_identifier['element_identifiers']) if not new_collection: elements = self.__load_elements( trans, element_identifiers ) + # else if elements is set, it better be an ordered dict! if elements is not self.ELEMENTS_UNINITIALIZED: type_plugin = collection_type_description.rank_type_plugin() dataset_collection = builder.build_collection( type_plugin, elements ) + if hide_source_items: + log.debug("Hiding source items during dataset collection creation") + for dataset in dataset_collection.dataset_instances: + dataset.visible = False else: dataset_collection = model.DatasetCollection( populated=False ) dataset_collection.collection_type = collection_type diff --git a/lib/galaxy/managers/collections_util.py b/lib/galaxy/managers/collections_util.py index 16bfaee8199..a6a9571cb01 100644 --- a/lib/galaxy/managers/collections_util.py +++ b/lib/galaxy/managers/collections_util.py @@ -1,6 +1,7 @@ import logging from galaxy import exceptions, model, web +from galaxy.util import string_as_bool log = logging.getLogger( __name__ ) @@ -26,6 +27,7 @@ def api_payload_to_create_params( payload ): collection_type=payload.get( "collection_type" ), element_identifiers=payload.get( "element_identifiers" ), name=payload.get( "name", None ), + hide_source_items=string_as_bool( payload.get( "hide_source_items", False ) ) ) return params diff --git a/test/api/test_history_contents.py b/test/api/test_history_contents.py index 7ef60cb6950..89ada2cc2ce 100644 --- a/test/api/test_history_contents.py +++ b/test/api/test_history_contents.py @@ -161,6 +161,23 @@ class HistoryContentsApiTestCase( api.ApiTestCase, TestsDatasets ): dataset_collection = show_response.json() assert dataset_collection[ "deleted" ] + def test_dataset_collection_hide_originals( self ): + payload = self.dataset_collection_populator.create_pair_payload( + self.history_id, + type="dataset_collection" + ) + + payload["hide_source_items"] = True + dataset_collection_response = self._post( "histories/%s/contents" % self.history_id, payload ) + self.__check_create_collection_response( dataset_collection_response ) + + contents_response = self._get( "histories/%s/contents" % self.history_id ) + datasets = [d for d in contents_response.json() if d["history_content_type"] == "dataset" and d["hid"] in [1, 2]] + # Assert two datasets in source were hidden. + assert len(datasets) == 2 + assert not datasets[0]["visible"] + assert not datasets[1]["visible"] + def test_update_dataset_collection( self ): payload = self.dataset_collection_populator.create_pair_payload( self.history_id,