commit/galaxy-central: 2 new changesets
2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/22fd4e79f08c/ Changeset: 22fd4e79f08c User: carlfeberhard Date: 2013-11-19 16:24:35 Summary: Visualizations API: fix create/update validation Affected #: 1 file diff -r b812508869b95cc994d049f724d9475aafd417d9 -r 22fd4e79f08c0185be71fbe37fa43d4aad631e78 lib/galaxy/webapps/galaxy/api/visualizations.py --- a/lib/galaxy/webapps/galaxy/api/visualizations.py +++ b/lib/galaxy/webapps/galaxy/api/visualizations.py @@ -10,7 +10,7 @@ from sqlalchemy import or_ from galaxy import web, util -from galaxy.web.base.controller import BaseAPIController, UsesVisualizationMixin +from galaxy.web.base.controller import BaseAPIController, UsesVisualizationMixin, SharableMixin from galaxy.model.item_attrs import UsesAnnotations from galaxy.exceptions import ( ItemAccessibilityException, ItemDeletionException, ItemOwnershipException, MessageException ) @@ -20,7 +20,7 @@ import logging log = logging.getLogger( __name__ ) -class VisualizationsController( BaseAPIController, UsesVisualizationMixin, UsesAnnotations ): +class VisualizationsController( BaseAPIController, UsesVisualizationMixin, SharableMixin, UsesAnnotations ): """ RESTful controller for interactions with visualizations. """ @@ -122,9 +122,10 @@ else: payload = self._validate_and_parse_payload( payload ) + vis_type = payload.pop( 'type', False ) payload[ 'save' ] = True - # create needs defaults like wizard needs food - generate defaults - this will err if given a weird key? - visualization = self.create_visualization( trans, **payload ) + # generate defaults - this will err if given a weird key? + visualization = self.create_visualization( trans, vis_type, **payload ) rval = { 'id' : trans.security.encode_id( visualization.id ) } @@ -217,11 +218,20 @@ #TODO: deleted #TODO: importable + # must have a type (I've taken this to be the visualization name) + if 'type' not in payload: + raise ValueError( "key/value 'type' is required" ) + validated_payload = {} for key, val in payload.items(): - if key == 'config': + #TODO: validate types in VALID_TYPES/registry names at the mixin/model level? + if key == 'type': + if not ( isinstance( val, str ) or isinstance( val, unicode ) ): + raise ValueError( '%s must be a string or unicode: %s' %( key, str( type( val ) ) ) ) + val = util.sanitize_html.sanitize_html( val, 'utf-8' ) + elif key == 'config': if not isinstance( val, dict ): - raise ValueError( '%s must be a dictionary (JSON): %s' %( key, str( type( val ) ) ) ) + raise ValueError( '%s must be a dictionary: %s' %( key, str( type( val ) ) ) ) elif key == 'annotation': if not ( isinstance( val, str ) or isinstance( val, unicode ) ): @@ -235,21 +245,16 @@ raise ValueError( '%s must be a string or unicode: %s' %( key, str( type( val ) ) ) ) val = util.sanitize_html.sanitize_html( val, 'utf-8' ) elif key == 'slug': - if not isinstance( val, str ): + if not ( isinstance( val, str ) or isinstance( val, unicode ) ): raise ValueError( '%s must be a string: %s' %( key, str( type( val ) ) ) ) val = util.sanitize_html.sanitize_html( val, 'utf-8' ) - elif key == 'type': - if not isinstance( val, str ): - raise ValueError( '%s must be a string: %s' %( key, str( type( val ) ) ) ) - val = util.sanitize_html.sanitize_html( val, 'utf-8' ) - #TODO: validate types in VALID_TYPES/registry names at the mixin/model level? elif key == 'dbkey': if not ( isinstance( val, str ) or isinstance( val, unicode ) ): raise ValueError( '%s must be a string or unicode: %s' %( key, str( type( val ) ) ) ) val = util.sanitize_html.sanitize_html( val, 'utf-8' ) - elif key not in valid_but_uneditable_keys: - raise AttributeError( 'unknown key: %s' %( str( key ) ) ) + #elif key not in valid_but_uneditable_keys: + # raise AttributeError( 'unknown key: %s' %( str( key ) ) ) validated_payload[ key ] = val return validated_payload https://bitbucket.org/galaxy/galaxy-central/commits/f166a093ebe3/ Changeset: f166a093ebe3 User: carlfeberhard Date: 2013-11-19 16:26:48 Summary: Visualizations Registry: propery default to str eqv test for test_type, properly call getattr_lambda Affected #: 1 file diff -r 22fd4e79f08c0185be71fbe37fa43d4aad631e78 -r f166a093ebe3237d1374c3ebda520f085a85ba1d lib/galaxy/visualization/registry.py --- a/lib/galaxy/visualization/registry.py +++ b/lib/galaxy/visualization/registry.py @@ -477,7 +477,7 @@ return lambda o: getattr( o, next_attr_name ) # recursive case - return lambda o: getattr( self._build_getattr_lambda( attr_name_list[:-1] ), next_attr_name ) + return lambda o: getattr( self._build_getattr_lambda( attr_name_list[:-1] )( o ), next_attr_name ) def parse_tests( self, xml_tree_list ): """ @@ -493,7 +493,7 @@ return tests for test_elem in xml_tree_list: - test_type = test_elem.get( 'type' ) + test_type = test_elem.get( 'type', 'eq' ) test_result = test_elem.text if not test_type or not test_result: log.warn( 'Skipping test. Needs both type attribute and text node to be parsed: ' @@ -509,9 +509,13 @@ getter = self._build_getattr_lambda( test_attr ) # result type should tell the registry how to convert the result before the test - test_result_type = test_elem.get( 'result_type' ) or 'string' + test_result_type = test_elem.get( 'result_type', 'string' ) + print + print test_attr, test_result_type + print # test functions should be sent an object to test, and the parsed result expected from the test + # is test_attr attribute an instance of result if test_type == 'isinstance': #TODO: wish we could take this further but it would mean passing in the datatypes_registry 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