commit/galaxy-central: 2 new changesets

2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/ea2a5e240c41/ Changeset: ea2a5e240c41 Branch: next-stable User: carlfeberhard Date: 2013-03-26 00:04:37 Summary: history panel: better bootstrapped history and hda data; UsesHistoryDatasetAssociationMixin: don't try to provide full data for deleted, purged, or non-accessible hda Affected #: 3 files diff -r 388648deecffe1d5d3c46525aabd5b4d55549248 -r ea2a5e240c41c9d58a3982d21af362781db980da lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -334,31 +334,40 @@ 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 @@ 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 ) \ diff -r 388648deecffe1d5d3c46525aabd5b4d55549248 -r ea2a5e240c41c9d58a3982d21af362781db980da lib/galaxy/webapps/galaxy/controllers/root.py --- a/lib/galaxy/webapps/galaxy/controllers/root.py +++ b/lib/galaxy/webapps/galaxy/controllers/root.py @@ -11,7 +11,7 @@ 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 @@ 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, diff -r 388648deecffe1d5d3c46525aabd5b4d55549248 -r ea2a5e240c41c9d58a3982d21af362781db980da templates/webapps/galaxy/root/alternate_history.mako --- a/templates/webapps/galaxy/root/alternate_history.mako +++ b/templates/webapps/galaxy/root/alternate_history.mako @@ -90,7 +90,7 @@ <% 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 @@ ## 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 @@ %></%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 @@ 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 https://bitbucket.org/galaxy/galaxy-central/commits/5b7bc81c3fc7/ Changeset: 5b7bc81c3fc7 User: carlfeberhard Date: 2013-03-26 00:05:30 Summary: merge next-stable Affected #: 3 files diff -r b437eece023175a6ac8ea87f7a4dae6582ad7892 -r 5b7bc81c3fc7712894a1ff1bd75476259bf6c591 lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -334,31 +334,40 @@ 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 @@ 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 ) \ diff -r b437eece023175a6ac8ea87f7a4dae6582ad7892 -r 5b7bc81c3fc7712894a1ff1bd75476259bf6c591 lib/galaxy/webapps/galaxy/controllers/root.py --- a/lib/galaxy/webapps/galaxy/controllers/root.py +++ b/lib/galaxy/webapps/galaxy/controllers/root.py @@ -11,7 +11,7 @@ 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 @@ 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, diff -r b437eece023175a6ac8ea87f7a4dae6582ad7892 -r 5b7bc81c3fc7712894a1ff1bd75476259bf6c591 templates/webapps/galaxy/root/alternate_history.mako --- a/templates/webapps/galaxy/root/alternate_history.mako +++ b/templates/webapps/galaxy/root/alternate_history.mako @@ -90,7 +90,7 @@ <% 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 @@ ## 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 @@ %></%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 @@ 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 Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org