Display an error message when cookies are blocked between the tool shed and galaxy.

This commit is contained in:
Dave Bouvier
2013-03-20 09:33:34 -04:00
parent bd5636523a
commit feddffdf69
2 changed files with 46 additions and 25 deletions
@@ -317,9 +317,9 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
@web.expose
def browse_valid_categories( self, trans, **kwd ):
# The request came from Galaxy, so restrict category links to display only valid repository changeset revisions.
galaxy_url = kwd.get( 'galaxy_url', None )
galaxy_url = suc.handle_galaxy_url( trans, **kwd )
if galaxy_url:
trans.set_cookie( galaxy_url, name='toolshedgalaxyurl' )
kwd[ 'galaxy_url' ] = galaxy_url
if 'f-free-text-search' in kwd:
if kwd[ 'f-free-text-search' ] == 'All':
# The user performed a search, then clicked the "x" to eliminate the search criteria.
@@ -346,11 +346,14 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
return trans.response.send_redirect( web.url_for( controller='repository',
action='browse_valid_repositories',
**kwd ) )
log.debug("CCC In browse_valid_categories, just before returning valid_category_grid, kwd: %s" % str( kwd ))
return self.valid_category_grid( trans, **kwd )
@web.expose
def browse_valid_repositories( self, trans, **kwd ):
galaxy_url = kwd.get( 'galaxy_url', None )
galaxy_url = suc.handle_galaxy_url( trans, **kwd )
if galaxy_url:
kwd[ 'galaxy_url' ] = galaxy_url
repository_id = kwd.get( 'id', None )
if 'f-free-text-search' in kwd:
if 'f-Category.name' in kwd:
@@ -359,8 +362,6 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
category = suc.get_category_by_name( trans, category_name )
# Set the id value in kwd since it is required by the ValidRepositoryGrid.build_initial_query method.
kwd[ 'id' ] = trans.security.encode_id( category.id )
if galaxy_url:
trans.set_cookie( galaxy_url, name='toolshedgalaxyurl' )
if 'operation' in kwd:
operation = kwd[ 'operation' ].lower()
if operation == "preview_tools_in_changeset":
@@ -423,7 +424,7 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
message = util.restore_text( params.get( 'message', '' ) )
status = params.get( 'status', 'done' )
# If the request originated with the UpdateManager, it will not include a galaxy_url.
galaxy_url = kwd.get( 'galaxy_url', '' )
galaxy_url = suc.handle_galaxy_url( trans, **kwd )
name = params.get( 'name', None )
owner = params.get( 'owner', None )
changeset_revision = params.get( 'changeset_revision', None )
@@ -437,11 +438,14 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
if from_update_manager:
update = 'true'
no_update = 'false'
else:
elif galaxy_url:
# Start building up the url to redirect back to the calling Galaxy instance.
url = suc.url_join( galaxy_url,
'admin_toolshed/update_to_changeset_revision?tool_shed_url=%s&name=%s&owner=%s&changeset_revision=%s&latest_changeset_revision=' % \
( web.url_for( '/', qualified=True ), repository.name, repository.user.username, changeset_revision ) )
else:
message = 'Unable to check for updates due to an invalid Galaxy URL: <b>%s</b>. You may need to enable cookies in your browser. ' % galaxy_url
return trans.show_error_message( message )
if changeset_revision == repository.tip( trans.app ):
# If changeset_revision is the repository tip, there are no additional updates.
if from_update_manager:
@@ -746,9 +750,7 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
params = util.Params( kwd )
message = util.restore_text( params.get( 'message', '' ) )
status = params.get( 'status', 'done' )
galaxy_url = kwd.get( 'galaxy_url', None )
if galaxy_url:
trans.set_cookie( galaxy_url, name='toolshedgalaxyurl' )
galaxy_url = suc.handle_galaxy_url( trans, **kwd )
if 'operation' in kwd:
item_id = kwd.get( 'id', '' )
if item_id:
@@ -833,9 +835,7 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
params = util.Params( kwd )
message = util.restore_text( params.get( 'message', '' ) )
status = params.get( 'status', 'done' )
galaxy_url = kwd.get( 'galaxy_url', None )
if galaxy_url:
trans.set_cookie( galaxy_url, name='toolshedgalaxyurl' )
galaxy_url = suc.handle_galaxy_url( trans, **kwd )
if 'operation' in kwd:
item_id = kwd.get( 'id', '' )
if item_id:
@@ -952,7 +952,6 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
params = util.Params( kwd )
message = util.restore_text( params.get( 'message', '' ) )
status = params.get( 'status', 'done' )
galaxy_url = kwd.get( 'galaxy_url', '' )
name = params.get( 'name', None )
owner = params.get( 'owner', None )
changeset_revision = params.get( 'changeset_revision', None )
@@ -1443,18 +1442,23 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
changeset_revisions = kwd.get( 'changeset_revisions', None )
name = kwd.get( 'name', None )
owner = kwd.get( 'owner', None )
galaxy_url = kwd.get( 'galaxy_url', None )
if not repository_ids:
repository = suc.get_repository_by_name_and_owner( trans.app, name, owner )
repository_ids = trans.security.encode_id( repository.id )
if not galaxy_url:
# If galaxy_url is not in the request, it had to have been stored in a cookie by the tool shed.
galaxy_url = trans.get_cookie( name='toolshedgalaxyurl' )
# Redirect back to local Galaxy to perform install.
url = suc.url_join( galaxy_url,
'admin_toolshed/prepare_for_install?tool_shed_url=%s&repository_ids=%s&changeset_revisions=%s' % \
( web.url_for( '/', qualified=True ), ','.join( util.listify( repository_ids ) ), ','.join( util.listify( changeset_revisions ) ) ) )
return trans.response.send_redirect( url )
galaxy_url = suc.handle_galaxy_url( trans, **kwd )
if galaxy_url:
# Redirect back to local Galaxy to perform install.
url = suc.url_join( galaxy_url,
'admin_toolshed/prepare_for_install?tool_shed_url=%s&repository_ids=%s&changeset_revisions=%s' % \
( web.url_for( '/', qualified=True ), ','.join( util.listify( repository_ids ) ), ','.join( util.listify( changeset_revisions ) ) ) )
return trans.response.send_redirect( url )
else:
message = 'Repository installation is not possible due to an invalid Galaxy URL: <b>%s</b>. You may need to enable cookies in your browser. ' % galaxy_url
status = 'error'
return trans.response.send_redirect( web.url_for( controller='repository',
action='browse_valid_categories',
message=message,
status=status ) )
@web.expose
def load_invalid_tool( self, trans, repository_id, tool_config, changeset_revision, **kwd ):
@@ -1854,8 +1858,6 @@ class RepositoryController( BaseUIController, common_util.ItemRatings ):
params = util.Params( kwd )
message = util.restore_text( params.get( 'message', '' ) )
status = params.get( 'status', 'done' )
# If the request originated with the UpdateManager, it will not include a galaxy_url.
galaxy_url = kwd.get( 'galaxy_url', '' )
name = params.get( 'name', None )
owner = params.get( 'owner', None )
changeset_revision = params.get( 'changeset_revision', None )
+19
View File
@@ -116,6 +116,7 @@ def changeset_is_malicious( trans, id, changeset_revision, **kwd ):
return False
def changeset_is_valid( app, repository, changeset_revision ):
"""Make sure a changeset hash is valid for a specified repository."""
repo = hg.repository( get_configured_ui(), repository.repo_path( app ) )
for changeset in repo.changelog:
changeset_hash = str( repo.changectx( changeset ) )
@@ -124,6 +125,7 @@ def changeset_is_valid( app, repository, changeset_revision ):
return False
def clean_repository_clone_url( repository_clone_url ):
"""Return a URL that can be used to clone a tool shed repository, eliminating the protocol and user if either exists."""
if repository_clone_url.find( '@' ) > 0:
# We have an url that includes an authenticated user, something like:
# http://test@bx.psu.edu:9009/repos/some_username/column
@@ -139,6 +141,7 @@ def clean_repository_clone_url( repository_clone_url ):
return tmp_url
def clean_tool_shed_url( tool_shed_url ):
"""Return a tool shed URL, eliminating the port if it exists."""
if tool_shed_url.find( ':' ) > 0:
# Eliminate the port, if any, since it will result in an invalid directory name.
return tool_shed_url.split( ':' )[ 0 ]
@@ -186,6 +189,10 @@ def copy_file_from_manifest( repo, ctx, filename, dir ):
def create_or_update_tool_shed_repository( app, name, description, installed_changeset_revision, ctx_rev, repository_clone_url, metadata_dict,
status, current_changeset_revision=None, owner='', dist_to_shed=False ):
"""
Update a tool shed repository record i the Galaxy database with the new information received. If a record defined by the received tool shed, repository name
and owner does not exists, create a new record with the received information.
"""
# The received value for dist_to_shed will be True if the InstallManager is installing a repository that contains tools or datatypes that used
# to be in the Galaxy distribution, but have been moved to the main Galaxy tool shed.
log.debug( "Adding new row (or updating an existing row) for repository '%s' in the tool_shed_repository table." % name )
@@ -272,6 +279,7 @@ def generate_sharable_link_for_repository_in_tool_shed( trans, repository, chang
return sharable_url
def generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, tool_section ):
"""Create and return an ElementTree tool Element."""
if tool_section is not None:
tool_elem = SubElement( tool_section, 'tool' )
else:
@@ -429,6 +437,7 @@ def get_configured_ui():
return _ui
def get_ctx_rev( tool_shed_url, name, owner, changeset_revision ):
"""Send a request to the tool shed to retrieve the ctx_rev for a repository defined by the combination of a name, owner and changeset revision."""
url = url_join( tool_shed_url, 'repository/get_ctx_rev?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) )
response = urllib2.urlopen( url )
ctx_rev = response.read()
@@ -448,6 +457,7 @@ def get_ctx_file_path_from_manifest( filename, repo, changeset_revision ):
return None, None
def get_file_context_from_ctx( ctx, filename ):
"""Return the mercurial file context for a specified file."""
# We have to be careful in determining if we found the correct file because multiple files with the same name may be in different directories
# within ctx if the files were moved within the change set. For example, in the following ctx.files() list, the former may have been moved to
# the latter: ['tmap_wrapper_0.0.19/tool_data_table_conf.xml.sample', 'tmap_wrapper_0.3.3/tool_data_table_conf.xml.sample']. Another scenario
@@ -473,6 +483,7 @@ def get_installed_tool_shed_repository( trans, id ):
return trans.sa_session.query( trans.model.ToolShedRepository ).get( trans.security.decode_id( id ) )
def get_named_tmpfile_from_ctx( ctx, filename, dir ):
"""Return a named temporary file created from a specified file with a given name included in a repository changeset revision."""
filename = strip_path( filename )
for ctx_file in ctx.files():
ctx_file_name = strip_path( ctx_file )
@@ -958,6 +969,14 @@ def handle_email_alerts( trans, repository, content_alert_str='', new_repo_alert
except Exception, e:
log.exception( "An error occurred sending a tool shed repository update alert by email." )
def handle_galaxy_url( trans, **kwd ):
galaxy_url = kwd.get( 'galaxy_url', None )
if galaxy_url:
trans.set_cookie( galaxy_url, name='toolshedgalaxyurl' )
else:
galaxy_url = trans.get_cookie( name='toolshedgalaxyurl' )
return galaxy_url
def open_repository_files_folder( trans, folder_path ):
"""Return a list of dictionaries, each of which contains information for a file or directory contained within a directory in a repository file hierarchy."""
try: