def manage_data_manager(self, trans, **kwd): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape(kwd.get('message', '')) status = escape(kwd.get('status', 'info')) data_manager_id = kwd.get('id', None) data_manager = trans.app.data_managers.get_manager(data_manager_id) if data_manager is None: return trans.response.send_redirect( web.url_for(controller="data_manager", action="index", message="Invalid Data Manager (%s) was requested" % data_manager_id, status="error")) jobs = list( reversed([ assoc.job for assoc in trans.sa_session.query( trans.app.model.DataManagerJobAssociation).filter_by( data_manager_id=data_manager_id) ])) return trans.fill_template("data_manager/manage_data_manager.mako", data_manager=data_manager, jobs=jobs, view_only=not_is_admin, message=message, status=status)
def index( self, trans, **kwd ): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape( kwd.get( 'message', '' ) ) status = escape( kwd.get( 'status', 'info' ) ) return trans.fill_template( "data_manager/index.mako", data_managers=trans.app.data_managers, tool_data_tables=trans.app.tool_data_tables, view_only=not_is_admin, message=message, status=status )
def manage_data_table(self, trans, **kwd): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape(kwd.get('message', '')) status = escape(kwd.get('status', 'info')) data_table_name = kwd.get('table_name', None) if not data_table_name: return trans.response.send_redirect( web.url_for(controller="data_manager", action="index")) data_table = trans.app.tool_data_tables.get(data_table_name, None) if data_table is None: return trans.response.send_redirect( web.url_for(controller="data_manager", action="index", message="Invalid Data table (%s) was requested" % data_table_name, status="error")) return trans.fill_template("data_manager/manage_data_table.mako", data_table=data_table, view_only=not_is_admin, message=message, status=status)
def index( self, trans, **kwd ): message = escape( kwd.get( 'message', '' ) ) status = escape( kwd.get( 'status', 'done' ) ) default_action = kwd.get( 'default_action', None ) return trans.fill_template( "/library/index.mako", default_action=default_action, message=message, status=status )
def index(self, trans, **kwd): message = escape(kwd.get('message', '')) status = escape(kwd.get('status', 'done')) default_action = kwd.get('default_action', None) return trans.fill_template("/library/index.mako", default_action=default_action, message=message, status=status)
def manage_data_manager( self, trans, **kwd ): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape( kwd.get( 'message', '' ) ) status = escape( kwd.get( 'status', 'info' ) ) data_manager_id = kwd.get( 'id', None ) data_manager = trans.app.data_managers.get_manager( data_manager_id ) if data_manager is None: return trans.response.send_redirect( web.url_for( controller="data_manager", action="index", message="Invalid Data Manager (%s) was requested" % data_manager_id, status="error" ) ) jobs = list( reversed( [ assoc.job for assoc in trans.sa_session.query( trans.app.model.DataManagerJobAssociation ).filter_by( data_manager_id=data_manager_id ) ] ) ) return trans.fill_template( "data_manager/manage_data_manager.mako", data_manager=data_manager, jobs=jobs, view_only=not_is_admin, message=message, status=status )
def manage_data_table( self, trans, **kwd ): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape( kwd.get( 'message', '' ) ) status = escape( kwd.get( 'status', 'info' ) ) data_table_name = kwd.get( 'table_name', None ) if not data_table_name: return trans.response.send_redirect( web.url_for( controller="data_manager", action="index" ) ) data_table = trans.app.tool_data_tables.get( data_table_name, None ) if data_table is None: return trans.response.send_redirect( web.url_for( controller="data_manager", action="index", message="Invalid Data table (%s) was requested" % data_table_name, status="error" ) ) return trans.fill_template( "data_manager/manage_data_table.mako", data_table=data_table, view_only=not_is_admin, message=message, status=status )
def view_job( self, trans, **kwd ): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape( kwd.get( 'message', '' ) ) status = escape( kwd.get( 'status', 'info' ) ) job_id = kwd.get( 'id', None ) try: job_id = trans.security.decode_id( job_id ) job = trans.sa_session.query( trans.app.model.Job ).get( job_id ) except Exception, e: job = None log.error( "Bad job id (%s) passed to view_job: %s" % ( job_id, e ) )
def index(self, trans, **kwd): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape(kwd.get('message', '')) status = escape(kwd.get('status', 'info')) return trans.fill_template("data_manager/index.mako", data_managers=trans.app.data_managers, tool_data_tables=trans.app.tool_data_tables, view_only=not_is_admin, message=message, status=status)
def view_job(self, trans, **kwd): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape(kwd.get('message', '')) status = escape(kwd.get('status', 'info')) job_id = kwd.get('id', None) try: job_id = trans.security.decode_id(job_id) job = trans.sa_session.query(trans.app.model.Job).get(job_id) except Exception, e: job = None log.error("Bad job id (%s) passed to view_job: %s" % (job_id, e))
def imp( self, trans, id ): """ Import a visualization into user's workspace. """ # Set referer message. referer = trans.request.referer if referer is not "": referer_message = "<a href='%s'>return to the previous page</a>" % escape(referer) else: referer_message = "<a href='%s'>go to Galaxy's start page</a>" % web.url_for( '/' ) # Do import. session = trans.sa_session visualization = self.get_visualization( trans, id, check_ownership=False ) if visualization.importable == False: return trans.show_error_message( "The owner of this visualization has disabled imports via this link.<br>You can %s" % referer_message, use_panels=True ) elif visualization.deleted: return trans.show_error_message( "You can't import this visualization because it has been deleted.<br>You can %s" % referer_message, use_panels=True ) else: # Create imported visualization via copy. # TODO: need to handle custom db keys. imported_visualization = visualization.copy( user=trans.user, title="imported: " + visualization.title ) # Persist session = trans.sa_session session.add( imported_visualization ) session.flush() # Redirect to load galaxy frames. return trans.show_ok_message( message="""Visualization "%s" has been imported. <br>You can <a href="%s">start using this visualization</a> or %s.""" % ( visualization.title, web.url_for( controller='visualization' ), referer_message ), use_panels=True )
def data_source_redirect( self, trans, tool_id=None ): """ Redirects a user accessing a Data Source tool to its target action link. This method will subvert mix-mode content blocking in several browsers when accessing non-https data_source tools from an https galaxy server. Tested as working on Safari 7.0 and FireFox 26 Subverting did not work on Chrome 31 """ if tool_id is None: return trans.response.send_redirect( url_for( controller="root", action="welcome" ) ) tool_version_select_field, tools, tool = self.__get_tool_components( tool_id, tool_version=None, get_loaded_tools_by_lineage=False, set_selected=False ) # No tool matching the tool id, display an error (shouldn't happen) if not tool: log.error( "data_source_redirect called with tool id '%s' but no such tool exists", tool_id ) trans.log_event( "Tool id '%s' does not exist" % tool_id ) trans.response.status = 404 return trans.show_error_message("Tool '%s' does not exist." % ( escape(tool_id) )) if isinstance( tool, DataSourceTool ): link = url_for( tool.action, **tool.get_static_param_values( trans ) ) else: link = url_for( controller='tool_runner', tool_id=tool.id ) return trans.response.send_redirect( link )
def admin_api_keys( self, trans, cntrller, uid, **kwd ): params = util.Params( kwd ) message = escape( util.restore_text( params.get( 'message', '' ) ) ) status = params.get( 'status', 'done' ) uid = params.get('uid', uid) if params.get( 'new_api_key_button', False ): new_key = trans.app.model.APIKeys() new_key.user_id = uid new_key.key = trans.app.security.get_new_guid() trans.sa_session.add( new_key ) trans.sa_session.flush() message = "A new web API key has been generated for (%s)" % escape( new_key.user.email ) status = "done" return trans.response.send_redirect( web.url_for( controller='userskeys', action='all_users', cntrller=cntrller, message=message, status=status ) )
def index( self, trans, tool_id=None, from_noframe=None, **kwd ): # No tool id passed, redirect to main page if tool_id is None: return trans.response.send_redirect( url_for( controller="root", action="welcome" ) ) # When the tool form is initially loaded, the received kwd will not include a 'refresh' # entry (which only is included when another option is selected in the tool_version_select_field), # so the default selected option should be the most recent version of the tool. The following # check will mae sure this occurs. refreshed_on_change = kwd.get( 'refresh', False ) tool_version_select_field, tools, tool = self.__get_tool_components( tool_id, tool_version=None, get_loaded_tools_by_lineage=False, set_selected=refreshed_on_change ) # No tool matching the tool id, display an error (shouldn't happen) if not tool: log.error( "index called with tool id '%s' but no such tool exists", tool_id ) trans.log_event( "Tool id '%s' does not exist" % tool_id ) trans.response.status = 404 return trans.show_error_message("Tool '%s' does not exist." % ( escape(tool_id) )) if tool.require_login and not trans.user: message = "You must be logged in to use this tool." status = "info" redirect = url_for( controller='tool_runner', action='index', tool_id=tool_id, **kwd ) return trans.response.send_redirect( url_for( controller='user', action='login', cntrller='user', message=message, status=status, redirect=redirect ) ) params = galaxy.util.Params( kwd, sanitize = False ) #Sanitize parameters when substituting into command line via input wrappers #do param translation here, used by datasource tools if tool.input_translator: tool.input_translator.translate( params ) # We may be visiting Galaxy for the first time ( e.g., sending data from UCSC ), # so make sure to create a new history if we've never had one before. history = tool.get_default_history_by_trans( trans, create=True ) template, vars = tool.handle_input( trans, params.__dict__ ) if len( params ) > 0: trans.log_event( "Tool params: %s" % ( str( params ) ), tool_id=tool_id ) add_frame = AddFrameData() add_frame.debug = trans.debug if from_noframe is not None: add_frame.wiki_url = trans.app.config.wiki_url add_frame.from_noframe = True return trans.fill_template( template, history=history, toolbox=self.get_toolbox(), tool_version_select_field=tool_version_select_field, tool=tool, util=galaxy.util, add_frame=add_frame, form_input_auto_focus=True, **vars )
def share( self, trans, id=None, email="", use_panels=False ): """ Handle sharing a visualization with a particular user. """ msg = mtype = None visualization = self.get_visualization( trans, id, check_ownership=True ) if email: other = trans.sa_session.query( model.User ) \ .filter( and_( model.User.table.c.email==email, model.User.table.c.deleted==False ) ) \ .first() if not other: mtype = "error" msg = ( "User '%s' does not exist" % escape( email ) ) elif other == trans.get_user(): mtype = "error" msg = ( "You cannot share a visualization with yourself" ) elif trans.sa_session.query( model.VisualizationUserShareAssociation ) \ .filter_by( user=other, visualization=visualization ).count() > 0: mtype = "error" msg = ( "Visualization already shared with '%s'" % escape( email ) ) else: share = model.VisualizationUserShareAssociation() share.visualization = visualization share.user = other session = trans.sa_session session.add( share ) self.create_item_slug( session, visualization ) session.flush() viz_title = escape( visualization.title ) other_email = escape( other.email ) trans.set_message( "Visualization '%s' shared with user '%s'" % ( viz_title, other_email ) ) return trans.response.send_redirect( web.url_for(controller='visualization', action='sharing', id=id ) ) return trans.fill_template( "/ind_share_base.mako", message = msg, messagetype = mtype, item=visualization, email=email, use_panels=use_panels )
def all_users( self, trans, cntrller="userskeys", **kwd ): params = util.Params( kwd ) message = escape( util.restore_text( params.get( 'message', '' ) ) ) status = params.get( 'status', 'done' ) users = [] for user in trans.sa_session.query( trans.app.model.User ) \ .filter( trans.app.model.User.table.c.deleted==False ) \ .order_by( trans.app.model.User.table.c.email ): uid = int(user.id) userkey = "" for api_user in trans.sa_session.query(trans.app.model.APIKeys) \ .filter( trans.app.model.APIKeys.user_id == uid): userkey = api_user.key users.append({'uid':uid, 'email':user.email, 'key':userkey}) return trans.fill_template( 'webapps/galaxy/user/list_users.mako', cntrller=cntrller, users=users, message=message, status=status )
class DataManager(BaseUIController): @web.expose def index(self, trans, **kwd): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape(kwd.get('message', '')) status = escape(kwd.get('status', 'info')) return trans.fill_template("data_manager/index.mako", data_managers=trans.app.data_managers, tool_data_tables=trans.app.tool_data_tables, view_only=not_is_admin, message=message, status=status) @web.expose def manage_data_manager(self, trans, **kwd): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape(kwd.get('message', '')) status = escape(kwd.get('status', 'info')) data_manager_id = kwd.get('id', None) data_manager = trans.app.data_managers.get_manager(data_manager_id) if data_manager is None: return trans.response.send_redirect( web.url_for(controller="data_manager", action="index", message="Invalid Data Manager (%s) was requested" % data_manager_id, status="error")) jobs = list( reversed([ assoc.job for assoc in trans.sa_session.query( trans.app.model.DataManagerJobAssociation).filter_by( data_manager_id=data_manager_id) ])) return trans.fill_template("data_manager/manage_data_manager.mako", data_manager=data_manager, jobs=jobs, view_only=not_is_admin, message=message, status=status) @web.expose def view_job(self, trans, **kwd): not_is_admin = not trans.user_is_admin() if not_is_admin and not trans.app.config.enable_data_manager_user_view: raise paste.httpexceptions.HTTPUnauthorized( "This Galaxy instance is not configured to allow non-admins to view the data manager." ) message = escape(kwd.get('message', '')) status = escape(kwd.get('status', 'info')) job_id = kwd.get('id', None) try: job_id = trans.security.decode_id(job_id) job = trans.sa_session.query(trans.app.model.Job).get(job_id) except Exception, e: job = None log.error("Bad job id (%s) passed to view_job: %s" % (job_id, e)) if not job: return trans.response.send_redirect( web.url_for(controller="data_manager", action="index", message="Invalid job (%s) was requested" % job_id, status="error")) data_manager_id = job.data_manager_association.data_manager_id data_manager = trans.app.data_managers.get_manager(data_manager_id) hdas = [assoc.dataset for assoc in job.get_output_datasets()] data_manager_output = [] error_messages = [] for hda in hdas: try: data_manager_json = loads(open(hda.get_file_name()).read()) except Exception, e: data_manager_json = {} error_messages.append( escape( "Unable to obtain data_table info for hda (%s): %s" % (hda.id, e))) values = [] for key, value in data_manager_json.get('data_tables', {}).iteritems(): values.append((key, value)) data_manager_output.append(values)
def index( self, trans, tool_id=None, from_noframe=None, **kwd ): # No tool id passed, redirect to main page if tool_id is None: return trans.response.send_redirect( url_for( controller="root", action="welcome" ) ) # When the tool form is initially loaded, the received kwd will not include a 'refresh' # entry (which only is included when another option is selected in the tool_version_select_field), # so the default selected option should be the most recent version of the tool. The following # check will mae sure this occurs. refreshed_on_change = kwd.get( 'refresh', False ) tool_version_select_field, tools, tool = self.__get_tool_components( tool_id, tool_version=None, get_loaded_tools_by_lineage=False, set_selected=refreshed_on_change ) # No tool matching the tool id, display an error (shouldn't happen) if not tool or not tool.allow_user_access( trans.user ): log.error( "index called with tool id '%s' but no such tool exists", tool_id ) trans.log_event( "Tool id '%s' does not exist" % tool_id ) trans.response.status = 404 return trans.show_error_message("Tool '%s' does not exist." % ( escape(tool_id) )) if tool.require_login and not trans.user: message = "You must be logged in to use this tool." status = "info" redirect = url_for( controller='tool_runner', action='index', tool_id=tool_id, **kwd ) return trans.response.send_redirect( url_for( controller='user', action='login', cntrller='user', message=message, status=status, redirect=redirect ) ) def _validated_params_for( kwd ): params = galaxy.util.Params( kwd, sanitize=False ) # Sanitize parameters when substituting into command line via input wrappers #do param translation here, used by datasource tools if tool.input_translator: tool.input_translator.translate( params ) return params params = _validated_params_for( kwd ) # We may be visiting Galaxy for the first time ( e.g., sending data from UCSC ), # so make sure to create a new history if we've never had one before. history = tool.get_default_history_by_trans( trans, create=True ) try: template, vars = tool.handle_input( trans, params.__dict__ ) except KeyError: # This error indicates (or at least can indicate) there was a # problem with the stored tool_state - it is incompatible with # this variant of the tool - possibly because the tool changed # or because the tool version changed. del kwd[ "tool_state" ] params = _validated_params_for( kwd ) template, vars = tool.handle_input( trans, params.__dict__ ) if len( params ) > 0: trans.log_event( "Tool params: %s" % ( str( params ) ), tool_id=tool_id ) add_frame = AddFrameData() add_frame.debug = trans.debug if from_noframe is not None: add_frame.wiki_url = trans.app.config.wiki_url add_frame.from_noframe = True return trans.fill_template( template, history=history, toolbox=self.get_toolbox(), tool_version_select_field=tool_version_select_field, tool=tool, util=galaxy.util, add_frame=add_frame, form_input_auto_focus=True, **vars )