Skip to content

Commit

Permalink
Use url_for() to generate dataset URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Apr 21, 2020
1 parent 5218bd9 commit d295750
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/galaxy/webapps/galaxy/api/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,9 @@ def export_invocation_bco(self, trans, invocation_id, **kwd):

# may want to extend this to have more reviewers.
reviewing_users = [stored_workflow.user]
workflow_encoded_id = trans.security.encode_id(stored_workflow.id)
history_encoded_id = trans.security.encode_id(history.id)
dict_workflow = json.loads(self.workflow_dict(trans, workflow_encoded_id))
encoded_workflow_id = trans.security.encode_id(stored_workflow.id)
encoded_history_id = trans.security.encode_id(history.id)
dict_workflow = json.loads(self.workflow_dict(trans, encoded_workflow_id))

# h_contents = self.history_contents_manager.contained(history)

Expand All @@ -1016,7 +1016,7 @@ def export_invocation_bco(self, trans, invocation_id, **kwd):

# listing the versions of the workflow for 'version' and 'derived_from'
versions = []
workflow_versions = self.workflow_manager.get_stored_accessible_workflow(trans, workflow_encoded_id)
workflow_versions = self.workflow_manager.get_stored_accessible_workflow(trans, encoded_workflow_id)
for i, w in enumerate(reversed(workflow_versions.workflows)):
version = {
'version': i,
Expand Down Expand Up @@ -1059,7 +1059,7 @@ def export_invocation_bco(self, trans, invocation_id, **kwd):
'name': workflow.name,
'version': current_version,
'review': reviewers,
'derived_from': url_for('workflow', id=workflow_encoded_id, qualified=True),
'derived_from': url_for('workflow', id=encoded_workflow_id, qualified=True),
'created': workflow_invocation.create_time.isoformat(),
'modified': workflow_invocation.update_time.isoformat(),
'contributors': contributors,
Expand All @@ -1073,10 +1073,7 @@ def export_invocation_bco(self, trans, invocation_id, **kwd):
if tag.user_tname not in keywords:
keywords.append(tag.user_tname)

host = 'https://localhost:8080'
input_subdomain, output_subdomain, pipeline_steps, software_prerequisites = [], [], [], []
# Which `url_for` function option would generate this format below?
url_format = '{}/api/histories/{}/contents/{}'
for i, step in enumerate(workflow_invocation.steps):
current_tool = dict_workflow['steps'][str(i)]
if step.workflow_step.type == 'tool':
Expand All @@ -1086,20 +1083,20 @@ def export_invocation_bco(self, trans, invocation_id, **kwd):
for job in step.jobs:
for job_input in job.input_datasets:
if hasattr(job_input.dataset, 'dataset_id'):
inputobj = trans.security.encode_id(job_input.dataset.dataset_id)
encoded_dataset_id = trans.security.encode_id(job_input.dataset.dataset_id)
input_obj = {
'filename': job_input.dataset.name,
'uri': url_format.format(host, history_encoded_id, inputobj),
'uri': url_for('history_content', history_id=encoded_history_id, id=encoded_dataset_id, qualified=True),
'access_time': job_input.dataset.create_time.isoformat(),
}
input_list.append(input_obj)

for job_output in job.output_datasets:
if hasattr(job_output.dataset, 'dataset_id'):
outobj = trans.security.encode_id(job_output.dataset.dataset_id)
encoded_dataset_id = trans.security.encode_id(job_output.dataset.dataset_id)
output_obj = {
'filename': job_output.dataset.name,
'uri': url_format.format(host, history_encoded_id, outobj),
'uri': url_for('history_content', history_id=encoded_history_id, id=encoded_dataset_id, qualified=True),
'access_time': job_output.dataset.create_time.isoformat(),
}
output_list.append(output_obj)
Expand All @@ -1109,7 +1106,7 @@ def export_invocation_bco(self, trans, invocation_id, **kwd):
'mediatype': job_output.dataset.extension,
'uri': {
'filename': job_output.dataset.name,
'uri': url_format.format(host, history_encoded_id, outobj) ,
'uri': url_for('history_content', history_id=encoded_history_id, id=encoded_dataset_id, qualified=True),
'access_time': job_output.dataset.create_time.isoformat(),
}
}
Expand Down Expand Up @@ -1158,7 +1155,7 @@ def export_invocation_bco(self, trans, invocation_id, **kwd):

execution_domain = {
'script_access_type': 'a_galaxy_workflow',
'script': [url_for('workflows', encoded_workflow_id=workflow_encoded_id)],
'script': [url_for('workflows', encoded_workflow_id=encoded_workflow_id)],
'script_driver': 'Galaxy',
'software_prerequisites': software_prerequisites,
'external_data_endpoints': [],
Expand Down

0 comments on commit d295750

Please sign in to comment.