diff --git a/lib/galaxy/web/controllers/history.py b/lib/galaxy/web/controllers/history.py
index ea4ada07b83..380ff43dc2d 100644
--- a/lib/galaxy/web/controllers/history.py
+++ b/lib/galaxy/web/controllers/history.py
@@ -513,7 +513,6 @@ class HistoryController( BaseController, Sharable, UsesAnnotations, UsesHistory
"""Import another user's history via a shared URL"""
msg = ""
user = trans.get_user()
- user_history = trans.get_history()
# Set referer message
if 'referer' in kwd:
referer = kwd['referer']
@@ -527,11 +526,9 @@ class HistoryController( BaseController, Sharable, UsesAnnotations, UsesHistory
# Do import.
if not id:
return trans.show_error_message( "You must specify a history you want to import.
You can %s." % referer_message, use_panels=True )
- import_history = self.get_history( trans, id, check_ownership=False )
+ import_history = self.get_history( trans, id, check_ownership=False, check_accessible=True )
if not import_history:
return trans.show_error_message( "The specified history does not exist.
You can %s." % referer_message, use_panels=True )
- if not import_history.importable:
- return trans.show_error_message( "The owner of this history has disabled imports via this link.
You can %s." % referer_message, use_panels=True )
if user:
if import_history.user_id == user.id:
return trans.show_error_message( "You cannot import your own history.
You can %s." % referer_message, use_panels=True )
@@ -548,8 +545,8 @@ class HistoryController( BaseController, Sharable, UsesAnnotations, UsesHistory
new_history.add_galaxy_session( galaxy_session, association=association )
trans.sa_session.add( new_history )
trans.sa_session.flush()
- if not user_history.datasets:
- trans.set_history( new_history )
+ # Set imported history to be user's current history.
+ trans.set_history( new_history )
return trans.show_ok_message(
message="""History "%s" has been imported.
You can start using this history or %s."""
% ( new_history.name, web.url_for( '/' ), referer_message ), use_panels=True )
diff --git a/test/functional/test_history_functions.py b/test/functional/test_history_functions.py
index 08b2ca1ed8b..5835a4efef0 100644
--- a/test/functional/test_history_functions.py
+++ b/test/functional/test_history_functions.py
@@ -196,10 +196,15 @@ class TestHistory( TwillTestCase ):
self.disable_access_via_link( self.security.encode_id( history3.id ),
check_str='Anyone can view and import this history',
check_str_after_submit='Make History Accessible via Link' )
- # Try importing history3 after disabling access via link.
+ # Try importing history3 after disabling access via link. To do this, need to login as regular user 2, who cannot access
+ # history via sharing or via link.
+ self.logout()
+ self.login( email=regular_user2.email )
self.import_history_via_url( self.security.encode_id( history3.id ),
admin_user.email,
- check_str_after_submit='The owner of this history has disabled imports via this link.' )
+ check_str_after_submit='History is not accessible to current user' )
+ self.logout()
+ self.login( email=admin_user.email )
# Test sharing history3 with an invalid user
self.share_current_history( 'jack@jill.com',
check_str_after_submit='jack@jill.com is not a valid Galaxy user.' )