From 146ae6bc69f192a83b4649589cc968d32cb26da4 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Thu, 22 May 2025 16:36:26 +0200 Subject: [PATCH] Enable retrieving contents from extra file paths with leading `/` by stripping all leading `/` in filename. I don't think there's a legitimate reason that we should treat this as an absolute path marker. Addresses @luke-c-sargent's comment in https://github.com/goeckslab/tools-mti/pull/99#issuecomment-2864667012 --- lib/galaxy/webapps/galaxy/services/datasets.py | 3 +++ lib/galaxy_test/api/test_datasets.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/galaxy/webapps/galaxy/services/datasets.py b/lib/galaxy/webapps/galaxy/services/datasets.py index e51eb3df1fd..86500c10612 100644 --- a/lib/galaxy/webapps/galaxy/services/datasets.py +++ b/lib/galaxy/webapps/galaxy/services/datasets.py @@ -652,6 +652,9 @@ class DatasetsService(ServiceBase, UsesVisualizationMixin): dataset_manager = self.dataset_manager_by_type[hda_ldda] dataset_instance = dataset_manager.get_accessible(dataset_id, trans.user) dataset_manager.ensure_dataset_on_disk(trans, dataset_instance) + if filename and filename.startswith("/"): + # Path needs to relative to extra files path + filename = filename.lstrip("/") if raw: if filename and filename != "index": object_store = trans.app.object_store diff --git a/lib/galaxy_test/api/test_datasets.py b/lib/galaxy_test/api/test_datasets.py index 57e06a265e0..e5ed6d05974 100644 --- a/lib/galaxy_test/api/test_datasets.py +++ b/lib/galaxy_test/api/test_datasets.py @@ -347,6 +347,22 @@ class TestDatasetsApi(ApiTestCase): self._assert_status_code_is(display_response, 200) assert display_response.text == contents + def test_display_extra_paths(self, history_id: str): + test_data_resolver = TestDataResolver() + with open(test_data_resolver.get_filename("1.fasta")) as fh: + fasta_contents = fh.read() + hda1 = self.dataset_populator.new_dataset(history_id, content=fasta_contents, ftype="fasta", wait=True) + response = self.dataset_populator.run_tool( + "create_directory_index", inputs={"reference": {"src": "hda", "id": hda1["id"]}}, history_id=history_id + ) + self.dataset_populator.wait_for_job(response["jobs"][0]["id"]) + directory_dataset = response["outputs"][0] + display_response = self._get( + f"histories/{history_id}/contents/{directory_dataset['id']}/display?filename=/1.fasta" + ) + display_response.raise_for_status() + assert display_response.text == fasta_contents + def test_display_error_handling(self, history_id): hda1 = self.dataset_populator.create_deferred_hda( history_id, "https://raw.githubusercontent.com/galaxyproject/galaxy/dev/test-data/1.bed"