mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-31 10:32:11 +08:00
history panel: better bootstrapped history and hda data; UsesHistoryDatasetAssociationMixin: don't try to provide full data for deleted, purged, or non-accessible hda
This commit is contained in:
@@ -334,31 +334,40 @@ class UsesHistoryDatasetAssociationMixin:
|
||||
def get_hda_dict( self, trans, hda ):
|
||||
hda_dict = hda.get_api_value( view='element' )
|
||||
history = hda.history
|
||||
hda_dict[ 'api_type' ] = "file"
|
||||
|
||||
# Add additional attributes that depend on trans can hence must be added here rather than at the model level.
|
||||
can_access_hda = trans.app.security_agent.can_access_dataset( trans.get_current_user_roles(), hda.dataset )
|
||||
can_access_hda = ( trans.user_is_admin() or can_access_hda )
|
||||
hda_dict[ 'accessible' ] = can_access_hda
|
||||
|
||||
# return here if deleted and purged or can't access
|
||||
purged = ( hda.purged or hda.dataset.purged )
|
||||
if ( hda.deleted and purged ) or not can_access_hda:
|
||||
return trans.security.encode_dict_ids( hda_dict )
|
||||
|
||||
if trans.user_is_admin() or trans.app.config.expose_dataset_path:
|
||||
hda_dict[ 'file_name' ] = hda.file_name
|
||||
|
||||
if not hda_dict[ 'deleted' ]:
|
||||
hda_dict[ 'download_url' ] = url_for( 'history_contents_display', history_id = trans.security.encode_id( history.id ),
|
||||
history_content_id = trans.security.encode_id( hda.id ) )
|
||||
hda_dict[ 'download_url' ] = url_for( 'history_contents_display',
|
||||
history_id = trans.security.encode_id( history.id ),
|
||||
history_content_id = trans.security.encode_id( hda.id ) )
|
||||
|
||||
can_access_hda = trans.app.security_agent.can_access_dataset( trans.get_current_user_roles(), hda.dataset )
|
||||
hda_dict[ 'accessible' ] = ( trans.user_is_admin() or can_access_hda )
|
||||
hda_dict[ 'api_type' ] = "file"
|
||||
|
||||
if not( hda.purged or hda.deleted or hda.dataset.purged ):
|
||||
meta_files = []
|
||||
for meta_type in hda.metadata.spec.keys():
|
||||
if isinstance( hda.metadata.spec[ meta_type ].param, FileParameter ):
|
||||
meta_files.append( dict( file_type=meta_type ) )
|
||||
if meta_files:
|
||||
hda_dict[ 'meta_files' ] = meta_files
|
||||
meta_files = []
|
||||
for meta_type in hda.metadata.spec.keys():
|
||||
if isinstance( hda.metadata.spec[ meta_type ].param, FileParameter ):
|
||||
meta_files.append( dict( file_type=meta_type ) )
|
||||
if meta_files:
|
||||
hda_dict[ 'meta_files' ] = meta_files
|
||||
|
||||
hda_dict[ 'display_apps' ] = self.get_display_apps( trans, hda )
|
||||
hda_dict[ 'display_types' ] = self.get_old_display_applications( trans, hda )
|
||||
hda_dict[ 'visualizations' ] = hda.get_visualizations()
|
||||
|
||||
# return here if deleted
|
||||
if hda.deleted and not purged:
|
||||
return trans.security.encode_dict_ids( hda_dict )
|
||||
|
||||
if hda.creating_job and hda.creating_job.tool_id:
|
||||
tool_used = trans.app.toolbox.get_tool( hda.creating_job.tool_id )
|
||||
if tool_used and tool_used.force_history_refresh:
|
||||
@@ -813,7 +822,6 @@ class UsesHistoryMixin( SharableItemSecurityMixin ):
|
||||
history = self.get_object( trans, id, 'History', check_ownership=check_ownership, check_accessible=check_accessible, deleted=deleted )
|
||||
return self.security_check( trans, history, check_ownership, check_accessible )
|
||||
|
||||
|
||||
def get_history_datasets( self, trans, history, show_deleted=False, show_hidden=False, show_purged=False ):
|
||||
""" Returns history's datasets. """
|
||||
query = trans.sa_session.query( trans.model.HistoryDatasetAssociation ) \
|
||||
|
||||
@@ -11,7 +11,7 @@ from galaxy.model.item_attrs import UsesAnnotations
|
||||
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
class RootController( BaseUIController, UsesHistoryMixin, UsesAnnotations ):
|
||||
class RootController( BaseUIController, UsesHistoryMixin, UsesHistoryDatasetAssociationMixin, UsesAnnotations ):
|
||||
|
||||
@web.expose
|
||||
def default(self, trans, target1=None, target2=None, **kwd):
|
||||
@@ -130,8 +130,39 @@ class RootController( BaseUIController, UsesHistoryMixin, UsesAnnotations ):
|
||||
|
||||
else:
|
||||
# get all datasets server-side, client-side will get flags and render appropriately
|
||||
datasets = self.get_history_datasets( trans, history,
|
||||
show_deleted=True, show_hidden=True, show_purged=True )
|
||||
hdas = self.get_history_datasets( trans, history,
|
||||
show_deleted=True, show_hidden=True, show_purged=True )
|
||||
|
||||
#TODO: would be good to re-use the hdas above to get the history data...
|
||||
history_dictionary = self.get_history_dict( trans, history )
|
||||
|
||||
#TODO: blech - all here for now - duplication of hist. contents, index
|
||||
hda_dictionaries = []
|
||||
for hda in hdas:
|
||||
try:
|
||||
hda_dictionaries.append( self.get_hda_dict( trans, hda ) )
|
||||
|
||||
except Exception, exc:
|
||||
# don't fail entire list if hda err's, record and move on
|
||||
# (making sure http recvr knows it's err'd)
|
||||
encoded_hda_id = trans.security.encode_id( hda.id )
|
||||
log.error( "Error in history API at listing contents with history %s, hda %s: (%s) %s",
|
||||
history_dictionary[ 'id' ], encoded_hda_id, type( exc ), str( exc ) )
|
||||
return_val = {
|
||||
'id' : encoded_hda_id,
|
||||
'name' : hda.name,
|
||||
'hid' : hda.hid,
|
||||
'history_id': history_dictionary[ 'id' ],
|
||||
'state' : trans.model.Dataset.states.ERROR,
|
||||
'visible' : True,
|
||||
'misc_info' : str( exception ),
|
||||
'misc_blurb': 'Failed to retrieve dataset information.',
|
||||
'error' : str( exception )
|
||||
}
|
||||
hda_dictionaries.append( return_val )
|
||||
|
||||
history = history_dictionary
|
||||
datasets = hda_dictionaries
|
||||
|
||||
return trans.stream_template_mako( history_panel_template,
|
||||
history = history,
|
||||
|
||||
@@ -90,7 +90,7 @@ ${ h.to_json_string( dict([ ( string, _(string) ) for string in strings_to_local
|
||||
<%
|
||||
from urllib import unquote_plus
|
||||
|
||||
history_class_name = history.__class__.__name__
|
||||
history_class_name = 'History'
|
||||
encoded_id_template = '<%= id %>'
|
||||
|
||||
url_dict = {
|
||||
@@ -189,12 +189,9 @@ ${ unquote_plus( h.to_json_string( url_dict ) ) }
|
||||
## I'd rather do without these (esp. the get_hdas which hits the db twice)
|
||||
## but we'd need a common map producer (something like get_api_value but more complete)
|
||||
##TODO: api/web controllers should use common code, and this section should call that code
|
||||
<%def name="get_history( id )">
|
||||
<%def name="get_history( history )">
|
||||
<%
|
||||
history_json = trans.webapp.api_controllers[ 'histories' ].show( trans, trans.security.encode_id( id ) )
|
||||
#assert isinstance( history, dict ), (
|
||||
# 'Bootstrapped history was expecting a dictionary: %s' %( str( history ) ) )
|
||||
return history_json
|
||||
return h.to_json_string( history )
|
||||
%>
|
||||
</%def>
|
||||
|
||||
@@ -207,16 +204,9 @@ ${ unquote_plus( h.to_json_string( url_dict ) ) }
|
||||
%>
|
||||
</%def>
|
||||
|
||||
<%def name="get_hdas( history_id, hdas )">
|
||||
<%def name="get_hdas( hdas )">
|
||||
<%
|
||||
#BUG: one inaccessible dataset will error entire list
|
||||
if not hdas:
|
||||
return '[]'
|
||||
# rather just use the history.id (wo the datasets), but...
|
||||
hda_json = trans.webapp.api_controllers[ 'history_contents' ].index(
|
||||
trans, trans.security.encode_id( history_id ),
|
||||
ids=( ','.join([ trans.security.encode_id( hda.id ) for hda in hdas ]) ) )
|
||||
return hda_json
|
||||
return h.to_json_string( hdas )
|
||||
%>
|
||||
</%def>
|
||||
|
||||
@@ -324,8 +314,8 @@ $(function(){
|
||||
page_show_hidden = ${ 'true' if show_hidden == True else ( 'null' if show_hidden == None else 'false' ) },
|
||||
|
||||
user = ${ get_current_user() },
|
||||
history = ${ get_history( history.id ) },
|
||||
hdas = ${ get_hdas( history.id, datasets ) };
|
||||
history = ${ get_history( history ) },
|
||||
hdas = ${ get_hdas( datasets ) };
|
||||
|
||||
// add user data to history
|
||||
// i don't like this history+user relationship, but user authentication changes views/behaviour
|
||||
|
||||
Reference in New Issue
Block a user