commit/galaxy-central: greg: Fix some broken functional tests and fixes for deleting multiple data libraries and resetting the password for multiple users. Fixes issue # 678.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/e69c868b6891/ changeset: e69c868b6891 user: greg date: 2011-12-05 15:58:36 summary: Fix some broken functional tests and fixes for deleting multiple data libraries and resetting the password for multiple users. Fixes issue # 678. affected #: 7 files diff -r 627260f26eba2116bc6bfecf285d7d04d12a912b -r e69c868b6891ccf6deabcba8a767cdf31593d1be lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -5,6 +5,7 @@ from datetime import date, datetime, timedelta from time import strftime from galaxy import config, tools, web, util +from galaxy.util import inflector from galaxy.util.hash_util import * from galaxy.util.json import json_fix from galaxy.web import error, form, url_for @@ -2030,28 +2031,28 @@ @web.require_admin def reset_user_password( self, trans, **kwd ): webapp = kwd.get( 'webapp', 'galaxy' ) - id = kwd.get( 'id', None ) - if not id: - message = "No user ids received for resetting passwords" + user_id = kwd.get( 'id', None ) + if not user_id: + message = "No users received for resetting passwords." trans.response.send_redirect( web.url_for( controller='admin', action='users', webapp=webapp, message=message, status='error' ) ) - ids = util.listify( id ) + user_ids = util.listify( user_id ) if 'reset_user_password_button' in kwd: message = '' status = '' - for user_id in ids: + for user_id in user_ids: user = get_user( trans, user_id ) password = kwd.get( 'password', None ) confirm = kwd.get( 'confirm' , None ) if len( password ) < 6: - message = "Please use a password of at least 6 characters" + message = "Use a password of at least 6 characters." status = 'error' break elif password != confirm: - message = "Passwords do not match" + message = "Passwords do not match." status = 'error' break else: @@ -2059,18 +2060,18 @@ trans.sa_session.add( user ) trans.sa_session.flush() if not message and not status: - message = "Passwords reset for %d users" % len( ids ) + message = "Passwords reset for %d %s." % ( len( user_ids ), inflector.cond_plural( len( user_ids ), 'user' ) ) status = 'done' trans.response.send_redirect( web.url_for( controller='admin', action='users', webapp=webapp, message=util.sanitize_text( message ), status=status ) ) - users = [ get_user( trans, user_id ) for user_id in ids ] - if len( ids ) > 1: - id=','.join( id ) + users = [ get_user( trans, user_id ) for user_id in user_ids ] + if len( user_ids ) > 1: + user_id = ','.join( user_ids ) return trans.fill_template( '/admin/user/reset_password.mako', - id=id, + id=user_id, users=users, password='', confirm='', @@ -2435,13 +2436,11 @@ # overwrite it in case it contains stuff proprietary to the local instance. if not os.path.exists( os.path.join( tool_data_path, loc_file ) ): shutil.copy( os.path.abspath( filename ), os.path.join( tool_data_path, loc_file ) ) -def get_user( trans, id ): +def get_user( trans, user_id ): """Get a User from the database by id.""" - # Load user from database - id = trans.security.decode_id( id ) - user = trans.sa_session.query( trans.model.User ).get( id ) + user = trans.sa_session.query( trans.model.User ).get( trans.security.decode_id( user_id ) ) if not user: - return trans.show_error_message( "User not found for id (%s)" % str( id ) ) + return trans.show_error_message( "User not found for id (%s)" % str( user_id ) ) return user def get_user_by_username( trans, username ): """Get a user from the database by username""" diff -r 627260f26eba2116bc6bfecf285d7d04d12a912b -r e69c868b6891ccf6deabcba8a767cdf31593d1be lib/galaxy/web/controllers/library_common.py --- a/lib/galaxy/web/controllers/library_common.py +++ b/lib/galaxy/web/controllers/library_common.py @@ -2250,6 +2250,7 @@ # contents will be purged. The association between this method and the cleanup_datasets.py script # enables clean maintenance of libraries and library dataset disk files. This is also why the item_types # are not any of the associations ( the cleanup_datasets.py script handles everything ). + status = kwd.get( 'status', 'done' ) show_deleted = util.string_as_bool( kwd.get( 'show_deleted', False ) ) item_types = { 'library': trans.app.model.Library, 'folder': trans.app.model.LibraryFolder, @@ -2264,22 +2265,36 @@ item_desc = 'Dataset' else: item_desc = item_type.capitalize() - try: - library_item = trans.sa_session.query( item_types[ item_type ] ).get( trans.security.decode_id( item_id ) ) - except: - library_item = None - if not library_item or not ( is_admin or trans.app.security_agent.can_access_library_item( current_user_roles, library_item, trans.user ) ): - message = 'Invalid %s id ( %s ) specifield.' % ( item_desc, item_id ) + library_item_ids = util.listify( item_id ) + valid_items = 0 + invalid_items = 0 + not_authorized_items = 0 + flush_needed = False + message = '' + for library_item_id in library_item_ids: + try: + library_item = trans.sa_session.query( item_types[ item_type ] ).get( trans.security.decode_id( library_item_id ) ) + except: + library_item = None + if not library_item or not ( is_admin or trans.app.security_agent.can_access_library_item( current_user_roles, library_item, trans.user ) ): + invalid_items += 1 + elif not ( is_admin or trans.app.security_agent.can_modify_library_item( current_user_roles, library_item ) ): + not_authorized_items += 1 + else: + valid_items += 1 + library_item.deleted = True + trans.sa_session.add( library_item ) + flush_needed = True + if flush_needed: + trans.sa_session.flush() + if valid_items: + message += "%d %s marked deleted. " % ( valid_items, inflector.cond_plural( valid_items, item_desc ) ) + if invalid_items: + message += '%d invalid %s specifield. ' % ( invalid_items, inflector.cond_plural( invalid_items, item_desc ) ) status = 'error' - elif not ( is_admin or trans.app.security_agent.can_modify_library_item( current_user_roles, library_item ) ): - message = "You are not authorized to delete %s '%s'." % ( item_desc, library_item.name ) + if not_authorized_items: + message += 'You are not authorized to delete %d %s. ' % ( not_authorized_items, inflector.cond_plural( not_authorized_items, item_desc ) ) status = 'error' - else: - library_item.deleted = True - trans.sa_session.add( library_item ) - trans.sa_session.flush() - message = util.sanitize_text( "%s '%s' has been marked deleted" % ( item_desc, library_item.name ) ) - status = 'done' if item_type == 'library': return trans.response.send_redirect( web.url_for( controller=cntrller, action='browse_libraries', @@ -2296,6 +2311,7 @@ @web.expose def undelete_library_item( self, trans, cntrller, library_id, item_id, item_type, **kwd ): # This action will handle undeleting all types of library items + status = kwd.get( 'status', 'done' ) show_deleted = util.string_as_bool( kwd.get( 'show_deleted', False ) ) item_types = { 'library': trans.app.model.Library, 'folder': trans.app.model.LibraryFolder, @@ -2304,31 +2320,49 @@ current_user_roles = trans.get_current_user_roles() if item_type not in item_types: message = 'Bad item_type specified: %s' % str( item_type ) - status = ERROR + status = 'error' else: if item_type == 'library_dataset': item_desc = 'Dataset' else: item_desc = item_type.capitalize() - try: - library_item = trans.sa_session.query( item_types[ item_type ] ).get( trans.security.decode_id( item_id ) ) - except: - library_item = None - if not library_item or not ( is_admin or trans.app.security_agent.can_access_library_item( current_user_roles, library_item, trans.user ) ): - message = 'Invalid %s id ( %s ) specifield.' % ( item_desc, item_id ) + + library_item_ids = util.listify( item_id ) + valid_items = 0 + invalid_items = 0 + purged_items = 0 + not_authorized_items = 0 + flush_needed = False + message = '' + for library_item_id in library_item_ids: + try: + library_item = trans.sa_session.query( item_types[ item_type ] ).get( trans.security.decode_id( library_item_id ) ) + except: + library_item = None + if not library_item or not ( is_admin or trans.app.security_agent.can_access_library_item( current_user_roles, library_item, trans.user ) ): + invalid_items += 1 + elif library_item.purged: + purged_items += 1 + elif not ( is_admin or trans.app.security_agent.can_modify_library_item( current_user_roles, library_item ) ): + not_authorized_items += 1 + else: + valid_items += 1 + library_item.deleted = False + trans.sa_session.add( library_item ) + flush_needed = True + if flush_needed: + trans.sa_session.flush() + if valid_items: + message += "%d %s marked undeleted. " % ( valid_items, inflector.cond_plural( valid_items, item_desc ) ) + if invalid_items: + message += '%d invalid %s specifield. ' % ( invalid_items, inflector.cond_plural( invalid_items, item_desc ) ) status = 'error' - elif library_item.purged: - message = '%s %s has been purged, so it cannot be undeleted' % ( item_desc, library_item.name ) - status = ERROR - elif not ( is_admin or trans.app.security_agent.can_modify_library_item( current_user_roles, library_item ) ): - message = "You are not authorized to delete %s '%s'." % ( item_desc, library_item.name ) - status = 'error' - else: - library_item.deleted = False - trans.sa_session.add( library_item ) - trans.sa_session.flush() - message = util.sanitize_text( "%s '%s' has been marked undeleted" % ( item_desc, library_item.name ) ) - status = SUCCESS + if not_authorized_items: + message += 'You are not authorized to undelete %d %s. ' % ( not_authorized_items, inflector.cond_plural( not_authorized_items, item_desc ) ) + status = 'error' + if purged_items: + message += '%d %s marked purged, so cannot be undeleted. ' % ( purged_items, inflector.cond_plural( purged_items, item_desc ) ) + status = 'error' if item_type == 'library': return trans.response.send_redirect( web.url_for( controller=cntrller, action='browse_libraries', diff -r 627260f26eba2116bc6bfecf285d7d04d12a912b -r e69c868b6891ccf6deabcba8a767cdf31593d1be test/base/twilltestcase.py --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -1224,7 +1224,7 @@ tc.fv( "1", "password", password ) tc.fv( "1", "confirm", password ) tc.submit( "reset_user_password_button" ) - self.check_page_for_string( "Passwords reset for 1 users" ) + self.check_page_for_string( "Passwords reset for 1 user." ) self.home() def mark_user_deleted( self, user_id, email='' ): """Mark a user as deleted""" @@ -2278,7 +2278,7 @@ item_desc = 'Dataset' else: item_desc = item_type.capitalize() - check_str = "%s '%s' has been marked deleted" % ( item_desc, item_name ) + check_str = "marked deleted" self.check_page_for_string( check_str ) self.home() def undelete_library_item( self, cntrller, library_id, item_id, item_name, item_type='library_dataset' ): @@ -2290,7 +2290,7 @@ item_desc = 'Dataset' else: item_desc = item_type.capitalize() - check_str = "%s '%s' has been marked undeleted" % ( item_desc, item_name ) + check_str = "marked undeleted" self.check_page_for_string( check_str ) self.home() def purge_library( self, library_id, library_name ): diff -r 627260f26eba2116bc6bfecf285d7d04d12a912b -r e69c868b6891ccf6deabcba8a767cdf31593d1be test/functional/test_library_features.py --- a/test/functional/test_library_features.py +++ b/test/functional/test_library_features.py @@ -137,7 +137,7 @@ assert ldda2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda2 from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ ldda2.name, ldda2.message, admin_user.email ] ) + strings_displayed=[ ldda2.name, ldda2.message, 'bed' ] ) def test_050_add_2nd_public_dataset_to_folder2( self ): """Testing adding a 2nd public dataset folder2""" # Logged in as admin_user @@ -156,7 +156,7 @@ assert ldda3 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda3 from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ ldda3.name, ldda3.message, admin_user.email ] ) + strings_displayed=[ ldda3.name, ldda3.message, 'bed' ] ) def test_055_copy_dataset_from_history_to_subfolder( self ): """Testing copying a dataset from the current history to a subfolder""" # logged in as admin_user @@ -176,7 +176,7 @@ assert ldda4 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda4 from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ ldda4.name, ldda4.message, admin_user.email ] ) + strings_displayed=[ ldda4.name, ldda4.message, 'bed' ] ) def test_060_editing_dataset_attribute_info( self ): """Testing editing a library dataset's attribute information""" # logged in as admin_user @@ -299,11 +299,11 @@ ldda_message = 'Uploaded all files in test-data/users/test1...' self.browse_library( 'library', self.security.encode_id( library1.id ), - strings_displayed=[ regular_user1.email, ldda_message, '1.fasta' ] ) + strings_displayed=[ 'fasta', ldda_message, '1.fasta' ] ) ldda_message = 'Uploaded all files in test-data/users/test3.../run1' self.browse_library( 'library', self.security.encode_id( library1.id ), - strings_displayed=[ regular_user3.email, ldda_message, '2.fasta' ] ) + strings_displayed=[ 'fasta', ldda_message, '2.fasta' ] ) def test_085_mark_ldda2_deleted( self ): """Testing marking ldda2 as deleted""" # Logged in as admin_user diff -r 627260f26eba2116bc6bfecf285d7d04d12a912b -r e69c868b6891ccf6deabcba8a767cdf31593d1be test/functional/test_library_security.py --- a/test/functional/test_library_security.py +++ b/test/functional/test_library_security.py @@ -157,7 +157,7 @@ assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ ldda1.name, ldda1.message, admin_user.email ] ) + strings_displayed=[ ldda1.name, ldda1.message, 'bed' ] ) def test_030_access_ldda1_with_private_role_restriction( self ): """Testing accessing ldda1 with a private role restriction""" # Logged in as admin_user @@ -262,20 +262,20 @@ assert ldda2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda2 from the database' self.browse_library( cntrller='library', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ ldda2.name, ldda2.message, admin_user.email ] ) + strings_displayed=[ ldda2.name, ldda2.message, 'bed' ] ) def test_045_accessing_ldda2_with_role_associated_with_group_and_users( self ): """Testing accessing ldda2 with a role that is associated with a group and users""" # Logged in as admin_user # admin_user should be able to see 2.bed since she is associated with role2 self.browse_library( cntrller='library', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ ldda2.name, ldda2.message, admin_user.email ] ) + strings_displayed=[ ldda2.name, ldda2.message, 'bed' ] ) self.logout() # regular_user1 should be able to see 2.bed since she is associated with group_two self.login( email = regular_user1.email ) self.browse_library( cntrller='library', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ folder1.name, ldda2.name, ldda2.message, admin_user.email ] ) + strings_displayed=[ folder1.name, ldda2.name, ldda2.message, 'bed' ] ) # Check the permissions on the dataset 2.bed - they are as folows: # DATASET_MANAGE_PERMISSIONS = test@bx.psu.edu # DATASET_ACCESS = Role2 @@ -356,7 +356,7 @@ strings_displayed=[ "Upload a directory of files" ] ) self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ admin_user.email, ldda_message ] ) + strings_displayed=[ 'bed', ldda_message ] ) def test_055_change_permissions_on_datasets_uploaded_from_library_dir( self ): """Testing changing the permissions on datasets uploaded from a directory from the Admin view""" # logged in as admin_user diff -r 627260f26eba2116bc6bfecf285d7d04d12a912b -r e69c868b6891ccf6deabcba8a767cdf31593d1be test/functional/test_library_templates.py --- a/test/functional/test_library_templates.py +++ b/test/functional/test_library_templates.py @@ -181,7 +181,7 @@ assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library1.id ), - strings_displayed=[ ldda1.name, ldda1.message, admin_user.email ] ) + strings_displayed=[ ldda1.name, ldda1.message, 'bed' ] ) # Make sure the library template contents were correctly saved self.ldda_edit_info( 'library_admin', self.security.encode_id( library1.id ), @@ -308,7 +308,7 @@ assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library2.id ), - strings_displayed=[ ldda.name, ldda.message, admin_user.email ] ) + strings_displayed=[ ldda.name, ldda.message, 'bed' ] ) # Make sure the library template contents were correctly saved self.ldda_edit_info( 'library_admin', self.security.encode_id( library2.id ), @@ -363,8 +363,7 @@ 'Option1' ] ) def test_100_add_ldda_to_folder3( self ): """ - Testing adding a new library dataset to library3's folder, - making sure the SelectField setting is correct on the upload form. + Testing adding a new library dataset to library3's folder, making sure the SelectField setting is correct on the upload form. """ filename = '3.bed' ldda_message = '3.bed message' @@ -381,7 +380,7 @@ assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library3.id ), - strings_displayed=[ ldda.name, ldda.message, admin_user.email ] ) + strings_displayed=[ ldda.name, ldda.message, 'bed' ] ) # Make sure the library template contents were correctly saved self.ldda_edit_info( 'library_admin', self.security.encode_id( library3.id ), @@ -453,8 +452,7 @@ 'This text should be inherited' ] ) def test_120_add_ldda_to_folder4( self ): """ - Testing adding a new library dataset to library4's folder, - making sure the TextArea setting is correct on the upload form. + Testing adding a new library dataset to library4's folder, making sure the TextArea setting is correct on the upload form. """ filename = '4.bed' ldda_message = '4.bed message' @@ -471,7 +469,7 @@ assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library4.id ), - strings_displayed=[ ldda.name, ldda.message, admin_user.email ] ) + strings_displayed=[ ldda.name, ldda.message, 'bed' ] ) # Make sure the library template contents were correctly saved self.ldda_edit_info( 'library_admin', self.security.encode_id( library4.id ), @@ -519,8 +517,7 @@ 'This text should be inherited' ] ) def test_140_add_ldda_to_folder5( self ): """ - Testing adding a new library dataset to library5's folder, - making sure the TextField setting is correct on the upload form. + Testing adding a new library dataset to library5's folder, making sure the TextField setting is correct on the upload form. """ # Logged in as admin_user filename = '5.bed' @@ -537,7 +534,7 @@ assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library5.id ), - strings_displayed=[ ldda.name, ldda.message, admin_user.email ] ) + strings_displayed=[ ldda.name, ldda.message, 'bed' ] ) # Make sure the library template contents were correctly saved self.ldda_edit_info( 'library_admin', self.security.encode_id( library5.id ), @@ -558,9 +555,7 @@ field_default_1='%s default' % TextArea_form.name ) def test_150_add_ldda_to_library5( self ): """ - Testing adding a new library dataset to library5's folder, - making sure the TextField and new TextArea settings are - correct on the upload form. + Testing adding a new library dataset to library5's folder, making sure the TextField and new TextArea settings are correct on the upload form. """ filename = '6.bed' ldda_message = '6.bed message' @@ -579,7 +574,7 @@ assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library5.id ), - strings_displayed=[ ldda.name, ldda.message, admin_user.email ] ) + strings_displayed=[ ldda.name, ldda.message, 'bed' ] ) # Make sure the library template contents were correctly saved self.ldda_edit_info( 'library_admin', self.security.encode_id( library5.id ), @@ -626,8 +621,7 @@ 'none' ] ) def test_170_add_ldda_to_folder6( self ): """ - Testing adding a new library dataset to library6's folder, - making sure the WorkflowField setting is correct on the upload form. + Testing adding a new library dataset to library6's folder, making sure the WorkflowField setting is correct on the upload form. """ # Logged in as admin_user filename = '7.bed' @@ -644,7 +638,7 @@ assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database' self.browse_library( cntrller='library_admin', library_id=self.security.encode_id( library6.id ), - strings_displayed=[ ldda.name, ldda.message, admin_user.email ] ) + strings_displayed=[ ldda.name, ldda.message, 'bed' ] ) # Make sure the library template contents were correctly saved self.ldda_edit_info( 'library_admin', self.security.encode_id( library6.id ), diff -r 627260f26eba2116bc6bfecf285d7d04d12a912b -r e69c868b6891ccf6deabcba8a767cdf31593d1be test/functional/test_user_info.py --- a/test/functional/test_user_info.py +++ b/test/functional/test_user_info.py @@ -206,7 +206,7 @@ self.edit_user_info( cntrller='user', password='testuser', new_password='testuser#',\ - strings_displayed_after_submit=[ 'The password has been changed.' ] ) + strings_displayed_after_submit=[ 'The password has been changed' ] ) self.logout() refresh( regular_user12 ) # Test logging in with new email and password 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)
-
Bitbucket