Skip to content

Commit

Permalink
History, UI: use id of displayed history in delete
Browse files Browse the repository at this point in the history
- Refactor `delete current` to `delete` and require an id arg.
- Update history options menu to pass the id of the displayed/
current history to the above delete controller endpoint.

This means that the current history panel will delete the history
that's displayed (instead of potentially a different history that's
been set to the current history on the server side).

Note: this isn't an ideal refactoring but should solve the below
issue temporarily until we move more of the session state out of
API.

Closes #894
  • Loading branch information
carlfeberhard committed Jul 25, 2016
1 parent 5e49868 commit 2b4a855
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 84 deletions.
16 changes: 12 additions & 4 deletions client/galaxy/scripts/mvc/history/options-menu.js
Expand Up @@ -59,15 +59,23 @@ var menu = [
},
{
html : _l( 'Delete' ),
confirm : _l( 'Really delete the current history?' ),
href : 'history/delete_current',
anon : true,
func : function() {
if( Galaxy && Galaxy.currHistoryPanel && confirm( _l( 'Really delete the current history?' ) ) ){
galaxy_main.window.location.href = 'history/delete?id=' + Galaxy.currHistoryPanel.model.id;
}
},
},
{
html : _l( 'Delete Permanently' ),
confirm : _l( 'Really delete the current history permanently? This cannot be undone.' ),
href : 'history/delete_current?purge=True',
purge : true,
anon : true,
func : function() {
if( Galaxy && Galaxy.currHistoryPanel
&& confirm( _l( 'Really delete the current history permanently? This cannot be undone.' ) ) ){
galaxy_main.window.location.href = 'history/delete?purge=True&id=' + Galaxy.currHistoryPanel.model.id;
}
},
},


Expand Down
77 changes: 29 additions & 48 deletions lib/galaxy/webapps/galaxy/controllers/history.py
Expand Up @@ -1122,55 +1122,36 @@ def purge_deleted_datasets( self, trans ):
count += 1
return trans.show_ok_message( "%d datasets have been deleted permanently" % count, refresh_frames=['history'] )

# TODO: use api instead
@web.expose
def delete_current( self, trans, purge=False ):
"""Delete just the active history -- this does not require a logged in user."""
history = trans.get_history()
if history.users_shared_with:
return trans.show_error_message( "History (%s) has been shared with others, unshare it before deleting it. " % history.name )
if not history.deleted:
history.deleted = True
trans.sa_session.add( history )
trans.sa_session.flush()
trans.log_event( "History id %d marked as deleted" % history.id )
if purge and trans.app.config.allow_user_dataset_purge:
for hda in history.datasets:
if trans.user:
trans.user.adjust_total_disk_usage(-hda.quota_amount(trans.user))
hda.purged = True
trans.sa_session.add( hda )
trans.log_event( "HDA id %s has been purged" % hda.id )
trans.sa_session.flush()
if hda.dataset.user_can_purge:
try:
hda.dataset.full_delete()
trans.log_event( "Dataset id %s has been purged upon the the purge of HDA id %s" % ( hda.dataset.id, hda.id ) )
trans.sa_session.add( hda.dataset )
except:
log.exception( 'Unable to purge dataset (%s) on purge of hda (%s):' % ( hda.dataset.id, hda.id ) )
history.purged = True
self.sa_session.add( history )
self.sa_session.flush()
for hda in history.datasets:
# Not all datasets have jobs associated with them (e.g., datasets imported from libraries).
if hda.creating_job_associations:
# HDA has associated job, so try marking it deleted.
job = hda.creating_job_associations[0].job
if job.history_id == history.id and not job.finished:
# No need to check other outputs since the job's parent history is this history
job.mark_deleted( trans.app.config.track_jobs_in_database )
trans.app.job_manager.job_stop_queue.put( job.id )

# Regardless of whether it was previously deleted, get the most recent history or create a new one.
most_recent_history = self.history_manager.most_recent( user=trans.user )
if most_recent_history:
trans.set_history( most_recent_history )
return trans.show_ok_message( "History deleted, your most recent history is now active",
refresh_frames=['history'] )

trans.get_or_create_default_history()
return trans.show_ok_message( "History deleted, a new history is active", refresh_frames=['history'] )
def delete( self, trans, id, purge=False ):
"""Delete the history -- this does not require a logged in user."""
# TODO: use api instead
try:
# get the history with the given id, delete and optionally purge
current_history = self.history_manager.get_current( trans )
history = self.history_manager.get_owned( self.decode_id( id ), trans.user, current_history=current_history )
if history.users_shared_with:
raise exceptions.ObjectAttributeInvalidException(
"History has been shared with others. Unshare it before deleting it."
)
self.history_manager.delete( history, flush=( not purge ) )
if purge:
self.history_manager.purge( history )

# if this history is the current history for this session,
# - attempt to find the most recently used, undeleted history and switch to it.
# - If no suitable recent history is found, create a new one and switch
if history == current_history:
most_recent_history = self.history_manager.most_recent(
filters=[ model.History.deleted == false() ], user=trans.user )
if most_recent_history:
self.history_manager.set_current( trans, most_recent_history )
else:
trans.get_or_create_default_history()

except Exception as exc:
return trans.show_error_message( exc )
return trans.show_ok_message( "History deleted", refresh_frames=['history'] )

@web.expose
def resume_paused_jobs( self, trans, current=False, ids=None ):
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/history/options-menu.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions static/scripts/bundled/analysis.bundled.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/bundled/analysis.bundled.js.map

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions static/scripts/bundled/libs.bundled.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/bundled/libs.bundled.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/mvc/history/options-menu.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b4a855

Please sign in to comment.