1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/6f4c44ef44a3/ Changeset: 6f4c44ef44a3 User: dan Date: 2014-04-01 20:11:56 Summary: Update Biostar question posting to use POST. Have biostar bug reports automatically post. Affected #: 3 files diff -r 803730aa8abfa842bfceb8d4563b906d3bdf42d1 -r 6f4c44ef44a3d2df0778c0d4b6b27efc8014c1db lib/galaxy/util/biostar.py --- a/lib/galaxy/util/biostar.py +++ b/lib/galaxy/util/biostar.py @@ -8,14 +8,22 @@ from unicodedata import normalize from galaxy.web.base.controller import url_for from galaxy.tools.errors import ErrorReporter +from . import smart_str _punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') DEFAULT_GALAXY_TAG = 'galaxy' +# Default values for new posts to Biostar +DEFAULT_PAYLOAD = { + 'title': '', + 'tag_val': DEFAULT_GALAXY_TAG, + 'content': '', +} + BIOSTAR_ACTIONS = { None: { 'url': lambda x: '', 'uses_payload': False }, - 'new_post': { 'url': lambda x: 'p/new/post/', 'uses_payload': True }, + 'new_post': { 'url': lambda x: 'p/new/external/post/', 'uses_payload': True, 'hmac_values':{'content':'digest'} }, 'show_tags': { 'url': lambda x: 't/%s/' % ( "+".join( ( x.get( 'tag_val' ) or DEFAULT_GALAXY_TAG ).split( ',' ) ) ), 'uses_payload':False }, 'log_out': { 'url': lambda x: 'site/logout/', 'uses_payload': False } } @@ -37,13 +45,6 @@ result.append(word) return unicode(delim.join(result)) -# Default values for new posts to Biostar -DEFAULT_PAYLOAD = { - 'title': '', - 'tag_val': DEFAULT_GALAXY_TAG, - 'content': '', -} - def get_biostar_url( app, payload=None, biostar_action=None ): # Ensure biostar integration is enabled if not biostar_enabled( app ): @@ -54,12 +55,17 @@ # Start building up the payload payload = payload or {} payload = dict( DEFAULT_PAYLOAD, **payload ) + payload[ 'name' ] = app.config.biostar_key_name + for hmac_value_name, hmac_parameter_name in biostar_action.get( 'hmac_values', {} ).items(): + #Biostar requires ascii only on HMAC'd things + payload[ hmac_value_name ] = smart_str( payload.get( hmac_value_name, '' ), encoding='ascii', errors='replace' ) + payload[ hmac_parameter_name ] = hmac.new( app.config.biostar_key, payload[ hmac_value_name ] ).hexdigest() #generate url, can parse payload info url = str( urlparse.urljoin( app.config.biostar_url, biostar_action.get( 'url' )( payload ) ) ) if not biostar_action.get( 'uses_payload' ): payload = {} - url = url_for( url, **payload ) - return url + url = url_for( url ) + return url, payload def tag_for_tool( tool ): """ @@ -120,7 +126,7 @@ def biostar_logout( trans ): if biostar_enabled( trans.app ): delete_cookie( trans, trans.app.config.biostar_key_name ) - return get_biostar_url( trans.app, biostar_action='log_out' ) + return get_biostar_url( trans.app, biostar_action='log_out' )[0] return None class BiostarErrorReporter( ErrorReporter ): @@ -129,11 +135,13 @@ assert self._can_access_dataset( user ), Exception( "You are not allowed to access this dataset." ) tool_version_select_field, tools, tool = \ self.app.toolbox.get_tool_components( self.tool_id, tool_version=None, get_loaded_tools_by_lineage=False, set_selected=True ) - payload = { 'title': 'Bug report on "%s" tool' % ( tool.name ), 'content': self.report.replace( '\n', '<br />' ), 'tag_val':slugify( 'bug report' ) } + payload = { 'title': 'Bug report on "%s" tool' % ( tool.name ), 'content': self.report.replace( '\n', '<br />' ).replace( '\r', '' ), 'tag_val':slugify( 'bug report' ) } #Get footer for email from here payload2 = populate_tool_payload( tool=tool ) if 'content' in payload2: payload[ 'content' ] = "%s<br />%s" % ( payload['content'], payload2['content'] ) if 'tag_val' in payload2: payload[ 'tag_val' ] = ','.join( [ payload2[ 'tag_val' ], payload[ 'tag_val' ] ] ) + if 'submit' not in payload: + payload[ 'submit' ] = 1 #Automatically post bug reports to biostar return payload diff -r 803730aa8abfa842bfceb8d4563b906d3bdf42d1 -r 6f4c44ef44a3d2df0778c0d4b6b27efc8014c1db lib/galaxy/webapps/galaxy/controllers/biostar.py --- a/lib/galaxy/webapps/galaxy/controllers/biostar.py +++ b/lib/galaxy/webapps/galaxy/controllers/biostar.py @@ -18,12 +18,14 @@ pass Galaxy user information and optional information about a specific tool. """ try: - url = biostar.get_biostar_url( trans.app, payload=payload, biostar_action=biostar_action ) + url, payload = biostar.get_biostar_url( trans.app, payload=payload, biostar_action=biostar_action ) except Exception, e: return error( str( e ) ) # Only create/log in biostar user if is registered Galaxy user if trans.user: biostar.create_cookie( trans, trans.app.config.biostar_key_name, trans.app.config.biostar_key, trans.user.email ) + if payload: + return trans.fill_template( "biostar/post_redirect.mako", post_url=url, form_inputs=payload ) return trans.response.send_redirect( url ) @web.expose @@ -85,8 +87,8 @@ payload = error_reporter.send_report( trans.user, email=email, message=message ) except Exception, e: return error( str( e ) ) - return self.biostar_question_redirect( trans, payload=payload ) - + return self.biostar_redirect( trans, payload=payload, biostar_action='new_post' ) + @web.expose def biostar_logout( self, trans ): """ diff -r 803730aa8abfa842bfceb8d4563b906d3bdf42d1 -r 6f4c44ef44a3d2df0778c0d4b6b27efc8014c1db templates/webapps/galaxy/biostar/post_redirect.mako --- /dev/null +++ b/templates/webapps/galaxy/biostar/post_redirect.mako @@ -0,0 +1,27 @@ +<%inherit file="/base.mako"/> + +<%def name="javascripts()"> + ${parent.javascripts()} + <script> + $( document ).ready( function(){ + $("#postRedirect").hide(); + ##need to use 'click()' on submit button instead of submit() on form, since Biostar uses a parameter named 'submit' + $("#GalaxySubmitPostRedirectForm").click(); + }); + </script> +</%def> + +<%def name="title()">Post Biostar Question</%def> + +<div class="infomessagelarge"> + <p>You are now being forwarded to Biostar.<p> + <div id="postRedirect"> + <p>If you are not automatically forwarded, click the button below:<p> + <form id="postRedirectForm" action="${post_url}" method="post" > + %for input_name, input_value in form_inputs.items(): + <input type="hidden" name="${input_name}" value="${input_value | h}"> + %endfor + <input type="submit" name="GalaxySubmitPostRedirectForm" id='GalaxySubmitPostRedirectForm' value="Click Here"> + </form> + </div> +</div> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.