commit/galaxy-central: 2 new changesets
2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/8070d6f638fe/ changeset: 8070d6f638fe user: jgoecks date: 2013-03-17 15:58:43 summary: Import and documentation fixes for web helpers. affected #: 1 file diff -r 1aa6224b32c2e1c05eafbf1f507d2f7a754ded89 -r 8070d6f638fea37aff3ac3e081b7bd9fba0402b7 lib/galaxy/web/framework/helpers/__init__.py --- a/lib/galaxy/web/framework/helpers/__init__.py +++ b/lib/galaxy/web/framework/helpers/__init__.py @@ -1,7 +1,7 @@ import pkg_resources pkg_resources.require( "WebHelpers" ) -from webhelpers import * +from webhelpers import date, stylesheet_link_tag, javascript_include_tag, url_for from galaxy.util.json import to_json_string from galaxy.util import hash_util @@ -12,10 +12,13 @@ server_starttime = int(time.time()) -# If the date is more than one week ago, then display the actual date instead of in words def time_ago( x ): + """ + Convert a datetime to a string. + """ delta = timedelta(weeks=1) + # If the date is more than one week ago, then display the actual date instead of in words if (datetime.utcnow() - x) > delta: # Greater than a week difference return x.strftime("%b %d, %Y") else: @@ -27,8 +30,10 @@ else: return c -# Smart string truncation def truncate(content, length=100, suffix='...'): + """ + Smart string truncation + """ if len(content) <= length: return content else: https://bitbucket.org/galaxy/galaxy-central/commits/92275794f6ef/ changeset: 92275794f6ef user: jgoecks date: 2013-03-17 16:27:36 summary: Add method to encode ids in an dictionary and use to encode dataset id in tabular display. affected #: 2 files diff -r 8070d6f638fea37aff3ac3e081b7bd9fba0402b7 -r 92275794f6efe2f2e17c2d3785061e88f2f23f84 lib/galaxy/web/security/__init__.py --- a/lib/galaxy/web/security/__init__.py +++ b/lib/galaxy/web/security/__init__.py @@ -30,10 +30,13 @@ random_pool.stir() return str( number.getRandomNumber( nbits, random_pool.get_bytes ) ) + class SecurityHelper( object ): + def __init__( self, **config ): self.id_secret = config['id_secret'] self.id_cipher = Blowfish.new( self.id_secret ) + def encode_id( self, obj_id ): # Convert to string s = str( obj_id ) @@ -41,17 +44,32 @@ s = ( "!" * ( 8 - len(s) % 8 ) ) + s # Encrypt return self.id_cipher.encrypt( s ).encode( 'hex' ) + + def encode_dict_ids( self, a_dict ): + """ + Encode all ids in dictionary. Ids are identified by (a) an 'id' key or + (b) a key that ends with '_id' + """ + for key, val in a_dict.items(): + if key == 'id' or key.endswith('_id'): + a_dict[ key ] = self.encode_id( val ) + + return a_dict + def decode_id( self, obj_id ): return int( self.id_cipher.decrypt( obj_id.decode( 'hex' ) ).lstrip( "!" ) ) + def encode_guid( self, session_key ): # Session keys are strings # Pad to a multiple of 8 with leading "!" s = ( "!" * ( 8 - len( session_key ) % 8 ) ) + session_key # Encrypt return self.id_cipher.encrypt( s ).encode( 'hex' ) + def decode_guid( self, session_key ): # Session keys are strings return self.id_cipher.decrypt( session_key.decode( 'hex' ) ).lstrip( "!" ) + def get_new_guid( self ): # Generate a unique, high entropy 128 bit random number return get_random_bytes( 16 ) diff -r 8070d6f638fea37aff3ac3e081b7bd9fba0402b7 -r 92275794f6efe2f2e17c2d3785061e88f2f23f84 templates/webapps/galaxy/dataset/tabular_chunked.mako --- a/templates/webapps/galaxy/dataset/tabular_chunked.mako +++ b/templates/webapps/galaxy/dataset/tabular_chunked.mako @@ -17,8 +17,7 @@ require(['mvc/data'], function(data) { data.createTabularDatasetChunkedView( - // Dataset config. TODO: encode id. - _.extend( ${h.to_json_string( dataset.get_api_value() )}, + _.extend( ${h.to_json_string( trans.security.encode_dict_ids( dataset.get_api_value() ) )}, { chunk_url: "${h.url_for( controller='/dataset', action='display', dataset_id=trans.security.encode_id( dataset.id ))}", 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.
participants (1)
-
commits-noreply@bitbucket.org