mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Restoring the get configure menu api and decode ids
This commit is contained in:
@@ -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 )
|
||||
|
||||
@@ -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' )
|
||||
|
||||
Reference in New Issue
Block a user