Skip to content

Commit

Permalink
Fix user id decoding, fix optional array handling
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 15, 2017
1 parent d6f6a78 commit 4688eef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lib/galaxy/actions/admin.py
Expand Up @@ -13,7 +13,7 @@ class AdminActions( object ):
"""
Mixin for controllers that provide administrative functionality.
"""
def _create_quota( self, params ):
def _create_quota( self, params, decode_id=None ):
if params.amount.lower() in ( 'unlimited', 'none', 'no limit' ):
create_amount = None
else:
Expand All @@ -39,23 +39,25 @@ def _create_quota( self, params ):
raise ActionInputError( "Operation for an unlimited quota must be '='." )
else:
# Create the quota
in_users = util.listify( params.in_users )
in_groups = util.listify( params.in_groups )
quota = self.app.model.Quota( name=params.name, description=params.description, amount=create_amount, operation=params.operation )
self.sa_session.add( quota )
# If this is a default quota, create the DefaultQuotaAssociation
if params.default != 'no':
self.app.quota_agent.set_default_quota( params.default, quota )
else:
# Create the UserQuotaAssociations
for user in [ self.sa_session.query( self.app.model.User ).get( x ) for x in params.in_users ]:
for user in [ self.sa_session.query( self.app.model.User ).get( decode_id( x ) if decode_id else x ) for x in in_users ]:
uqa = self.app.model.UserQuotaAssociation( user, quota )
self.sa_session.add( uqa )
# Create the GroupQuotaAssociations
for group in [ self.sa_session.query( self.app.model.Group ).get( x ) for x in params.in_groups ]:
for group in [ self.sa_session.query( self.app.model.Group ).get( decode_id( x ) if decode_id else x ) for x in in_groups ]:
gqa = self.app.model.GroupQuotaAssociation( group, quota )
self.sa_session.add( gqa )
self.sa_session.flush()
message = "Quota '%s' has been created with %d associated users and %d associated groups." % \
( quota.name, len( params.in_users ), len( params.in_groups ) )
( quota.name, len( in_users ), len( in_groups ) )
return quota, message

def _rename_quota( self, quota, params ):
Expand Down
12 changes: 6 additions & 6 deletions lib/galaxy/webapps/galaxy/controllers/admin.py
Expand Up @@ -642,7 +642,7 @@ def rename_quota( self, trans, payload=None, **kwd ):
}
else:
try:
return { 'message': self._rename_quota( quota, util.Params( payload ) ) }
return { 'message': self._rename_quota( quota, util.Params( payload ), decode_id=trans.security.decode_id ) }
except ActionInputError as e:
return message_exception( trans, e.err_msg )

Expand Down Expand Up @@ -678,7 +678,7 @@ def manage_users_and_groups_for_quota( self, trans, payload=None, **kwd ):
build_select_input( 'in_users', 'Users', all_users, in_users ) ] }
else:
try:
return { 'message': self._manage_users_and_groups_for_quota( quota, util.Params( payload ), trans.security.decode_id ) }
return { 'message': self._manage_users_and_groups_for_quota( quota, util.Params( payload ), decode_id=trans.security.decode_id ) }
except ActionInputError as e:
return message_exception( trans, e.err_msg )

Expand Down Expand Up @@ -981,8 +981,8 @@ def create_role( self, trans, payload=None, **kwd ):
name = util.restore_text( payload.get( 'name', '' ) )
description = util.restore_text( payload.get( 'description', '' ) )
auto_create_checked = payload.get( 'auto_create' ) == 'true'
in_users = util.listify( payload.get( 'in_users' ) ) or []
in_groups = util.listify( payload.get( 'in_groups' ) ) or []
in_users = util.listify( payload.get( 'in_users' ) )
in_groups = util.listify( payload.get( 'in_groups' ) )
if not name or not description:
return message_exception( trans, 'Enter a valid name and a description.' )
elif trans.sa_session.query( trans.app.model.Role ).filter( trans.app.model.Role.table.c.name == name ).first():
Expand Down Expand Up @@ -1286,8 +1286,8 @@ def create_group( self, trans, payload=None, **kwd ):
else:
name = util.restore_text( payload.get( 'name', '' ) )
auto_create_checked = payload.get( 'auto_create' ) == 'true'
in_users = util.listify( payload.get( 'in_users' ) ) or []
in_roles = util.listify( payload.get( 'in_roles' ) ) or []
in_users = util.listify( payload.get( 'in_users' ) )
in_roles = util.listify( payload.get( 'in_roles' ) )
if not name:
return message_exception( trans, 'Enter a valid name.' )
elif trans.sa_session.query( trans.app.model.Group ).filter( trans.app.model.Group.table.c.name == name ).first():
Expand Down

0 comments on commit 4688eef

Please sign in to comment.