Skip to content

Commit

Permalink
Synchronize decoding ids across base controller and manager base.
Browse files Browse the repository at this point in the history
To ensure we have the same kind of exception thrown in both cases.
  • Loading branch information
jmchilton committed Dec 6, 2015
1 parent 9824905 commit f17a6c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
16 changes: 11 additions & 5 deletions lib/galaxy/managers/base.py
Expand Up @@ -112,18 +112,24 @@ def get_class( class_name ):
return item_class


def decode_id(app, id):
try:
# note: use str - occasionally a fully numeric id will be placed in post body and parsed as int via JSON
# resulting in error for valid id
return app.security.decode_id( str( id ) )
except ( ValueError, TypeError ):
msg = "Malformed id ( %s ) specified, unable to decode" % ( str( id ) )
raise exceptions.MalformedId( msg, id=str( id ) )


def get_object( trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None ):
"""
Convenience method to get a model object with the specified checks. This is
a generic method for dealing with objects uniformly from the older
controller mixin code - however whenever possible the managers for a
particular model should be used to load objects.
"""
try:
decoded_id = trans.security.decode_id( id )
except:
raise exceptions.MessageException( "Malformed %s id ( %s ) specified, unable to decode"
% ( class_name, str( id ) ), type='error' )
decoded_id = decode_id(trans.app, id)
try:
item_class = get_class( class_name )
assert item_class is not None
Expand Down
9 changes: 1 addition & 8 deletions lib/galaxy/web/base/controller.py
Expand Up @@ -11,7 +11,6 @@
from paste.httpexceptions import HTTPNotImplemented, HTTPRequestRangeNotSatisfiable
from galaxy.exceptions import ItemAccessibilityException, ItemDeletionException, ItemOwnershipException
from galaxy.exceptions import MessageException
from galaxy import exceptions

from galaxy import web
from galaxy import model
Expand Down Expand Up @@ -94,13 +93,7 @@ def get_role( self, trans, id, check_ownership=False, check_accessible=False, de

# ---- parsing query params
def decode_id( self, id ):
try:
# note: use str - occasionally a fully numeric id will be placed in post body and parsed as int via JSON
# resulting in error for valid id
return self.app.security.decode_id( str( id ) )
except ( ValueError, TypeError ):
msg = "Malformed id ( %s ) specified, unable to decode" % ( str( id ) )
raise exceptions.MalformedId( msg, id=str( id ) )
return managers_base.decode_id( self.app, id )

def encode_all_ids( self, trans, rval, recursive=False ):
"""
Expand Down

0 comments on commit f17a6c9

Please sign in to comment.