Skip to content

Commit

Permalink
Catch user input error for auto created roles and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 15, 2017
1 parent 246489a commit f9e8892
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/galaxy/webapps/galaxy/controllers/admin.py
Expand Up @@ -1000,6 +1000,9 @@ def create_role( self, trans, payload=None, **kwd ):
gra = trans.app.model.GroupRoleAssociation( group, role )
trans.sa_session.add( gra )
if auto_create_checked:
# Check if role with same name already exists
if trans.sa_session.query( trans.app.model.Group ).filter( trans.app.model.Group.table.c.name == name ).first():
return message_exception( trans, 'A group with that name already exists, so choose another name or disable group creation.' )
# Create the group
group = trans.app.model.Group( name=name )
trans.sa_session.add( group )
Expand Down Expand Up @@ -1305,6 +1308,9 @@ def create_group( self, trans, payload=None, **kwd ):
gra = trans.app.model.GroupRoleAssociation( group, role )
trans.sa_session.add( gra )
if auto_create_checked:
# Check if role with same name already exists
if trans.sa_session.query( trans.app.model.Role ).filter( trans.app.model.Role.table.c.name == name ).first():
return message_exception( trans, 'A role with that name already exists, so choose another name or disable role creation.' )
# Create the role
role = trans.app.model.Role( name=name, description='Role for group %s' % name )
trans.sa_session.add( role )
Expand Down

0 comments on commit f9e8892

Please sign in to comment.