diff --git a/templates/admin/dataset_security/role.mako b/templates/admin/dataset_security/role.mako index 0b37e6070ec..63add3c2bb3 100644 --- a/templates/admin/dataset_security/role.mako +++ b/templates/admin/dataset_security/role.mako @@ -50,28 +50,28 @@ $().ready(function() {
Users associated with '${role.name}'
${render_select( "in_users", in_users )}
- +
Users not associated with '${role.name}'
${render_select( "out_users", out_users )}
- +
Groups associated with '${role.name}'
${render_select( "in_groups", in_groups )}
- +
Groups not associated with '${role.name}'
${render_select( "out_groups", out_groups )}
- +
- +
diff --git a/test/base/twilltestcase.py b/test/base/twilltestcase.py index 3bccebaf549..e92c1febfdb 100644 --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -370,6 +370,7 @@ class TwillTestCase( unittest.TestCase ): self.home() #Reset our URL for future tests def login( self, email='test@bx.psu.edu', password='testuser'): + # test@bx.psu.edu is configured as an admin user self.create( email=email, password=password, confirm=password ) self.visit_page( "user/login?email=%s&password=%s" % (email, password) ) self.check_page_for_string( "Now logged in as %s" %email ) @@ -528,7 +529,7 @@ class TwillTestCase( unittest.TestCase ): # Dataset Security stuff def create_role( self, name='New Test Role', description="Very cool new test role", user_ids=[], group_ids=[] ): - """Create a new role with 2 members""" + """Create a new role""" self.visit_url( "%s/admin/create_role" % self.url ) form = tc.show() self.check_page_for_string( "Create Role" ) @@ -536,16 +537,38 @@ class TwillTestCase( unittest.TestCase ): tc.fv( "1", "name", name ) tc.fv( "1", "description", description ) for user_id in user_ids: - tc.fv( "1", "3", user_id ) # 1-based form field 3 is the 1st check box named 'users', user id 1 is test@bx.psu.edu + tc.fv( "1", "3", user_id ) # form field 3 is the check box named 'users' for group_id in group_ids: - tc.fv( "1", "4", group_id ) # 1-based form field 4 is the 1st check box named 'groups' + tc.fv( "1", "4", group_id ) # form field 4 is the check box named 'groups' tc.submit( "create_role_button" ) except AssertionError, err: errmsg = 'Exception caught attempting to create role: %s' % str( err ) raise AssertionError( errmsg ) self.home() - return form - def create_group( self, name='New Test Group3', user_ids=[], role_ids=[] ): + self.visit_page( "admin/roles" ) + self.check_page_for_string( name ) + self.home() + def mark_role_deleted( self, role_id ): + """Mark a role as deleted""" + self.visit_url( "%s/admin/mark_role_deleted?role_id=%s" % ( self.url, role_id ) ) + self.last_page() + self.check_page_for_string( 'The role has been marked as deleted' ) + self.home() + def undelete_role( self, role_id ): + """Undelete an existing role""" + self.visit_url( "%s/admin/undelete_role?role_id=%s" % ( self.url, role_id ) ) + self.last_page() + self.check_page_for_string( 'The role has been marked as not deleted' ) + self.home() + def purge_role( self, role_id, deleted=False ): + """Purge an existing role""" + if not deleted: + self.mark_role_deleted( role_id ) + self.visit_url( "%s/admin/purge_role?role_id=%s" % ( self.url, role_id ) ) + self.last_page() + self.check_page_for_string( 'The role has been purged from the database' ) + self.home() + def create_group( self, name='New Test Group', user_ids=[], role_ids=[] ): """Create a new group with 2 members and 1 associated role""" self.visit_url( "%s/admin/create_group" % self.url ) form = tc.show() @@ -553,47 +576,61 @@ class TwillTestCase( unittest.TestCase ): try: tc.fv( "1", "name", name ) for user_id in user_ids: - tc.fv( "1", "2", user_id ) # 1-based form field 2 is the 1st check box named 'members', user id 1 is test@bx.psu.edu + tc.fv( "1", "2", user_id ) # form field 2 is the check box named 'members' for role_id in role_ids: - tc.fv( "1", "3", role_id ) # form field 3 is the 1st check box named 'roles', role id 1 is 'New Test Role' + tc.fv( "1", "3", role_id ) # form field 3 is the check box named 'roles' tc.submit( "create_group_button" ) except AssertionError, err: errmsg = 'Exception caught attempting to create group: %s' % str( err ) raise AssertionError( errmsg ) self.home() - return form - def add_group_member( self, group_id ): + self.visit_page( "admin/groups" ) + self.check_page_for_string( name ) + self.home() + def add_group_members( self, group_id, user_ids=[] ): """Add a member to an existing group""" - # twill version 0.9 does not allow for this test self.visit_url( "%s/admin/group_members_edit?group_id=%s" % ( self.url, group_id ) ) self.check_page_for_string( 'Members of' ) try: - tc.fv( "1", "1", "2" ) # 1-based form field 2 is the 2nd check box named 'members', user id 2 is test2@bx.psu.edu + for user_id in user_ids: + tc.fv( "1", "1", user_id ) # form field 1 is the check box named 'members' tc.submit( "group_members_edit_button" ) except AssertionError, err: - errmsg = 'Exception caught attempting to create group: %s' % str( err ) - raise AssertionError( errmsg ) + raise AssertionError( 'Exception caught attempting to create group: %s' % str( err ) ) self.home() - def mark_group_deleted( self, group_id='' ): - """Delete an existing group""" + def associate_groups_with_role( self, role_id, group_ids=[] ): + """Add groups to an existing role""" + # NOTE: To get this to work with twill, all select lists must contain at least 1 option value + # or twill throws an exception, which is: ParseError: OPTION outside of SELECT + self.visit_url( "%s/admin/role?role_id=%s" % ( self.url, role_id ) ) + self.check_page_for_string( 'Groups associated with' ) + # All groups must be in the out_groups form field + try: + for group in groups: + tc.fv( "1", "7", group_id ) # form field 7 is the select list named out_groups, note the buttons... + tc.submit( "groups_add_button" ) + tc.submit( "role_button" ) + except AssertionError, err: + raise AssertionError( 'Exception caught attempting to associated groups with a role: %s' % str( err ) ) + except: + pass + self.home() + def mark_group_deleted( self, group_id ): + """Mark a group as deleted""" self.visit_url( "%s/admin/mark_group_deleted?group_id=%s" % ( self.url, group_id ) ) self.last_page() self.check_page_for_string( 'The group has been marked as deleted' ) self.home() - def undelete_group( self, group_id='' ): + def undelete_group( self, group_id ): """Undelete an existing group""" self.visit_url( "%s/admin/undelete_group?group_id=%s" % ( self.url, group_id ) ) self.last_page() self.check_page_for_string( 'The group has been marked as not deleted' ) self.home() - def purge_group( self, group=None ): + def purge_group( self, group_id, deleted=False ): """Purge an existing group""" - if not group.deleted: - self.mark_group_deleted( group_id=group.id ) - group_id = str( group.id ) - group_name = group.name.replace( ' ', '+' ) - self.visit_url( "%s/admin/deleted_groups" % self.url ) - self.check_page_for_string( '%s' % group.name ) + if not deleted: + self.mark_group_deleted( group_id ) self.visit_url( "%s/admin/purge_group?group_id=%s" % ( self.url, group_id ) ) self.last_page() self.check_page_for_string( 'The group has been purged from the database' ) diff --git a/test/functional/test_security_and_libraries.py b/test/functional/test_security_and_libraries.py index 34cb6cc32ca..ed4e68a5c2c 100644 --- a/test/functional/test_security_and_libraries.py +++ b/test/functional/test_security_and_libraries.py @@ -1,5 +1,5 @@ import galaxy.model -from base.twilltestcase import TwillTestCase +from base.twilltestcase import * s = 'You must have Galaxy administrator privileges to use this feature.' @@ -45,66 +45,126 @@ class TestHistory( TwillTestCase ): self.visit_page( "admin" ) self.check_page_for_string( 'Administration' ) user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test@bx.psu.edu' ).first() + # Make sure a private role exists for the user + private_role_found = False + for role in user.all_roles(): + if role.name == user.email and role.description == 'Private Role for %s' % user.email: + private_role_found = True + break + if not private_role_found: + raise AssertionError( "Private role not found for user '%s'" % user.email ) self.visit_url( "%s/admin/user?user_id=%s" % ( self.url, user.id ) ) self.check_page_for_string( "test@bx.psu.edu" ) self.home() self.logout() - # Need to ensure that we have 2 users + # Make sure that we have 3 users self.login( email='test2@bx.psu.edu' ) # This will not be an admin user self.visit_page( "admin" ) self.check_page_for_string( s ) self.logout() + self.login( email='test3@bx.psu.edu' ) # This will not be an admin user + self.visit_page( "admin" ) + self.check_page_for_string( s ) + self.logout() def test_10_create_role( self ): """Testing creating new non-private role with 2 members""" self.login( email='test@bx.psu.edu' ) - self.visit_page( "admin/create_role" ) - self.check_page_for_string( 'Create Role' ) user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test@bx.psu.edu' ).first() user_id1 = str( user.id ) user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test2@bx.psu.edu' ).first() user_id2 = str( user.id ) - self.create_role( user_ids=[user_id1, user_id2] ) - self.visit_page( "admin/roles" ) - self.check_page_for_string( "New Test Role" ) + self.create_role( user_ids=[ user_id1, user_id2 ] ) def test_15_create_group( self ): """Testing creating new group with 2 members and 1 associated role""" - self.visit_page( "admin/create_group" ) - self.check_page_for_string( 'Create Group' ) user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test@bx.psu.edu' ).first() user_id1 = str( user.id ) user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test2@bx.psu.edu' ).first() user_id2 = str( user.id ) role = galaxy.model.Role.filter( galaxy.model.Role.table.c.name=='New Test Role' ).first() role_id = str( role.id ) - self.create_group( user_ids=[user_id1, user_id2], role_ids=[role_id] ) - self.visit_page( "admin/groups" ) - self.check_page_for_string( "New Test Group" ) + self.create_group( user_ids=[ user_id1, user_id2 ], role_ids=[ role_id ] ) def test_20_add_group_member( self ): """Testing editing membership of an existing group""" - self.create_group( 'Another Test Group' ) + self.create_group( name='Another Test Group' ) + group = galaxy.model.Group.filter( galaxy.model.Group.table.c.name == 'Another Test Group' ).first() + group_id = str( group.id ) + user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test3@bx.psu.edu' ).first() + user_id = str( user.id ) + self.add_group_members( group_id, [ user_id ] ) + self.visit_url( "%s/admin/group_members_edit?group_id=%s" % ( self.url, group_id ) ) + self.check_page_for_string( 'test3@bx.psu.edu' ) + def test_25_associate_groups_with_role( self ): + """Testing adding existing groups to an existing role""" + group = galaxy.model.Group.filter( galaxy.model.Group.table.c.name == 'Another Test Group' ).first() + group_id = str( group.id ) + user = galaxy.model.User.filter( galaxy.model.User.table.c.email == 'test@bx.psu.edu' ).first() + user_id = str( user.id ) + # NOTE: To get this to work with twill, all select lists on the ~/admin/role page must contain at least + # 1 option value or twill throws an exception, which is: ParseError: OPTION outside of SELECT + # Due to this bug in twill, we crreate the role, associating it with at least 1 user and 1 group... + # + # TODO: need to enhance this test to associate DefaultUserPermissions and DefaultHistoryPermissions + # with the role, then add tests in test_55_purge_role to make sure the association records are deleted + # when the role is purged. + self.create_role( name='Another Test Role', user_ids=[ user_id ], group_ids=[ group_id ] ) + role = galaxy.model.Role.filter( galaxy.model.Role.table.c.name=='Another Test Role' ).first() + role_id = str( role.id ) group = galaxy.model.Group.filter( galaxy.model.Group.table.c.name == 'New Test Group' ).first() group_id = str( group.id ) - self.add_group_member( group_id ) - self.visit_page( 'admin/group_members_edit?group_id=%s' % group_id ) - self.check_page_for_string( 'test@bx.psu.edu' ) - self.check_page_for_string( 'test2@bx.psu.edu' ) - #def test_20_delete_group( self ): - # """Testing deleting a group""" - # self.visit_page( "admin/groups" ) - # self.check_page_for_string( "group_name=New+Test+Group" ) - # group = galaxy.model.Group.filter_by( name='New Test Group' ).all()[0] - # group_id = str( group.id ) - # self.mark_group_deleted( group_id=group_id ) - #def test_25_undelete_group( self ): - # """Testing undeleting a deleted group""" - # group = galaxy.model.Group.filter_by( name='New Test Group' ).all()[0] - # group_id = str( group.id ) - # self.undelete_group( group_id=group_id ) - #def test_30_purge_group( self ): - # """Testing purging a group""" - # group = galaxy.model.Group.filter_by( name='New Test Group' ).all()[0] - # self.purge_group( group=group ) - + # ...and then we associate the role with a group not yet associated + self.associate_groups_with_role( role_id, group_ids=[ group_id ] ) + self.visit_page( 'admin/roles' ) + self.check_page_for_string( 'New Test Group' ) + def test_30_mark_group_deleted( self ): + """Testing marking a group as deleted""" + self.visit_page( "admin/groups" ) + self.check_page_for_string( "Another Test Group" ) + group = galaxy.model.Group.filter( galaxy.model.Group.table.c.name == 'Another Test Group' ).first() + group_id = str( group.id ) + self.mark_group_deleted( group_id ) + def test_35_undelete_group( self ): + """Testing undeleting a deleted group""" + group = galaxy.model.Group.filter( galaxy.model.Group.table.c.name == 'Another Test Group' ).first() + group_id = str( group.id ) + self.undelete_group( group_id ) + def test_40_mark_role_deleted( self ): + """Testing marking a role as deleted""" + self.visit_page( "admin/roles" ) + self.check_page_for_string( "Another Test Role" ) + role = galaxy.model.Role.filter( galaxy.model.Role.table.c.name == 'Another Test Role' ).first() + role_id = str( role.id ) + self.mark_role_deleted( role_id ) + def test_45_undelete_role( self ): + """Testing undeleting a deleted role""" + role = galaxy.model.Role.filter( galaxy.model.Role.table.c.name == 'Another Test Role' ).first() + role_id = str( role.id ) + self.undelete_role( role_id ) + def test_50_purge_group( self ): + """Testing purging a group""" + group = galaxy.model.Group.filter( galaxy.model.Group.table.c.name == 'Another Test Group' ).first() + group_id = str( group.id ) + self.purge_group( group_id ) + # Make sure there are no UserGroupAssociations + uga = galaxy.model.UserGroupAssociation.filter( galaxy.model.UserGroupAssociation.table.c.group_id == group_id ).all() + if uga: + raise AssertionError( "Purging the group did not delete the UserGroupAssociations for group_id '%s'" % group_id ) + # Make sure there are no GroupRoleAssociations + gra = galaxy.model.GroupRoleAssociation.filter( galaxy.model.GroupRoleAssociation.table.c.group_id == group_id ).all() + if gra: + raise AssertionError( "Purging the group did not delete the GroupRoleAssociations for group_id '%s'" % group_id ) + def test_55_purge_role( self ): + """Testing purging a role""" + role = galaxy.model.Role.filter( galaxy.model.Role.table.c.name == 'Another Test Role' ).first() + role_id = str( role.id ) + self.purge_role( role_id ) + # Make sure there are no GroupRoleAssociations + gra = galaxy.model.GroupRoleAssociation.filter( galaxy.model.GroupRoleAssociation.table.c.role_id == role_id ).all() + if gra: + raise AssertionError( "Purging the role did not delete the GroupRoleAssociations for role_id '%s'" % role_id ) + # Make sure there are no ActionDatasetRoleAssociations + adra = galaxy.model.ActionDatasetRoleAssociation.filter( galaxy.model.ActionDatasetRoleAssociation.table.c.role_id == role_id ).all() + if adra: + raise AssertionError( "Purging the role did not delete the ActionDatasetRoleAssociations for role_id '%s'" % role_id ) #def test_20_create_library( self ): # """Testing creating new library""" # self.create_library( name='New Test Library', description='New Test Library Description' )