From 324ec35c86c7444b628e301affe1d918f1a2d71f Mon Sep 17 00:00:00 2001 From: anuprulez Date: Tue, 1 Aug 2017 16:23:11 +0200 Subject: [PATCH] Restoring the get configure menu api and decode ids --- lib/galaxy/webapps/galaxy/api/workflows.py | 38 ++++++++++++++-------- lib/galaxy/webapps/galaxy/buildapp.py | 1 + 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/workflows.py b/lib/galaxy/webapps/galaxy/api/workflows.py index 4696c4c4159..c422e138097 100644 --- a/lib/galaxy/webapps/galaxy/api/workflows.py +++ b/lib/galaxy/webapps/galaxy/api/workflows.py @@ -56,6 +56,19 @@ class WorkflowsAPIController(BaseAPIController, UsesStoredWorkflowMixin, UsesAnn """ return self.get_workflows_list( trans, kwd ) + @expose_api + def get_workflow_menu( self, trans, **kwd ): + """ + Get workflows present in the tools panel + GET /api/workflows/menu + """ + user = trans.get_user() + ids_in_menu = [ x.stored_workflow_id for x in user.stored_workflow_menu_entries ] + return { + 'ids_in_menu': ids_in_menu, + 'workflows': self.get_workflows_list( trans, kwd ) + } + @expose_api def set_workflow_menu( self, trans, **kwd ): """ @@ -69,6 +82,10 @@ class WorkflowsAPIController(BaseAPIController, UsesStoredWorkflowMixin, UsesAnn workflow_ids = [] elif type( workflow_ids ) != list: workflow_ids = [ workflow_ids ] + workflow_ids_decoded = [] + # Decode the encoded workflow ids + for ids in workflow_ids: + workflow_ids_decoded.append( trans.security.decode_id( ids ) ) sess = trans.sa_session # This explicit remove seems like a hack, need to figure out # how to make the association do it automatically. @@ -78,19 +95,14 @@ class WorkflowsAPIController(BaseAPIController, UsesStoredWorkflowMixin, UsesAnn q = sess.query( model.StoredWorkflow ) # To ensure id list is unique seen_workflow_ids = set() - for wf_id in workflow_ids: - for item in q: - # Encode the original id and compare it against the encoded ids - # coming from the UI to save for workflow menu in tools - if wf_id == trans.security.encode_id( item.id ): - if item.id in seen_workflow_ids: - continue - else: - seen_workflow_ids.add( item.id ) - m = model.StoredWorkflowMenuEntry() - m.stored_workflow = q.get( item.id ) - user.stored_workflow_menu_entries.append( m ) - break + for wf_id in workflow_ids_decoded: + if wf_id in seen_workflow_ids: + continue + else: + seen_workflow_ids.add( wf_id ) + m = model.StoredWorkflowMenuEntry() + m.stored_workflow = q.get( wf_id ) + user.stored_workflow_menu_entries.append( m ) sess.flush() message = "Menu updated." trans.set_message( message ) diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index fbdcbc4d821..510ee0d9406 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -301,6 +301,7 @@ def populate_api_routes( webapp, app ): webapp.mapper.connect( '/api/genomes/{id}/sequences', controller='genomes', action='sequences' ) webapp.mapper.resource( 'visualization', 'visualizations', path_prefix='/api' ) webapp.mapper.connect( '/api/workflows/build_module', action='build_module', controller="workflows" ) + webapp.mapper.connect( '/api/workflows/menu', action='get_workflow_menu', controller="workflows", conditions=dict( method=[ "GET" ] ) ) webapp.mapper.connect( '/api/workflows/menu', action='set_workflow_menu', controller="workflows", conditions=dict( method=[ "PUT" ] ) ) webapp.mapper.resource( 'workflow', 'workflows', path_prefix='/api' ) webapp.mapper.resource_with_deleted( 'history', 'histories', path_prefix='/api' )