commit/galaxy-central: carlfeberhard: Managers, users: add filters for later admin use, quota serializers, and a fallback anonymous user serialization; DatasetAssociations & HDAs: add filters
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/3abf1c30e473/ Changeset: 3abf1c30e473 User: carlfeberhard Date: 2015-02-05 21:55:23+00:00 Summary: Managers, users: add filters for later admin use, quota serializers, and a fallback anonymous user serialization; DatasetAssociations & HDAs: add filters Affected #: 4 files diff -r 494418e72cf0007e909c7f4b9134cd2b82df49e2 -r 3abf1c30e4730fb84c8a3ab764661e19071a8e45 lib/galaxy/managers/datasets.py --- a/lib/galaxy/managers/datasets.py +++ b/lib/galaxy/managers/datasets.py @@ -274,3 +274,15 @@ def add_deserializers( self ): super( DatasetAssociationDeserializer, self ).add_deserializers() deletable.PurgableDeserializerMixin.add_deserializers( self ) + +class DatasetAssociationFilters( base.ModelFilterParser, deletable.PurgableFiltersMixin ): + + def _add_parsers( self ): + super( DatasetAssociationFilters, self )._add_parsers() + deletable.PurgableFiltersMixin._add_parsers( self ) + + self.orm_filter_parsers.update({ + 'name' : { 'op': ( 'eq', 'contains', 'like' ) }, + 'state' : { 'op': ( 'eq', 'in' ) }, + }) + #self.fn_filter_parsers.update({}) diff -r 494418e72cf0007e909c7f4b9134cd2b82df49e2 -r 3abf1c30e4730fb84c8a3ab764661e19071a8e45 lib/galaxy/managers/hdas.py --- a/lib/galaxy/managers/hdas.py +++ b/lib/galaxy/managers/hdas.py @@ -592,3 +592,25 @@ }) self.deserializable_keyset.update( self.deserializers.keys() ) + + +class HDAFilters( datasets.DatasetAssociationFilters ): + model_class = model.HistoryDatasetAssociation + + def _add_parsers( self ): + super( HDAFilters, self )._add_parsers() + + self.fn_filter_parsers.update({ + #TODO: filter_string_attr_contains, filter_string_attr_eq + #'dbkey' : { 'op': { 'has' : self.filter_annotation_contains, } }, + + #TODO: add this in annotatable mixin + 'annotation' : { 'op': { 'has' : self.filter_annotation_contains, } }, + #TODO: add this in taggable mixin + 'tag' : { + 'op': { + 'eq' : self.filter_has_tag, + 'has': self.filter_has_partial_tag, + } + } + }) diff -r 494418e72cf0007e909c7f4b9134cd2b82df49e2 -r 3abf1c30e4730fb84c8a3ab764661e19071a8e45 lib/galaxy/managers/histories.py --- a/lib/galaxy/managers/histories.py +++ b/lib/galaxy/managers/histories.py @@ -310,7 +310,7 @@ 'contents' : self.serialize_contents }) - def serialize_contents( self, trans, history, key ): + def serialize_contents( self, trans, history, *args ): contents_dictionaries = [] for content in history.contents_iter( types=[ 'dataset', 'dataset_collection' ] ): contents_dict = {} diff -r 494418e72cf0007e909c7f4b9134cd2b82df49e2 -r 3abf1c30e4730fb84c8a3ab764661e19071a8e45 lib/galaxy/managers/users.py --- a/lib/galaxy/managers/users.py +++ b/lib/galaxy/managers/users.py @@ -8,15 +8,17 @@ from galaxy import model from galaxy import exceptions +from galaxy import util from galaxy.managers import base +from galaxy.managers import deletable from galaxy.managers import api_keys import logging log = logging.getLogger( __name__ ) -class UserManager( base.ModelManager ): +class UserManager( base.ModelManager, deletable.PurgableManagerMixin ): model_class = model.User foreign_key_name = 'user' @@ -107,7 +109,7 @@ """ Return a list of admin email addresses from the config file. """ - return [ x.strip() for x in self.app.config.get( "admin_users", "" ).split( "," ) ] + return [ email.strip() for email in self.app.config.get( "admin_users", "" ).split( "," ) ] def admins( self, trans, filters=None, **kwargs ): """ @@ -193,14 +195,19 @@ #TODO: not sure we need to go through sec agent... it's just the first role of type private return self.app.security_agent.get_private_user_role( user ) + def quota( self, trans, user ): + #TODO: use quota manager + return self.app.quota_agent.get_percent( user=user ) -class UserSerializer( base.ModelSerializer ): - def __init__( self ): +class UserSerializer( base.ModelSerializer, deletable.PurgableSerializerMixin ): + + def __init__( self, app ): """ Convert a User and associated data to a dictionary representation. """ super( UserSerializer, self ).__init__() + self.user_manager = UserManager( app ) self.default_view = 'summary' self.add_view( 'summary', [ @@ -209,23 +216,80 @@ self.add_view( 'detailed', [ 'update_time', 'create_time', + + 'deleted', + 'purged', + 'active', + 'total_disk_usage', 'nice_total_disk_usage', - 'deleted', - 'purged', - 'active' - ], include_keys_from='summary' ) - #self.add_view( 'summary', [ + 'quota_percent' # 'preferences', # # all tags # 'tags', # # all annotations # 'annotations' - #], include_keys_from='detailed' ) + ], include_keys_from='summary' ) def add_serializers( self ): + super( UserSerializer, self ).add_serializers() + deletable.PurgableSerializerMixin.add_serializers( self ) + self.serializers.update({ 'id' : self.serialize_id, 'create_time' : self.serialize_date, 'update_time' : self.serialize_date, + 'is_admin' : lambda t, i, k: self.user_manager.is_admin( t, i ), + 'quota_percent' : lambda t, i, k: self.user_manager.quota( t, i ) }) + + def serialize_current_anonymous_user( self, trans, user, keys ): + # use the current history if any to get usage stats for trans' anonymous user + #TODO: might be better as sep. Serializer class + history = trans.history + if not history: + raise exceptions.AuthenticationRequired( 'No history for anonymous user usage stats' ); + + usage = trans.app.quota_agent.get_usage( trans, history=trans.history ) + percent = trans.app.quota_agent.get_percent( trans=trans, usage=usage ) + + # a very small subset of keys available + values = { + 'id' : None, + 'total_disk_usage' : int( usage ), + 'nice_total_disk_usage' : util.nice_size( usage ), + 'quota_percent' : percent, + } + serialized = {} + for key in keys: + if key in values: + serialized[ key ] = values[ key ] + return serialized + + def serialize( self, trans, user, keys ): + """ + Override to return at least some usage info if user is anonymous. + """ + if self.user_manager.is_anonymous( user ): + return self.serialize_current_anonymous_user( trans, user, keys ) + return super( UserSerializer, self ).serialize( trans, user, keys ) + + +class AdminUserFilters( base.ModelFilterParser, deletable.PurgableFiltersMixin ): + model_class = model.User + + def _add_parsers( self ): + super( AdminUserFilters, self )._add_parsers() + deletable.PurgableFiltersMixin._add_parsers( self ) + + #PRECONDITION: user making the query has been verified as an admin + self.orm_filter_parsers.update({ + 'name' : { 'op': ( 'eq', 'contains', 'like' ) }, + 'email' : { 'op': ( 'eq', 'contains', 'like' ) }, + 'username' : { 'op': ( 'eq', 'contains', 'like' ) }, + 'active' : { 'op': ( 'eq' ) }, + 'disk_usage' : { 'op': ( 'le', 'ge' ) } + }) + + self.fn_filter_parsers.update({ + }) 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