From 6dcf593af801f37685322f17ec220113d088d40b Mon Sep 17 00:00:00 2001 From: Jeremy Goecks Date: Mon, 3 May 2010 16:32:35 -0400 Subject: [PATCH] Enable users not logged in to view a shared/accessible/published visualization. --- lib/galaxy/web/base/controller.py | 3 ++- lib/galaxy/web/controllers/tracks.py | 21 ++++++++++++++------- lib/galaxy/web/framework/__init__.py | 5 +++++ templates/tracks/browser.mako | 2 +- templates/visualization/display.mako | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/web/base/controller.py b/lib/galaxy/web/base/controller.py index 2a2c45ab096..50538cc43df 100644 --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -208,7 +208,8 @@ class UsesVisualization( SharableItemSecurity ): if dbkey is None: dbkey = dataset.dbkey # Hack for backward compat ## TODO: chrom needs to be able to be set; right now it's empty. - config = { "title": visualization.title, "vis_id": id, "tracks": tracks, "chrom": "", "dbkey": dbkey } + config = { "title": visualization.title, "vis_id": trans.security.encode_id( visualization.id ), + "tracks": tracks, "chrom": "", "dbkey": dbkey } return config diff --git a/lib/galaxy/web/controllers/tracks.py b/lib/galaxy/web/controllers/tracks.py index bfe2e1fce80..d7efcb9b330 100644 --- a/lib/galaxy/web/controllers/tracks.py +++ b/lib/galaxy/web/controllers/tracks.py @@ -72,7 +72,7 @@ class DatasetSelectionGrid( grids.Grid ): .filter( model.HistoryDatasetAssociation.extension.in_(self.available_tracks) ) \ .filter( model.Dataset.state != "error") -class TracksController( BaseController ): +class TracksController( BaseController, UsesVisualization ): """ Controller for track browser interface. Handles building a new browser from datasets in the current history, and display of the resulting browser. @@ -158,8 +158,7 @@ class TracksController( BaseController ): return trans.fill_template( 'tracks/browser.mako', config=config ) @web.json - @web.require_login() - def chroms(self, trans, dbkey=None ): + def chroms(self, trans, vis_id=None ): """ Returns a naturally sorted list of chroms/contigs for the given dbkey """ @@ -171,18 +170,26 @@ class TracksController( BaseController ): def split_by_number(s): return [ check_int(c) for c in re.split('([0-9]+)', s) ] - - chroms = self._chroms( trans, dbkey ) + + # Get visualization and config. + visualization = self.get_visualization( trans, vis_id, check_ownership=False, check_accessible=True ) + visualization.config = self.get_visualization_config( trans, visualization ) + if visualization is None: + raise web.httpexceptions.HTTPNotFound() + + # Get chroms data. + chroms = self._chroms( trans, visualization ) to_sort = [{ 'chrom': chrom, 'len': length } for chrom, length in chroms.iteritems()] to_sort.sort(lambda a,b: cmp( split_by_number(a['chrom']), split_by_number(b['chrom']) )) return to_sort - def _chroms( self, trans, dbkey ): + def _chroms( self, trans, visualization ): """ Called by the browser to get a list of valid chromosomes and lengths """ # If there is any dataset in the history of extension `len`, this will use it - user = trans.get_user() + user = visualization.user + dbkey = visualization.config['dbkey'] if 'dbkeys' in user.preferences: user_keys = from_json_string( user.preferences['dbkeys'] ) if dbkey in user_keys: diff --git a/lib/galaxy/web/framework/__init__.py b/lib/galaxy/web/framework/__init__.py index 8b2b5a4c7e5..a39c5709c84 100644 --- a/lib/galaxy/web/framework/__init__.py +++ b/lib/galaxy/web/framework/__init__.py @@ -675,6 +675,11 @@ class UniverseWebTransaction( base.DefaultWebTransaction ): """ Returns the db_file dataset associated/needed by `dataset`, or `None`. """ + + # If no history, return None. + if self.history is None: + return None + datasets = self.sa_session.query( self.app.model.HistoryDatasetAssociation ) \ .filter_by( deleted=False, history_id=self.history.id, extension="len" ) for ds in datasets: diff --git a/templates/tracks/browser.mako b/templates/tracks/browser.mako index f3b00c0766b..4167db7209a 100644 --- a/templates/tracks/browser.mako +++ b/templates/tracks/browser.mako @@ -272,7 +272,7 @@ ${h.js( 'galaxy.base', 'galaxy.panels', "json2", "jquery", "jquery.event.drag", $.ajax({ url: "${h.url_for( action='chroms' )}", - data: { dbkey: view.dbkey }, + data: { vis_id: view.vis_id }, dataType: "json", success: function ( data ) { view.chrom_data = data; diff --git a/templates/visualization/display.mako b/templates/visualization/display.mako index 0bad2d19420..be7be4611cb 100644 --- a/templates/visualization/display.mako +++ b/templates/visualization/display.mako @@ -124,7 +124,7 @@ $.ajax({ ## JG: added controller name url: "${h.url_for( controller='/tracks', action='chroms' )}", - data: { dbkey: view.dbkey }, + data: { vis_id: view.vis_id }, dataType: "json", success: function ( data ) { view.chrom_data = data;