details: http://www.bx.psu.edu/hg/galaxy/rev/386e245f8076 changeset: 2415:386e245f8076 user: Greg Von Kuster <greg@bx.psu.edu> date: Thu May 21 15:48:39 2009 -0400 description: Bug fixes and new functional tests for library features that were missing them. 17 file(s) affected in this change: lib/galaxy/model/__init__.py lib/galaxy/web/controllers/admin.py lib/galaxy/web/controllers/library.py templates/admin/library/browse_library.mako templates/admin/library/common.mako templates/admin/library/edit_info_template.mako templates/admin/library/folder_info.mako templates/admin/library/ldda_edit_info.mako templates/admin/library/new_info_template.mako templates/library/browse_library.mako templates/library/common.mako templates/library/edit_info_template.mako templates/library/ldda_edit_info.mako templates/library/library_dataset_info.mako templates/library/new_info_template.mako test/base/twilltestcase.py test/functional/test_security_and_libraries.py diffs (2528 lines): diff -r 1a82088aac38 -r 386e245f8076 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Thu May 21 11:32:25 2009 -0400 +++ b/lib/galaxy/model/__init__.py Thu May 21 15:48:39 2009 -0400 @@ -300,6 +300,9 @@ class LibraryItemInfoPermissions( object ): def __init__( self, action, library_item, role ): + # LIBRARY_ADD -> Not Applicable + # LIBRARY_MODIFY -> Can modify LibraryItemInfoElement.contents + # LIBRARY_MANAGE -> Can change permissions on LibraryItemInfo self.action = action if isinstance( library_item, LibraryItemInfo ): self.library_item_info = library_item @@ -309,6 +312,9 @@ class LibraryItemInfoTemplatePermissions( object ): def __init__( self, action, library_item, role ): + # LIBRARY_ADD -> Not Applicable + # LIBRARY_MODIFY -> Can add or delete LibraryItemInfoTemplateElements + # LIBRARY_MANAGE -> Can change permissions on LibraryItemInfoTemplate self.action = action if isinstance( library_item, LibraryItemInfoTemplate ): self.library_item_info_template = library_item @@ -673,7 +679,9 @@ self.description = description self.root_folder = root_folder def get_library_item_info_templates( self, template_list=[], restrict=False ): - if self.library_info_template_associations: + # We only want the next available template in the inheritable hierarchy, so we'll only extend + # template_list if it is empty + if not template_list and self.library_info_template_associations: template_list.extend( [ lita.library_item_info_template for lita in self.library_info_template_associations if lita.library_item_info_template not in template_list ] ) return template_list @@ -696,11 +704,13 @@ self.item_count += 1 def get_library_item_info_templates( self, template_list=[], restrict=False ): # If restrict is True, we'll return only those templates directly associated with this Folder - if self.library_folder_info_template_associations: + # We only want the next available template in the inheritable hierarchy, so we'll only extend + # template_list if it is empty + if not template_list and self.library_folder_info_template_associations: template_list.extend( [ lfita.library_item_info_template for lfita in self.library_folder_info_template_associations if lfita.library_item_info_template not in template_list ] ) - if restrict not in [ 'True', True ] and self.parent: + if not template_list and restrict not in [ 'True', True ] and self.parent: self.parent.get_library_item_info_templates( template_list ) - elif restrict not in [ 'True', True, 'folder' ] and self.library_root: + elif not template_list and restrict not in [ 'True', True, 'folder' ] and self.library_root: for library_root in self.library_root: library_root.get_library_item_info_templates( template_list ) return template_list @@ -759,9 +769,11 @@ purged = property( get_purged, set_purged ) def get_library_item_info_templates( self, template_list=[], restrict=False ): # If restrict is True, we'll return only those templates directly associated with this LibraryDataset - if self.library_dataset_info_template_associations: + # We only want the next available template in the inheritable hierarchy, so we'll only extend + # template_list if it is empty + if not template_list and self.library_dataset_info_template_associations: template_list.extend( [ ldita.library_item_info_template for ldita in self.library_dataset_info_template_associations if ldita.library_item_info_template not in template_list ] ) - if restrict not in [ 'True', True ]: + if not template_list and restrict not in [ 'True', True ]: self.folder.get_library_item_info_templates( template_list, restrict ) return template_list @@ -828,9 +840,12 @@ return def get_library_item_info_templates( self, template_list=[], restrict=False ): # If restrict is True, we'll return only those templates directly associated with this LibraryDatasetDatasetAssociation - if self.library_dataset_dataset_info_template_associations: + # We only want the next available template in the inheritable hierarchy, so we'll only extend + # template_list if it is empty + if not template_list and self.library_dataset_dataset_info_template_associations: template_list.extend( [ lddita.library_item_info_template for lddita in self.library_dataset_dataset_info_template_associations if lddita.library_item_info_template not in template_list ] ) - self.library_dataset.get_library_item_info_templates( template_list, restrict ) + if not template_list: + self.library_dataset.get_library_item_info_templates( template_list, restrict ) return template_list class LibraryInfoTemplateAssociation( object ): @@ -902,11 +917,22 @@ class LibraryItemInfo( object ): def __init__( self, user=None ): self.user = user - def get_element_by_template_element( self, template_element ): + def get_element_by_template_element( self, template_element, create_element=False ): for element in self.elements: if element.library_item_info_template_element == template_element: return element - raise 'element not found' + if create_element: + # Template elements may have been added to the template after the + # library item initially inherited it, so we'll add the additional + # element to the library item + element = LibraryItemInfoElement() + element.library_item_info_template_element = template_element + element.library_item_info = self + element.flush() + self.elements.append( element ) + return element + else: + return None class LibraryItemInfoElement( object ): pass diff -r 1a82088aac38 -r 386e245f8076 lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Thu May 21 11:32:25 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Thu May 21 15:48:39 2009 -0400 @@ -848,32 +848,6 @@ show_deleted=True ) @web.expose @web.require_admin - def undelete_library( self, trans, **kwd ): - params = util.Params( kwd ) - library = trans.app.model.Library.get( int( params.id ) ) - def undelete_folder( library_folder ): - for folder in library_folder.folders: - folder.refresh() - undelete_folder( folder ) - library_folder.refresh() - for library_dataset in library_folder.datasets: - library_dataset.refresh() - ldda = library_dataset.library_dataset_dataset_association - if ldda: - ldda.refresh() - ldda.deleted = False - ldda.flush() - library_dataset.deleted = False - library_dataset.flush() - library_folder.deleted = False - library_folder.flush() - undelete_folder( library.root_folder ) - library.deleted = False - library.flush() - msg = "Library '%s' and all of its contents have been marked not deleted" % library.name - return trans.response.send_redirect( web.url_for( action='browse_libraries', msg=util.sanitize_text( msg ), messagetype='done' ) ) - @web.expose - @web.require_admin def purge_library( self, trans, **kwd ): params = util.Params( kwd ) library = trans.app.model.Library.get( int( params.id ) ) @@ -1104,7 +1078,7 @@ last_used_build = folder.genome_build replace_id = params.get( 'replace_id', None ) if replace_id: - replace_dataset = trans.app.model.LibraryDataset.get( params.get( 'replace_id', None ) ) + replace_dataset = trans.app.model.LibraryDataset.get( int( replace_id ) ) if not last_used_build: last_used_build = replace_dataset.library_dataset_dataset_association.dbkey else: @@ -1197,6 +1171,8 @@ permissions = {} accessible = False for k, v in trans.app.model.Dataset.permitted_actions.items(): + # TODO: need to handle case where a user has the DATASET_MANAGE_PERMISSIONS permission, but not + # the DATASET_ACCESS permission, making the former useless. Need to display a warning message. in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ] # At least 1 user must have every role associated with this dataset, or the dataset is inaccessible if v == trans.app.security_agent.permitted_actions.DATASET_ACCESS: @@ -1381,6 +1357,8 @@ permissions = {} accessible = False for k, v in trans.app.model.Dataset.permitted_actions.items(): + # TODO: need to handle case where a user has the DATASET_MANAGE_PERMISSIONS permission, but not + # the DATASET_ACCESS permission, making the former useless. Need to display a warning message. in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ] # At least 1 user must have every role associated with this dataset, or the dataset is inaccessible if v == trans.app.security_agent.permitted_actions.DATASET_ACCESS: @@ -1567,7 +1545,7 @@ messagetype=messagetype ) @web.expose @web.require_admin - def info_template( self, trans, library_id, id=None, num_fields=0, folder_id=None, ldda_id=None, library_dataset_id=None, **kwd ): + def info_template( self, trans, library_id, id=None, num_fields=0, folder_id=None, ldda_id=None, library_dataset_id=None, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) @@ -1646,7 +1624,7 @@ liit.description = util.restore_text( params.get( 'description', '' ) ) liit.flush() # Inherit the template's permissions from the library_item - trans.app.security_agent.copy_library_permissions( liit, library_item ) + trans.app.security_agent.copy_library_permissions( library_item, liit ) # Create template association if folder_id: liit_assoc = trans.app.model.LibraryFolderInfoTemplateAssociation() @@ -1694,7 +1672,13 @@ msg=msg, messagetype=messagetype ) elif action == 'edit_template': - if params.get( 'edit_info_template_button', False ): + define_or_save = 'define' + edit_info_template_button = params.get( 'edit_info_template_button', False ) + if edit_info_template_button: + if edit_info_template_button == 'Define fields': + define_or_save = 'save' + else: + define_or_save = 'define' # Save changes to existing attributes, only set name if nonempty/nonNone is passed, but always set description name = params.get( 'name', None ) if name: @@ -1702,7 +1686,7 @@ library_item.description = params.get( 'description', '' ) library_item.flush() # Save changes to exisiting elements - for elem_id in params.get( 'element_ids', [] ): + for elem_id in util.listify( params.get( 'element_ids', [] ) ): liit_element = trans.app.model.LibraryItemInfoTemplateElement.get( elem_id ) name = params.get( 'element_name_%s' % elem_id, None ) if name: @@ -1721,7 +1705,7 @@ if elem_name: library_item.add_element( name=elem_name, description=elem_description ) library_item.refresh() - msg = 'Information template %s has been updated' % library_item.name + msg = "Information template '%s' has been updated" % library_item.name return trans.fill_template( "/admin/library/edit_info_template.mako", liit=library_item, num_fields=num_fields, @@ -1731,6 +1715,7 @@ folder_id=folder_id, library_item_name=library_item.name, library_item_desc=library_item_desc, + define_or_save=define_or_save, msg=msg, messagetype=messagetype ) elif action == 'permissions': @@ -1771,6 +1756,8 @@ library_item = trans.app.model.LibraryDatasetDatasetAssociation.get( library_item_id ) # This response_action method requires a folder_id folder_id = library_item.library_dataset.folder.id + elif library_item_type == 'library_item_info_elememt': + library_item = trans.app.model.LibraryItemInfoElement.get( library_item_id ) else: msg = "Invalid library item type ( %s ) specified, id ( %s )" % ( str( library_item_type ), str( library_item_id ) ) return trans.response.send_redirect( web.url_for( controller='admin', @@ -1869,6 +1856,7 @@ action='library_item_info', library_id=library_id, id=id, + library_item_id=library_item_id, library_item_type=library_item_type, permissions=True, msg=util.sanitize_text( msg ), @@ -1977,10 +1965,14 @@ msg = 'Bad library_item_type specified: %s' % str( library_item_type ) messagetype = 'error' else: + if library_item_type == 'library_dataset': + library_item_desc = 'Dataset' + else: + library_item_desc = library_item_type.capitalize() library_item = library_item_types[ library_item_type ].get( int( library_item_id ) ) library_item.deleted = True library_item.flush() - msg = util.sanitize_text( "%s '%s' has been marked deleted" % ( library_item_type, library_item.name ) ) + msg = util.sanitize_text( "%s '%s' has been marked deleted" % ( library_item_desc, library_item.name ) ) messagetype = 'done' if library_item_type == 'library': return self.browse_libraries( trans, msg=msg, messagetype=messagetype ) @@ -1997,14 +1989,18 @@ msg = 'Bad library_item_type specified: %s' % str( library_item_type ) messagetype = 'error' else: + if library_item_type == 'library_dataset': + library_item_desc = 'Dataset' + else: + library_item_desc = library_item_type.capitalize() library_item = library_item_types[ library_item_type ].get( int( library_item_id ) ) if library_item.purged: - msg = '%s %s has been purged, so it cannot be undeleted' % ( library_item_type, library_item.name ) + msg = '%s %s has been purged, so it cannot be undeleted' % ( library_item_desc, library_item.name ) messagetype = 'error' else: library_item.deleted = False library_item.flush() - msg = util.sanitize_text( "%s '%s' has been marked undeleted" % ( library_item_type, library_item.name ) ) + msg = util.sanitize_text( "%s '%s' has been marked undeleted" % ( library_item_desc, library_item.name ) ) messagetype = 'done' if library_item_type == 'library': return self.browse_libraries( trans, msg=msg, messagetype=messagetype ) diff -r 1a82088aac38 -r 386e245f8076 lib/galaxy/web/controllers/library.py --- a/lib/galaxy/web/controllers/library.py Thu May 21 11:32:25 2009 -0400 +++ b/lib/galaxy/web/controllers/library.py Thu May 21 15:48:39 2009 -0400 @@ -1169,7 +1169,13 @@ msg=msg, messagetype=messagetype ) elif action == 'edit_template': - if params.get( 'edit_info_template_button', False ): + define_or_save = 'define' + edit_info_template_button = params.get( 'edit_info_template_button', False ) + if edit_info_template_button: + if edit_info_template_button == 'Define fields': + define_or_save = 'save' + else: + define_or_save = 'define' # Save changes to existing attributes, only set name if nonempty/nonNone is passed, but always set description name = params.get( 'name', None ) if name: @@ -1177,7 +1183,7 @@ library_item.description = params.get( 'description', '' ) library_item.flush() # Save changes to exisiting elements - for elem_id in params.get( 'element_ids', [] ): + for elem_id in util.listify( params.get( 'element_ids', [] ) ): liit_element = trans.app.model.LibraryItemInfoTemplateElement.get( elem_id ) name = params.get( 'element_name_%s' % elem_id, None ) if name: @@ -1206,6 +1212,7 @@ folder_id=folder_id, library_item_name=library_item.name, library_item_desc=library_item_desc, + define_or_save=define_or_save, msg=msg, messagetype=messagetype ) elif action == 'permissions': @@ -1246,6 +1253,8 @@ library_item = trans.app.model.LibraryDatasetDatasetAssociation.get( library_item_id ) # This response_action method requires a folder_id folder_id = library_item.library_dataset.folder.id + elif library_item_type == 'library_item_info_elememt': + library_item = trans.app.model.LibraryItemInfoElement.get( library_item_id ) else: msg = "Invalid library item type ( %s ) specified, id ( %s )" % ( str( library_item_type ), str( library_item_id ) ) return trans.response.send_redirect( web.url_for( controller='library', @@ -1339,17 +1348,18 @@ trans.app.security_agent.set_all_library_permissions( library_item.library_item_info, permissions ) library_item.library_item_info.refresh() library_item.refresh() - msg = "Permissions updated for field '%s'" % library_item.name + msg = "Permissions updated for field '%s'" % library_item.library_item_info_template_element.name return trans.response.send_redirect( web.url_for( controller='library', action='library_item_info', library_id=library_id, id=id, + library_item_id=library_item_id, library_item_type=library_item_type, permissions=True, msg=util.sanitize_text( msg ), messagetype='done' ) ) return trans.fill_template( '/library/info_permissions.mako', - library_item_info_element=library_item_info_element, + library_item_info_element=library_item, library_id=library_id, msg=msg, messagetype=messagetype ) diff -r 1a82088aac38 -r 386e245f8076 templates/admin/library/browse_library.mako --- a/templates/admin/library/browse_library.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/admin/library/browse_library.mako Thu May 21 15:48:39 2009 -0400 @@ -115,7 +115,8 @@ %if folder.library_folder_info_template_associations: <% template = folder.get_library_item_info_templates( template_list=[], restrict=True )[0] %> <a class="action-button" href="${h.url_for( controller='admin', action='info_template', library_id=library_id, id=template.id, edit_template=True )}">Edit this folder's information template</a> - %else: + %elif not folder.library_folder_info_associations: + ## Only allow adding a new template to the folder if a previously inherited template has not already been used <a class="action-button" href="${h.url_for( controller='admin', action='info_template', library_id=library_id, folder_id=folder.id, new_template=True )}">Add an information template to this folder</a> %endif <a class="action-button" href="${h.url_for( controller='admin', action='folder', permissions=True, id=folder.id, library_id=library_id )}">Edit this folder's permissions</a> diff -r 1a82088aac38 -r 386e245f8076 templates/admin/library/common.mako --- a/templates/admin/library/common.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/admin/library/common.mako Thu May 21 15:48:39 2009 -0400 @@ -84,11 +84,10 @@ elif isinstance( library_item, trans.app.model.LibraryDatasetDatasetAssociation ): library_item_type = 'library_dataset_dataset_association' library_item_desc = 'library dataset' - library_item_info_associations = library_item.library_dataset_dataset_info_associations - elif isinstance( library_item, trans.app.model.LibraryItemInfoElement ): - library_item_type = 'library_item_info' - library_item_desc = 'information' - library_item_info_associations = None + if library_item.library_dataset_dataset_info_associations: + library_item_info_associations = library_item.library_dataset_dataset_info_associations + elif library_item.library_dataset_dataset_info_template_associations: + library_item_info_associations = library_item.library_dataset_dataset_info_template_associations %> %if library_item_info_associations: <p/> @@ -100,17 +99,18 @@ <input type="hidden" name="library_item_type" value="${library_item_type}"/> %for library_item_info_association in library_item_info_associations: %for template_element in library_item_info_association.library_item_info.library_item_info_template.elements: - <% element = library_item_info_association.library_item_info.get_element_by_template_element( template_element ) %> + <% element = library_item_info_association.library_item_info.get_element_by_template_element( template_element, create_element=True ) %> <input type="hidden" name="id" value="${element.id}"/> <div class="form-row"> - <label> - ${template_element.name}: - <a id="element-${element.id}-popup" class="popup-arrow" style="display: none;">▼</a> - <div popupmenu="element-${element.id}-popup"> - <a class="action-button" href="${h.url_for( controller='admin', action='library_item_info', library_id=library_id, id=element.id, library_item_type='library_item_info_elememt', permissions=True )}">Edit this information's permissions</a> - </div> - </label> - <textarea name="info_element_${element.id}" rows="3" cols="35">${element.contents}</textarea> + <label>${template_element.name}:</label> + %if element.contents: + <textarea name="info_element_${element.id}" rows="3" cols="35">${element.contents}</textarea> + %else: + <textarea name="info_element_${element.id}" rows="3" cols="35"></textarea> + %endif + <div class="toolParamHelp" style="clear: both;"> + ${template_element.description} + </div> <div style="clear: both"></div> </div> %endfor @@ -145,11 +145,10 @@ elif isinstance( library_item, trans.app.model.LibraryDatasetDatasetAssociation ): library_item_type = 'library_dataset_dataset_association' library_item_desc = 'library dataset' - library_item_info_associations = library_item.library_dataset_dataset_info_associations - elif isinstance( library_item, trans.app.model.LibraryItemInfoElement ): - library_item_type = 'library_item_info' - library_item_desc = 'information' - library_item_info_associations = None + if library_item.library_dataset_dataset_info_associations: + library_item_info_associations = library_item.library_dataset_dataset_info_associations + elif library_item.library_dataset_dataset_info_template_associations: + library_item_info_associations = library_item.library_dataset_dataset_info_template_associations %> %if library_item_info_associations: <p/> @@ -158,11 +157,16 @@ <div class="toolFormBody"> %for library_item_info_association in library_item_info_associations: %for template_element in library_item_info_association.library_item_info.library_item_info_template.elements: - <% element = library_item_info_association.library_item_info.get_element_by_template_element( template_element ) %> + <% element = library_item_info_association.library_item_info.get_element_by_template_element( template_element, create_element=True ) %> <div class="form-row"> <label>${template_element.name}:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - ${element.contents} + %if element.contents: + <div style="float: left; width: 250px; margin-right: 10px;"> + ${element.contents} + </div> + %endif + <div class="toolParamHelp" style="clear: both;"> + ${template_element.description} </div> <div style="clear: both"></div> </div> diff -r 1a82088aac38 -r 386e245f8076 templates/admin/library/edit_info_template.mako --- a/templates/admin/library/edit_info_template.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/admin/library/edit_info_template.mako Thu May 21 15:48:39 2009 -0400 @@ -24,12 +24,12 @@ <input type="hidden" name="id" value="${liit.id}"/> <input type="hidden" name="set_num_fields" value="${num_fields}"/> <div class="form-row"> - <b>Template name:</b> + <label>Template name:</label> <input type="text" name="name" value="${liit.name}" size="40"/> <div style="clear: both"></div> </div> <div class="form-row"> - <b>Template description (optional):</b> + <label>Template description (optional):</label> <input type="text" name="description" value="${liit.description}" size="40"/> <div style="clear: both"></div> </div> @@ -39,9 +39,9 @@ %for template_element in liit.elements: <input type="hidden" name="element_ids" value="${template_element.id}"/> <div class="form-row"> - <b>Field label:</b> + <label>Field label:</label> <input type="text" name="element_name_${template_element.id}" value="${template_element.name}" size="40"/> - <b>Field help text (optional):</b> + <label>Field help text (optional):</label> <input type="text" name="element_description_${template_element.id}" value="${template_element.description}" size="40"/> <div style="clear: both"></div> </div> @@ -50,22 +50,26 @@ <div class="form-row"> <div class="toolFormTitle">Additional field ${1+element_count}</div> <div class="form-row"> - <b>Field label:</b> + <label>Field label:</label> <input type="text" name="new_element_name_${element_count}" value="" size="40"/> - <b>Field help text (optional):</b> + <label>Field help text (optional):</label> <input type="text" name="new_element_description_${element_count}" value="" size="40"/> <div style="clear: both"></div> </div> </div> %endfor - <div class="form-row"> - <label>Add additional fields:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="text" name="num_fields" value="0" size="3"/> + %if define_or_save == 'define': + <div class="form-row"> + <label>Add additional fields:</label> + <div style="float: left; width: 250px; margin-right: 10px;"> + <input type="text" name="num_fields" value="0" size="3"/> + </div> + <div style="clear: both"></div> </div> - <div style="clear: both"></div> - </div> - <input type="submit" name="edit_info_template_button" value="Save"/> + <input type="submit" name="edit_info_template_button" value="Define fields"/> + %else: + <input type="submit" name="edit_info_template_button" value="Save"/> + %endif </div> </form> </div> diff -r 1a82088aac38 -r 386e245f8076 templates/admin/library/folder_info.mako --- a/templates/admin/library/folder_info.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/admin/library/folder_info.mako Thu May 21 15:48:39 2009 -0400 @@ -43,5 +43,6 @@ %elif folder.library_folder_info_template_associations: ${render_available_templates( folder, library_id, restrict=True )} %else: + ## Look for any inheritable templates ${render_available_templates( folder, library_id, restrict=False )} %endif diff -r 1a82088aac38 -r 386e245f8076 templates/admin/library/ldda_edit_info.mako --- a/templates/admin/library/ldda_edit_info.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/admin/library/ldda_edit_info.mako Thu May 21 15:48:39 2009 -0400 @@ -56,7 +56,11 @@ <div class="form-row"> <label>Message:</label> <div style="float: left; width: 250px; margin-right: 10px;"> - <textarea name="message" rows="3" cols="35">${ldda.message}</textarea> + %if ldda.message: + <textarea name="message" rows="3" cols="35">${ldda.message}</textarea> + %else: + <textarea name="message" rows="3" cols="35"></textarea> + %endif </div> <div class="toolParamHelp" style="clear: both;"> This information will be displayed in the library browser diff -r 1a82088aac38 -r 386e245f8076 templates/admin/library/new_info_template.mako --- a/templates/admin/library/new_info_template.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/admin/library/new_info_template.mako Thu May 21 15:48:39 2009 -0400 @@ -54,13 +54,8 @@ </div> <div class="toolFormBody"> <div class="form-row"> - <label>Add additional template fields:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="text" name="num_fields" value="0" size="3"/> - </div> - <div style="clear: both"></div> + <input type="submit" name="new_info_template_button" value="Save"/> </div> - <input type="submit" name="new_info_template_button" value="Save"/> </div> </form> </div> diff -r 1a82088aac38 -r 386e245f8076 templates/library/browse_library.mako --- a/templates/library/browse_library.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/library/browse_library.mako Thu May 21 15:48:39 2009 -0400 @@ -105,26 +105,26 @@ </script> <![endif]> -<%def name="render_folder( parent, parent_pad, created_ldda_ids, library_id )"> +<%def name="render_folder( folder, folder_pad, created_ldda_ids, library_id )"> <% def show_folder(): - if trans.app.security_agent.check_folder_contents( trans.user, parent ) or trans.app.security_agent.show_library_item( trans.user, parent ): + if trans.app.security_agent.check_folder_contents( trans.user, folder ) or trans.app.security_agent.show_library_item( trans.user, folder ): return True return False if not show_folder: return "" - root_folder = not parent.parent + root_folder = not folder.parent if root_folder: - pad = parent_pad + pad = folder_pad else: - pad = parent_pad + 20 - if parent_pad == 0: + pad = folder_pad + 20 + if folder_pad == 0: expander = "/static/images/silk/resultset_bottom.png" - folder = "/static/images/silk/folder_page.png" + folder_img = "/static/images/silk/folder_page.png" subfolder = False else: expander = "/static/images/silk/resultset_next.png" - folder = "/static/images/silk/folder.png" + folder_img = "/static/images/silk/folder.png" subfolder = True created_ldda_id_list = util.listify( created_ldda_ids ) if created_ldda_id_list: @@ -134,34 +134,35 @@ <li class="folderRow libraryOrFolderRow" style="padding-left: ${pad}px;"> <input type="checkbox" class="folderCheckbox" style="float: left;"/> <div class="rowTitle"> - <span class="expandLink"><img src="${h.url_for( expander )}" class="expanderIcon"/><img src="${h.url_for( folder )}" class="rowIcon"/> - ${parent.name} - %if parent.description: - <i>- ${parent.description}</i> + <span class="expandLink"><img src="${h.url_for( expander )}" class="expanderIcon"/><img src="${h.url_for( folder_img )}" class="rowIcon"/> + ${folder.name} + %if folder.description: + <i>- ${folder.description}</i> %endif - <a id="folder-${parent.id}-popup" class="popup-arrow" style="display: none;">▼</a> - <div popupmenu="folder-${parent.id}-popup"> - %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=parent ): - <a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', library_id=library_id, folder_id=parent.id )}">Add datasets to this folder</a> - <a class="action-button" href="${h.url_for( controller='library', action='folder', new=True, id=parent.id, library_id=library_id )}">Create a new sub-folder in this folder</a> + <a id="folder_img-${folder.id}-popup" class="popup-arrow" style="display: none;">▼</a> + <div popupmenu="folder_img-${folder.id}-popup"> + %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=folder ): + <a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', library_id=library_id, folder_id=folder.id )}">Add datasets to this folder</a> + <a class="action-button" href="${h.url_for( controller='library', action='folder', new=True, id=folder.id, library_id=library_id )}">Create a new sub-folder in this folder</a> %endif - %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=parent ): - <a class="action-button" href="${h.url_for( controller='library', action='folder', information=True, id=parent.id, library_id=library_id )}">Edit this folder's information</a> + %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=folder ): + <a class="action-button" href="${h.url_for( controller='library', action='folder', information=True, id=folder.id, library_id=library_id )}">Edit this folder's information</a> %else: - <a class="action-button" href="${h.url_for( controller='library', action='folder', information=True, id=parent.id, library_id=library_id )}">View this folder's information</a> + <a class="action-button" href="${h.url_for( controller='library', action='folder', information=True, id=folder.id, library_id=library_id )}">View this folder's information</a> %endif - %if parent.library_folder_info_template_associations: - %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=parent ): - <% template = parent.get_library_item_info_templates( template_list=[], restrict=True )[0] %> + %if folder.library_folder_info_template_associations: + %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=folder ): + <% template = folder.get_library_item_info_templates( template_list=[], restrict=True )[0] %> <a class="action-button" href="${h.url_for( controller='library', action='info_template', library_id=library.id, id=template.id, edit_template=True )}">Edit this folder's information template</a> %endif - %else: - %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=parent ): - <a class="action-button" href="${h.url_for( controller='library', action='info_template', library_id=library.id, folder_id=parent.id, new_template=True )}">Add an information template to this folder</a> + %elif not folder.library_folder_info_associations: + ## Only allow adding a new template to the folder if a previously inherited template has not already been used + %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=folder ): + <a class="action-button" href="${h.url_for( controller='library', action='info_template', library_id=library.id, folder_id=folder.id, new_template=True )}">Add an information template to this folder</a> %endif %endif - %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MANAGE, library_item=parent ): - <a class="action-button" href="${h.url_for( controller='library', action='folder', permissions=True, id=parent.id, library_id=library_id )}">Edit this folder's permissions</a> + %if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MANAGE, library_item=folder ): + <a class="action-button" href="${h.url_for( controller='library', action='folder', permissions=True, id=folder.id, library_id=library_id )}">Edit this folder's permissions</a> %endif </div> </div> @@ -172,10 +173,10 @@ %else: <ul> %endif - %for folder in name_sorted( parent.active_folders ): - ${render_folder( folder, pad, created_ldda_ids, library_id )} + %for child_folder in name_sorted( folder.active_folders ): + ${render_folder( child_folder, pad, created_ldda_ids, library_id )} %endfor - %for library_dataset in name_sorted( parent.active_datasets ): + %for library_dataset in name_sorted( folder.active_datasets ): <% selected = created_ldda_ids and library_dataset.library_dataset_dataset_association.id in created_ldda_ids %> diff -r 1a82088aac38 -r 386e245f8076 templates/library/common.mako --- a/templates/library/common.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/library/common.mako Thu May 21 15:48:39 2009 -0400 @@ -80,11 +80,10 @@ elif isinstance( library_item, trans.app.model.LibraryDatasetDatasetAssociation ): library_item_type = 'library_dataset_dataset_association' library_item_desc = 'library dataset' - library_item_info_associations = library_item.library_dataset_dataset_info_associations - elif isinstance( library_item, trans.app.model.LibraryItemInfoElement ): - library_item_type = 'library_item_info' - library_item_desc = 'information' - library_item_info_associations = None + if library_item.library_dataset_dataset_info_associations: + library_item_info_associations = library_item.library_dataset_dataset_info_associations + elif library_item.library_dataset_dataset_info_template_associations: + library_item_info_associations = library_item.library_dataset_dataset_info_template_associations %> %if library_item_info_associations: <p/> @@ -94,44 +93,28 @@ <form name="edit_info" action="${h.url_for( controller='library', action='library_item_info', library_id=library_id, edit_info=True )}" method="post"> <input type="hidden" name="library_item_id" value="${library_item.id}"/> <input type="hidden" name="library_item_type" value="${library_item_type}"/> - <% render_submit_button = False %> %for library_item_info_association in library_item_info_associations: %for template_element in library_item_info_association.library_item_info.library_item_info_template.elements: - <% element = library_item_info_association.library_item_info.get_element_by_template_element( template_element ) %> + <% element = library_item_info_association.library_item_info.get_element_by_template_element( template_element, create_element=True ) %> <input type="hidden" name="id" value="${element.id}"/> - <% - can_add = trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=element.library_item_info ) - can_modify = trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=element.library_item_info ) - can_manage = trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MANAGE, library_item=element.library_item_info ) - %> <div class="form-row"> - %if can_manage: - <label> - ${template_element.name}: - <a id="element-${element.id}-popup" class="popup-arrow" style="display: none;">▼</a> - <div popupmenu="element-${element.id}-popup"> - <a class="action-button" href="${h.url_for( controller='admin', action='library_item_info', library_id=library_id, id=element.id, library_item_type='library_item_info_elememt', permissions=True )}">Edit this information's permissions</a> - </div> - </label> + <label>${template_element.name}:</label> + %if element.contents: + <textarea name="info_element_${element.id}" rows="3" cols="35">${element.contents}</textarea> %else: - <label>${template_element.name}:</label> + <textarea name="info_element_${element.id}" rows="3" cols="35"></textarea> %endif - %if can_modify: - <textarea name="info_element_${element.id}" rows="3" cols="35">${element.contents}</textarea> - <% render_submit_button = True %> - %else: - ${element.contents} - %endif + <div class="toolParamHelp" style="clear: both;"> + ${template_element.description} + </div> <div style="clear: both"></div> </div> %endfor <div style="clear: both"></div> %endfor - %if render_submit_button: - <div class="form-row"> - <input type="submit" name="edit_info_button" value="Save"/> - </div> - %endif + <div class="form-row"> + <input type="submit" name="edit_info_button" value="Save"/> + </div> </form> </div> </div> @@ -158,11 +141,10 @@ elif isinstance( library_item, trans.app.model.LibraryDatasetDatasetAssociation ): library_item_type = 'library_dataset_dataset_association' library_item_desc = 'library dataset' - library_item_info_associations = library_item.library_dataset_dataset_info_associations - elif isinstance( library_item, trans.app.model.LibraryItemInfoElement ): - library_item_type = 'library_item_info' - library_item_desc = 'information' - library_item_info_associations = None + if library_item.library_dataset_dataset_info_associations: + library_item_info_associations = library_item.library_dataset_dataset_info_associations + elif library_item.library_dataset_dataset_info_template_associations: + library_item_info_associations = library_item.library_dataset_dataset_info_template_associations %> %if library_item_info_associations: <p/> @@ -171,11 +153,14 @@ <div class="toolFormBody"> %for library_item_info_association in library_item_info_associations: %for template_element in library_item_info_association.library_item_info.library_item_info_template.elements: - <% element = library_item_info_association.library_item_info.get_element_by_template_element( template_element ) %> + <% element = library_item_info_association.library_item_info.get_element_by_template_element( template_element, create_element=True ) %> <div class="form-row"> <label>${template_element.name}:</label> <div style="float: left; width: 250px; margin-right: 10px;"> ${element.contents} + </div> + <div class="toolParamHelp" style="clear: both;"> + ${template_element.description} </div> <div style="clear: both"></div> </div> diff -r 1a82088aac38 -r 386e245f8076 templates/library/edit_info_template.mako --- a/templates/library/edit_info_template.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/library/edit_info_template.mako Thu May 21 15:48:39 2009 -0400 @@ -27,12 +27,12 @@ <input type="hidden" name="id" value="${liit.id}"/> <input type="hidden" name="set_num_fields" value="${num_fields}"/> <div class="form-row"> - <b>Template name:</b> + <label>Template name:</label> <input type="text" name="name" value="${liit.name}" size="40"/> <div style="clear: both"></div> </div> <div class="form-row"> - <b>Template description (optional):</b> + <label>Template description (optional):</label> <input type="text" name="description" value="${liit.description}" size="40"/> <div style="clear: both"></div> </div> @@ -42,9 +42,9 @@ %for template_element in liit.elements: <input type="hidden" name="element_ids" value="${template_element.id}"/> <div class="form-row"> - <b>Field label:</b> + <label>Field label:</label> <input type="text" name="element_name_${template_element.id}" value="${template_element.name}" size="40"/> - <b>Field help text (optional):</b> + <label>Field help text (optional):</label> <input type="text" name="element_description_${template_element.id}" value="${template_element.description}" size="40"/> <div style="clear: both"></div> </div> @@ -53,22 +53,26 @@ <div class="form-row"> <div class="toolFormTitle">Additional field ${1+element_count}</div> <div class="form-row"> - <b>Field label:</b> + <label>Field label:</label> <input type="text" name="new_element_name_${element_count}" value="" size="40"/> - <b>Field help text (optional):</b> + <label>Field help text (optional):</label> <input type="text" name="new_element_description_${element_count}" value="" size="40"/> <div style="clear: both"></div> </div> </div> %endfor - <div class="form-row"> - <label>Add additional fields:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="text" name="num_fields" value="0" size="3"/> + %if define_or_save == 'define': + <div class="form-row"> + <label>Add additional fields:</label> + <div style="float: left; width: 250px; margin-right: 10px;"> + <input type="text" name="num_fields" value="0" size="3"/> + </div> + <div style="clear: both"></div> </div> - <div style="clear: both"></div> - </div> - <input type="submit" name="edit_info_template_button" value="Save"/> + <input type="submit" name="edit_info_template_button" value="Define fields"/> + %else: + <input type="submit" name="edit_info_template_button" value="Save"/> + %endif </div> </form> %else: diff -r 1a82088aac38 -r 386e245f8076 templates/library/ldda_edit_info.mako --- a/templates/library/ldda_edit_info.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/library/ldda_edit_info.mako Thu May 21 15:48:39 2009 -0400 @@ -56,7 +56,11 @@ <div class="form-row"> <label>Message:</label> <div style="float: left; width: 250px; margin-right: 10px;"> - <textarea name="message" rows="3" cols="35">${ldda.message}</textarea> + %if ldda.message: + <textarea name="message" rows="3" cols="35">${ldda.message}</textarea> + %else: + <textarea name="message" rows="3" cols="35"></textarea> + %endif </div> <div class="toolParamHelp" style="clear: both;"> This information will be displayed in the library browser @@ -116,7 +120,7 @@ <p/> %else: <div class="toolForm"> - <div class="toolFormTitle">View attributes of ${ldda.name}</div> + <div class="toolFormTitle">View information about ${ldda.name}</div> <div class="toolFormBody"> <div class="form-row"> <b>Name:</b> ${ldda.name} diff -r 1a82088aac38 -r 386e245f8076 templates/library/library_dataset_info.mako --- a/templates/library/library_dataset_info.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/library/library_dataset_info.mako Thu May 21 15:48:39 2009 -0400 @@ -47,7 +47,7 @@ </div> %else: <div class="toolForm"> - <div class="toolFormTitle">View attributes of ${library_dataset.name}</div> + <div class="toolFormTitle">View information about ${library_dataset.name}</div> <div class="toolFormBody"> <div class="form-row"> <b>Name:</b> ${library_dataset.name} diff -r 1a82088aac38 -r 386e245f8076 templates/library/new_info_template.mako --- a/templates/library/new_info_template.mako Thu May 21 11:32:25 2009 -0400 +++ b/templates/library/new_info_template.mako Thu May 21 15:48:39 2009 -0400 @@ -55,13 +55,8 @@ </div> <div class="toolFormBody"> <div class="form-row"> - <label>Add additional template fields:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="text" name="num_fields" value="0" size="3"/> - </div> - <div style="clear: both"></div> + <input type="submit" name="new_info_template_button" value="Save"/> </div> - <input type="submit" name="new_info_template_button" value="Save"/> </div> </form> %else: diff -r 1a82088aac38 -r 386e245f8076 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Thu May 21 11:32:25 2009 -0400 +++ b/test/base/twilltestcase.py Thu May 21 15:48:39 2009 -0400 @@ -816,6 +816,19 @@ tc.fv( "1", "2", description ) # form field 1 is the field named name... tc.submit( "create_library_button" ) self.home() + def set_library_permissions( self, library_id, library_name, role_id, permissions_in, permissions_out ): + url = "admin/library?id=%s&permissions=True&update_roles_button=Save" % ( library_id ) + for po in permissions_out: + key = '%s_out' % po + url ="%s&%s=%s" % ( url, key, str( role_id ) ) + for pi in permissions_in: + key = '%s_in' % pi + url ="%s&%s=%s" % ( url, key, str( role_id ) ) + self.home() + self.visit_url( "%s/%s" % ( self.url, url ) ) + check_str = "Permissions updated for library '%s'" % library_name + self.check_page_for_string( check_str ) + self.home() def rename_library( self, library_id, old_name, name='Library One Renamed', description='This is Library One Re-described' ): """Rename a library""" self.home() @@ -829,16 +842,71 @@ check_str = "Library '%s' has been renamed to '%s'" % ( old_name, name ) self.check_page_for_string( check_str ) self.home() - def add_library_info_template( self, library_id, library_name ): + def add_library_info_template( self, library_id, library_name, num_fields='2', name='Library Template 1', ele_name_0='Foo', ele_name_1='Doh' ): """Add a new info template to a library""" self.home() url = "%s/admin/info_template?library_id=%s&new_template=True&num_fields=2&create_info_template_button=Go" % ( self.url, library_id ) - self.home() self.visit_url( url ) check_str = "Create a new information template for library '%s'" % library_name self.check_page_for_string ( check_str ) - # TODO: finish this... - def add_folder_info_template( self, library_id, library_name, folder_id, folder_name ): + tc.fv( '1', 'library_id', library_id ) + tc.fv( '1', 'set_num_fields', num_fields ) + tc.fv( '1', 'name', name ) + tc.fv( '1', 'new_element_name_0', ele_name_0 ) + tc.fv( '1', 'new_element_name_1', ele_name_1 ) + tc.submit( 'new_info_template_button' ) + self.home() + def add_library_info_template_element( self, library_id, template_id, template_name, ele_name_1, ele_desc_1, + ele_name_2, ele_desc_2, new_ele_name='Fubar', new_ele_desc='This is the Fubar compnent' ): + """Add a new element to an existing library info template""" + self.home() + url = "%s/admin/info_template?library_id=%s&id=%s&edit_template=True&num_fields=1&edit_info_template_button=Save" % \ + ( self.url, library_id, template_id ) + self.visit_url( url ) + check_str = "Edit template '%s'" % template_name + self.check_page_for_string ( check_str ) + tc.fv( '1', 'id', template_id ) + tc.fv( '1', 'set_num_fields', '0' ) + tc.fv( '1', 'name', template_name ) + tc.fv( '1', 'element_name_1', ele_name_1 ) + tc.fv( '1', 'element_description_1', ele_desc_1 ) + tc.fv( '1', 'element_name_2', ele_name_2 ) + tc.fv( '1', 'element_description_2', ele_desc_2 ) + tc.fv( '1', 'new_element_name_0', new_ele_name ) + tc.fv( '1', 'new_element_description_0', new_ele_desc ) + tc.submit( 'edit_info_template_button' ) + check_str = "Information template '%s' has been updated" % template_name + self.check_page_for_string( check_str ) + self.home() + def edit_library_info( self, library_id, library_name, ele_1_field_name, ele_1_contents, ele_2_field_name, ele_2_contents ): + """Add information to a library using an existing template with 2 elements""" + self.home() + self.visit_url( "%s/admin/library?information=True&id=%s" % ( self.url, library_id ) ) + check_str = 'Other information about library %s' % library_name + self.check_page_for_string( check_str ) + tc.fv( '2', ele_1_field_name, ele_1_contents ) + tc.fv( '2', ele_2_field_name, ele_2_contents ) + tc.submit( 'create_new_info_button' ) + self.home() + def edit_library_info_template( self, library_id, id, name, name_1, desc_1, name_2, desc_2 ): + """Edit an existing library info template""" + self.home() + url = "%s/admin/info_template?library_id=%s&id=%s&edit_template=True" % ( self.url, library_id, id ) + self.visit_url( url ) + self.check_page_for_string ( 'Edit template' ) + tc.fv( '1', 'id', id ) + tc.fv( '1', 'set_num_fields', '0' ) + tc.fv( '1', 'name', name ) + tc.fv( '1', 'element_name_1', name_1 ) + tc.fv( '1', 'element_description_1', desc_1 ) + tc.fv( '1', 'element_name_2', name_2 ) + tc.fv( '1', 'element_description_2', desc_2 ) + tc.submit( 'edit_info_template_button' ) + check_str = "Information template '%s' has been updated" % name + self.check_page_for_string( check_str ) + self.home() + def add_folder_info_template( self, library_id, library_name, folder_id, folder_name, num_fields='2', + name='Folder Template 1', ele_name_0='Fu', ele_help_0='', ele_name_1='Bar', ele_help_1='' ): """Add a new info template to a folder""" self.home() url = "%s/admin/info_template?library_id=%s&folder_id=%s&new_template=True&num_fields=2&create_info_template_button=Go" % \ @@ -847,7 +915,16 @@ self.visit_url( url ) check_str = "Create a new information template for folder '%s'" % folder_name self.check_page_for_string ( check_str ) - # TODO: finish this... + tc.fv( '1', 'library_id', library_id ) + tc.fv( '1', 'folder_id', folder_id ) + tc.fv( '1', 'set_num_fields', num_fields ) + tc.fv( '1', 'name', name ) + tc.fv( '1', 'new_element_name_0', ele_name_0 ) + tc.fv( '1', 'new_element_description_0', ele_help_0.replace( '+', ' ' ) ) + tc.fv( '1', 'new_element_name_1', ele_name_1 ) + tc.fv( '1', 'new_element_description_1', ele_help_1.replace( '+', ' ' ) ) + tc.submit( 'new_info_template_button' ) + self.home() def add_folder( self, library_id, folder_id, name='Folder One', description='NThis is Folder One' ): """Create a new folder""" self.home() @@ -870,16 +947,27 @@ check_str = "Folder '%s' has been renamed to '%s'" % ( old_name, name ) self.check_page_for_string( check_str ) self.home() - def add_library_dataset( self, filename, library_id, folder_id, folder_name, file_format='auto', dbkey='hg18', roles=[], message='', root=False ): + def add_library_dataset( self, filename, library_id, folder_id, folder_name, file_format='auto', + dbkey='hg18', roles=[], message='', root=False, check_template_str1='', check_template_str2='', + check_template_str3='' ): """Add a dataset to a folder""" filename = self.get_filename( filename ) self.home() - self.visit_url( "%s/admin/library_dataset_dataset_association?upload_option=upload_file&library_id=%s&folder_id=%s&message=%s" % ( self.url, library_id, folder_id, message ) ) + self.visit_url( "%s/admin/library_dataset_dataset_association?upload_option=upload_file&library_id=%s&folder_id=%s&message=%s" % \ + ( self.url, library_id, folder_id, message ) ) self.check_page_for_string( 'Upload files' ) + # If we've been sent some template labels, make sure they are included in the upload form + if check_template_str1: + self.check_page_for_string( check_template_str1 ) + if check_template_str2: + self.check_page_for_string( check_template_str2 ) + if check_template_str3: + self.check_page_for_string( check_template_str3 ) tc.fv( "1", "folder_id", folder_id ) tc.formfile( "1", "file_data", filename ) tc.fv( "1", "file_format", file_format ) tc.fv( "1", "dbkey", dbkey ) + tc.fv( "1", "message", message.replace( '+', ' ' ) ) for role_id in roles: tc.fv( "1", "roles", role_id ) # form field 7 is the select list named out_groups, note the buttons... tc.submit( "new_dataset_button" ) @@ -887,6 +975,125 @@ check_str = "Added 1 datasets to the library '%s' ( each is selected )." % folder_name else: check_str = "Added 1 datasets to the folder '%s' ( each is selected )." % folder_name + self.check_page_for_string( check_str ) + self.home() + def set_library_dataset_permissions( self, library_id, folder_id, ldda_id, ldda_name, role_id, permissions_in, permissions_out ): + url = "admin/library_dataset_dataset_association?library_id=%s&folder_id=%s&&id=%s&permissions=True&update_roles_button=Save" % \ + ( library_id, folder_id, ldda_id ) + #role_ids = util.listify( role_ids ) + #for role_id in role_ids: + for po in permissions_out: + key = '%s_out' % po + url ="%s&%s=%s" % ( url, key, str( role_id ) ) + for pi in permissions_in: + key = '%s_in' % pi + url ="%s&%s=%s" % ( url, key, str( role_id ) ) + print url + self.home() + self.visit_url( "%s/%s" % ( self.url, url ) ) + check_str = "Permissions updated for dataset '%s'" % ldda_name + self.check_page_for_string( check_str ) + self.home() + def edit_ldda_template_element_info( self, library_id, folder_id, ldda_id, ldda_name, ele_1_field_name, + ele_1_contents, ele_2_field_name, ele_2_contents, ele_1_help='', ele_2_help='', + ele_3_field_name='', ele_3_contents='', ele_3_help='' ): + """Edit library_dataset_dataset_association template element information""" + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, library_id, folder_id, ldda_id ) ) + check_str = 'Edit attributes of %s' % ldda_name + self.check_page_for_string( check_str ) + ele_1_contents = ele_1_contents.replace( '+', ' ' ) + ele_2_contents = ele_2_contents.replace( '+', ' ' ) + tc.fv( '4', ele_1_field_name, ele_1_contents ) + tc.fv( '4', ele_2_field_name, ele_2_contents.replace( '+', ' ' ) ) + if ele_3_field_name and ele_3_contents: + ele_3_contents = ele_3_contents.replace( '+', ' ' ) + tc.fv( '4', ele_3_field_name, ele_3_contents ) + tc.submit( 'edit_info_button' ) + self.check_page_for_string( 'This is the latest version of this library dataset' ) + self.check_page_for_string( 'The information has been updated.' ) + self.check_page_for_string( ele_1_contents ) + self.check_page_for_string( ele_2_contents ) + if ele_3_field_name and ele_3_contents: + self.check_page_for_string( ele_3_contents ) + if ele_1_help: + check_str = ele_1_help.replace( '+', ' ' ) + self.check_page_for_string( check_str ) + self.check_page_for_string( ele_2_contents ) + if ele_2_help: + check_str = ele_2_help.replace( '+', ' ' ) + self.check_page_for_string( check_str ) + if ele_2_help: + check_str = ele_3_help.replace( '+', ' ' ) + self.check_page_for_string( check_str ) + self.home() + def edit_ldda_attribute_info( self, library_id, folder_id, ldda_id, ldda_name, new_ldda_name ): + """Edit library_dataset_dataset_association attribute information""" + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, library_id, folder_id, ldda_id ) ) + check_str = 'Edit attributes of %s' % ldda_name + self.check_page_for_string( check_str ) + tc.fv( '1', 'name', new_ldda_name ) + tc.submit( 'save' ) + check_str = 'Attributes updated for library dataset %s' % new_ldda_name + self.check_page_for_string( check_str ) + check_str = 'Edit attributes of %s' % new_ldda_name + self.check_page_for_string( check_str ) + self.home() + def upload_new_dataset_version( self, filename, library_id, folder_id, folder_name, library_dataset_id, ldda_name, file_format='auto', + dbkey='hg18', message='', check_template_str1='', check_template_str2='', check_template_str3='' ): + """Upload new version(s) of a dataset""" + self.home() + filename = self.get_filename( filename ) + + url = "%s/admin/library_dataset_dataset_association?upload_option=upload_file&library_id=%s&folder_id=%s&replace_id=%s&message=%s" % \ + ( self.url, library_id, folder_id, library_dataset_id, message ) + print "####url: ", url + + self.visit_url( "%s/admin/library_dataset_dataset_association?upload_option=upload_file&library_id=%s&folder_id=%s&replace_id=%s&message=%s" % \ + ( self.url, library_id, folder_id, library_dataset_id, message ) ) + self.check_page_for_string( 'Upload files' ) + self.check_page_for_string( 'You are currently selecting a new file to replace' ) + self.check_page_for_string( ldda_name ) + # If we've been sent some template labels, make sure they are included in the upload form + if check_template_str1: + self.check_page_for_string( check_template_str1 ) + if check_template_str2: + self.check_page_for_string( check_template_str2 ) + if check_template_str3: + self.check_page_for_string( check_template_str3 ) + tc.formfile( "1", "file_data", filename ) + tc.fv( "1", "file_format", file_format ) + tc.fv( "1", "dbkey", dbkey ) + tc.fv( "1", "message", message.replace( '+', ' ' ) ) + tc.submit( "new_dataset_button" ) + check_str = "Added 1 dataset versions to the library dataset '%s' in the folder '%s'." % ( ldda_name, folder_name ) + self.check_page_for_string( check_str ) + self.home() + def upload_new_dataset_versions( self, library_id, folder_id, folder_name, library_dataset_id, ldda_name, file_format='auto', + dbkey='hg18', message='', check_template_str1='', check_template_str2='', check_template_str3='' ): + """Upload new version(s) of a dataset using a directory of files""" + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?upload_option=upload_directory&library_id=%s&folder_id=%s&replace_id=%s" \ + % ( self.url, library_id, folder_id, library_dataset_id ) ) + self.check_page_for_string( 'Upload a directory of files' ) + self.check_page_for_string( 'You are currently selecting a new file to replace' ) + # If we've been sent some template labels, make sure they are included in the upload form + if check_template_str1: + self.check_page_for_string( check_template_str1 ) + if check_template_str2: + self.check_page_for_string( check_template_str2 ) + if check_template_str3: + self.check_page_for_string( check_template_str3 ) + tc.fv( "1", "file_format", file_format ) + tc.fv( "1", "dbkey", dbkey ) + tc.fv( "1", "message", message.replace( '+', ' ' ) ) + library_dir = "%s" % self.file_dir + tc.fv( "1", "server_dir", "library" ) + tc.submit( "new_dataset_button" ) + check_str = "Added 3 dataset versions to the library dataset '%s' in the folder '%s'." % ( ldda_name, folder_name ) self.check_page_for_string( check_str ) self.home() def add_history_datasets_to_library( self, library_id, folder_id, folder_name, hda_id, root=False ): @@ -900,15 +1107,24 @@ check_str = "Added 1 datasets to the folder '%s' ( each is selected )." % folder_name self.check_page_for_string( check_str ) self.home() - def add_datasets_from_library_dir( self, library_id, folder_id, folder_name, file_format='auto', dbkey='hg18', roles_tuple=[], root=False ): + def add_datasets_from_library_dir( self, library_id, folder_id, folder_name, file_format='auto', dbkey='hg18', roles_tuple=[], + message='', root=False, check_template_str1='', check_template_str2='', check_template_str3='' ): """Add a directory of datasets to a folder""" # roles is a list of tuples: [ ( role_id, role_description ) ] self.home() self.visit_url( "%s/admin/library_dataset_dataset_association?upload_option=upload_directory&library_id=%s&folder_id=%s" % ( self.url, library_id, folder_id ) ) self.check_page_for_string( 'Upload a directory of files' ) + # If we've been sent some template labels, make sure they are included in the upload form + if check_template_str1: + self.check_page_for_string( check_template_str1 ) + if check_template_str2: + self.check_page_for_string( check_template_str2 ) + if check_template_str3: + self.check_page_for_string( check_template_str3 ) tc.fv( "1", "folder_id", folder_id ) tc.fv( "1", "file_format", file_format ) tc.fv( "1", "dbkey", dbkey ) + tc.fv( "1", "message", message.replace( '+', ' ' ) ) library_dir = "%s" % self.file_dir tc.fv( "1", "server_dir", "library" ) for role_tuple in roles_tuple: @@ -920,18 +1136,28 @@ check_str = "Added 3 datasets to the folder '%s' ( each is selected )." % folder_name self.check_page_for_string( check_str ) self.home() - def mark_library_deleted( self, library_id, library_name ): - """Mark a library as deleted""" + def delete_library_item( self, library_id, library_item_id, library_item_name, library_item_type='library_dataset' ): + """Mark a library item as deleted""" self.home() - self.visit_url( "%s/admin/library?id=%s&delete=True" % ( self.url, library_id ) ) - check_str = "Library '%s' and all of its contents have been marked deleted" % library_name + self.visit_url( "%s/admin/delete_library_item?library_id=%s&library_item_id=%s&library_item_type=%s" \ + % ( self.url, library_id, library_item_id, library_item_type ) ) + if library_item_type == 'library_dataset': + library_item_desc = 'Dataset' + else: + library_item_desc = library_item_type.capitalize() + check_str = "%s '%s' has been marked deleted" % ( library_item_desc, library_item_name ) self.check_page_for_string( check_str ) self.home() - def undelete_library( self, library_id, library_name ): - """Mark a library as not deleted""" + def undelete_library_item( self, library_id, library_item_id, library_item_name, library_item_type='library_dataset' ): + """Mark a library item as deleted""" self.home() - self.visit_url( "%s/admin/undelete_library?id=%s" % ( self.url, library_id ) ) - check_str = "Library '%s' and all of its contents have been marked not deleted" % library_name + self.visit_url( "%s/admin/undelete_library_item?library_id=%s&library_item_id=%s&library_item_type=%s" \ + % ( self.url, library_id, library_item_id, library_item_type ) ) + if library_item_type == 'library_dataset': + library_item_desc = 'Dataset' + else: + library_item_desc = library_item_type.capitalize() + check_str = "%s '%s' has been marked undeleted" % ( library_item_desc, library_item_name ) self.check_page_for_string( check_str ) self.home() def purge_library( self, library_id, library_name ): diff -r 1a82088aac38 -r 386e245f8076 test/functional/test_security_and_libraries.py --- a/test/functional/test_security_and_libraries.py Thu May 21 11:32:25 2009 -0400 +++ b/test/functional/test_security_and_libraries.py Thu May 21 15:48:39 2009 -0400 @@ -40,6 +40,15 @@ global admin_user admin_user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test@bx.psu.edu' ).first() assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database' + # Get the admin user's privat role for later use + global admin_user_private_role + admin_user_private_role = None + for role in admin_user.all_roles(): + if role.name == admin_user.email and role.description == 'Private Role for %s' % admin_user.email: + admin_user_private_role = role + break + if not admin_user_private_role: + raise AssertionError( "Private role not found for user '%s'" % admin_user.email ) # Make sure DefaultUserPermissions are correct if len( admin_user.default_permissions ) > 1: raise AssertionError( '%d DefaultUserPermissions were created for %s when their account was created ( should have been 1 )' \ @@ -168,14 +177,14 @@ actions_in = [ 'manage permissions' ] permissions_out = [ 'DATASET_ACCESS' ] actions_out = [ 'access' ] - private_role = None + regular_user2_private_role = None for role in regular_user2.all_roles(): if role.name == regular_user2.email and role.description == 'Private Role for %s' % regular_user2.email: - private_role = role + regular_user2_private_role = role break - if not private_role: + if not regular_user2_private_role: raise AssertionError( "Private role not found for user '%s'" % regular_user2.email ) - role_id = str( private_role.id ) + role_id = str( regular_user2_private_role.id ) # Change DefaultHistoryPermissions for the current history self.history_set_default_permissions( permissions_out=permissions_out, permissions_in=permissions_in, role_id=role_id ) if len( latest_history.default_permissions ) != len( actions_in ): @@ -283,11 +292,12 @@ """Testing undeleting a user account""" self.undelete_user( user_id=regular_user3.id, email=regular_user3.email ) def test_045_create_role( self ): - """Testing creating new role with 3 members, then renaming it""" + """Testing creating new role with 3 members ( and a new group named the same ), then renaming the role""" name = 'Role One' description = "This is Role Ones description" user_ids=[ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ] - self.create_role( name=name, description=description, in_user_ids=user_ids, in_group_ids=[], private_role=admin_user.email ) + self.create_role( name=name, description=description, in_user_ids=user_ids, in_group_ids=[], + create_group_for_role='yes', private_role=admin_user.email ) # Get the role object for later tests global role_one role_one = galaxy.model.Role.filter( galaxy.model.Role.table.c.name==name ).first() @@ -308,6 +318,12 @@ if len( user.roles ) != 2: raise AssertionError( '%d UserRoleAssociations are associated with user %s ( should be 2 )' \ % ( len( user.roles ), user.email ) ) + # Make sure the group was created + self.home() + self.visit_page( 'admin/groups' ) + self.check_page_for_string( name ) + global group_zero + group_zero = galaxy.model.Group.filter( galaxy.model.Group.table.c.name==name ).first() # Rename the role rename = "Role One's been Renamed" redescription="This is Role One's Re-described" @@ -430,7 +446,7 @@ if len( admin_user.roles ) != 5: raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 5 )' % ( len( admin_user.roles ), admin_user.email ) ) def test_070_create_library( self ): - """Testing creating a new library, then renaming it and renaming the root folder""" + """Testing creating a new library, then renaming it""" name = "Library One's Name" description = "This is Library One's description" self.create_library( name=name, description=description ) @@ -443,6 +459,12 @@ galaxy.model.Library.table.c.description==description, galaxy.model.Library.table.c.deleted==False ) ).first() assert library_one is not None, 'Problem retrieving library named "%s" from the database' % name + # Set permissions on the library, sort for later testing + permissions_in = [ k for k, v in galaxy.model.Library.permitted_actions.items() ] + permissions_out = [] + # Role one members are: admin_user, regular_user1, regular_user3. Each of these users will be permitted to + # LIBRARY_ADD, LIBRARY_MODIFY, LIBRARY_MANAGE for library items. + self.set_library_permissions( str( library_one.id ), library_one.name, str( role_one.id ), permissions_in, permissions_out ) # Rename the library rename = "Library One's been Renamed" redescription = "This is Library One's Re-described" @@ -455,9 +477,149 @@ library_one.refresh() self.rename_library( str( library_one.id ), library_one.name, name=name, description=description ) library_one.refresh() - def test_075_add_new_folder_to_root_folder( self ): + def test_075_library_template_features( self ): + """Testing adding a template to a library, along with template features on the admin side""" + actions = [ v.action for k, v in galaxy.model.Library.permitted_actions.items() ] + actions.sort() + # Add a new information template to the library + template_name = 'Library Template 1' + ele_name_0 = 'Foo' + ele_name_1 = 'Doh' + self.add_library_info_template( library_one.id, library_one.name, name=template_name, num_fields='2', ele_name_0=ele_name_0, ele_name_1=ele_name_1 ) + self.home() + self.visit_url( '%s/admin/library?id=%s&information=True' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( ele_name_0 ) + self.check_page_for_string( ele_name_1 ) + self.home() + # Get the template for later testing + global library_one_template + library_one_template = galaxy.model.LibraryItemInfoTemplate.query().order_by( desc( galaxy.model.LibraryItemInfoTemplate.table.c.id ) ).first() + assert library_one_template is not None, 'Problem retrieving LibraryItemInfoTemplate for library named "%s" from the database' % str( library_one.name ) + # Make sure the library permissions were inherited by the template + template_permissions = galaxy.model.LibraryItemInfoTemplatePermissions \ + .query() \ + .filter( galaxy.model.LibraryItemInfoTemplatePermissions.table.c.library_item_info_template_id == library_one_template.id ) \ + .order_by( desc( galaxy.model.LibraryItemInfoTemplatePermissions.table.c.id ) ) \ + .limit( 3 ) \ + .all() + template_permissions = [ litp_obj.action for litp_obj in template_permissions ] + template_permissions.sort() + assert actions == template_permissions, "Template permissions for template %s not correctly inherited from library %s" \ + % ( library_one_template.name, library_one.name ) + # Make sure that the library permissions were inherited by each of the template elements + for library_item_info in library_one_template.library_item_infos: + info_permissions = galaxy.model.LibraryItemInfoPermissions \ + .filter( galaxy.model.LibraryItemInfoPermissions.table.c.library_item_info_id == library_item_info.id ) \ + .all() + info_permissions = [ liip_obj.action for liip_obj in info_permissions ] + info_permissions.sort() + assert actions == info_permissions, "Permissions for library_item_info id %s not correctly inherited from library %s" \ + % ( library_item_info.id, library_one.name ) + # Need the current library_item_info_element.id + last_library_item_info_element_id = galaxy.model.LibraryItemInfoElement.query() \ + .order_by( desc( galaxy.model.LibraryItemInfoElement.table.c.id ) ).first() + if last_library_item_info_element_id is None: + last_library_item_info_element_id = 0 + # Add information to the library using the template + ele_1_field_name = "info_element_%s_%s" % ( str( library_one_template.id ), str( last_library_item_info_element_id + 1 ) ) + ele_1_contents = 'hello' + ele_2_field_name = "info_element_%s_%s" % ( str( library_one_template.id ), str( last_library_item_info_element_id + 2 ) ) + ele_2_contents = 'world' + self.edit_library_info( str( library_one.id ), library_one.name, ele_1_field_name, ele_1_contents, ele_2_field_name, ele_2_contents ) + self.home() + self.visit_url( '%s/admin/library?id=%s&information=True' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( ele_1_contents ) + self.check_page_for_string( ele_2_contents ) + self.home() + self.visit_url( '%s/admin/library?id=%s&information=True' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( ele_1_contents ) + self.check_page_for_string( ele_2_contents ) + # Edit the template + new_name = 'Library Template 1 renamed' + new_ele_name_1 = 'wind' + ele_desc_1 = 'This is the wind component' + new_ele_name_2 = 'bag' + ele_desc_2 = 'This is the bag component' + self.edit_library_info_template( str( library_one.id ), library_one_template.id, new_name, new_ele_name_1, ele_desc_1, new_ele_name_2, ele_desc_2 ) + self.home() + self.visit_url( '%s/admin/library?id=%s&information=True' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( new_ele_name_1 ) + self.check_page_for_string( ele_desc_1 ) + self.check_page_for_string( ele_1_contents ) + self.check_page_for_string( new_ele_name_2 ) + self.check_page_for_string( ele_desc_2 ) + self.check_page_for_string( ele_2_contents ) + def test_080_add_public_dataset_to_root_folder( self ): + """Testing adding a public dataset to the root folder""" + actions = [ v.action for k, v in galaxy.model.Library.permitted_actions.items() ] + actions.sort() + message = 'Testing adding a public dataset to the root folder' + self.add_library_dataset( '1.bed', + str( library_one.id ), + str( library_one.root_folder.id ), + library_one.root_folder.name, + file_format='bed', + dbkey='hg18', + message=message.replace( ' ', '+' ), + root=True ) + global ldda_one + ldda_one = galaxy.model.LibraryDatasetDatasetAssociation.query() \ + .order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ).first() + assert ldda_one is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_one from the database' + self.home() + self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( "1.bed" ) + self.check_page_for_string( message ) + self.check_page_for_string( admin_user.email ) + # Make sure the library permissions were inherited to the library_dataset_dataset_association + ldda_permissions = galaxy.model.LibraryDatasetDatasetAssociationPermissions \ + .filter( galaxy.model.LibraryDatasetDatasetAssociationPermissions.table.c.library_dataset_dataset_association_id == ldda_one.id ) \ + .all() + ldda_permissions = [ lddap_obj.action for lddap_obj in ldda_permissions ] + ldda_permissions.sort() + assert actions == ldda_permissions, "Permissions for ldda id %s not correctly inherited from library %s" \ + % ( ldda_one.id, library_one.name ) + # Make sure DatasetPermissions are correct - default is 'manage permissions' + if len( ldda_one.dataset.actions ) > 1: + raise AssertionError( '%d DatasetPermissionss were created for dataset id %d when it was created ( should have been 1 )' \ + % ( len( ldda_one.dataset.actions ), ldda_one.dataset.id ) ) + dp = galaxy.model.DatasetPermissions.filter( galaxy.model.DatasetPermissions.table.c.dataset_id==ldda_one.dataset.id ).first() + if not dp.action == galaxy.model.Dataset.permitted_actions.DATASET_MANAGE_PERMISSIONS.action: + raise AssertionError( 'The DatasetPermissions.action for dataset id %d is "%s", but it should be "manage permissions"' \ + % ( ldda_one.dataset.id, dp.action ) ) + # Make sure the library template was inherited by the ldda + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( library_one.root_folder.id ), str( ldda_one.id ) ) ) + self.check_page_for_string( 'wind' ) + self.check_page_for_string( 'This is the wind component' ) + self.check_page_for_string( 'bag' ) + self.check_page_for_string( 'This is the bag component' ) + # Make sure other users can access the dataset from the Libraries view + self.logout() + self.login( email=regular_user2.email ) + self.home() + self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( "1.bed" ) + self.logout() + self.login( email=admin_user.email ) + self.home() + def test_085_editing_dataset_information( self ): + """Testing editing dataset template element information""" + # Need the current library_item_info_element.id + last_library_item_info_element = galaxy.model.LibraryItemInfoElement.query() \ + .order_by( desc( galaxy.model.LibraryItemInfoElement.table.c.id ) ).first() + global ldda_one_ele_2_field_name + ldda_one_ele_2_field_name = "info_element_%s" % str( last_library_item_info_element.id ) + ele_2_contents = 'pipe' + global ldda_one_ele_1_field_name + ldda_one_ele_1_field_name = "info_element_%s" % ( str( last_library_item_info_element.id - 1 ) ) + ele_1_contents = 'blown' + self.edit_ldda_template_element_info( str( library_one.id ), str( library_one.root_folder.id ), str( ldda_one.id ), + ldda_one.name, ldda_one_ele_1_field_name, ele_1_contents, ldda_one_ele_2_field_name, ele_2_contents ) + self.home() + def test_090_add_new_folder_to_root_folder( self ): """Testing adding a folder to a library root folder""" - self.login( email = 'test@bx.psu.edu' ) root_folder = library_one.root_folder name = "Root Folder's Folder One" description = "This is the root folder's Folder One" @@ -466,23 +628,238 @@ folder_one = galaxy.model.LibraryFolder.filter( and_( galaxy.model.LibraryFolder.table.c.parent_id==root_folder.id, galaxy.model.LibraryFolder.table.c.name==name, galaxy.model.LibraryFolder.table.c.description==description ) ).first() - assert folder_one is not None, 'Problem retrieving library folder named "Folder One" from the database' + assert folder_one is not None, 'Problem retrieving library folder named "%s" from the database' % name self.home() self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) self.check_page_for_string( name ) self.check_page_for_string( description ) - def test_080_add_dataset_with_private_role_restriction_to_folder( self ): - """Testing adding a dataset with a private role restriction to a folder""" - # Add a dataset restricted by regular_user1 private role - message ='This+is+a+test' - self.add_library_dataset( '1.bed', + # Make sure the library template is inherited + self.home() + self.visit_url( '%s/admin/folder?id=%s&library_id=%s&information=True' % ( self.url, str( folder_one.id ), str( library_one.id ) ) ) + self.check_page_for_string( 'wind' ) + self.check_page_for_string( 'This is the wind component' ) + self.check_page_for_string( 'bag' ) + self.check_page_for_string( 'This is the bag component' ) + self.home() + def test_095_add_folder_template( self ): + """Testing adding a new folder template to a folder""" + # Add a new information template to the folder + template_name = 'Folder Template 1' + ele_name_0 = 'Fu' + ele_help_0 = 'This is the Fu component'.replace( ' ', '+' ) + ele_name_1 = 'Bar' + ele_help_1 = 'This is the Bar component'.replace( ' ', '+' ) + self.home() + self.add_folder_info_template( str( library_one.id ), library_one.name, str( folder_one.id ), folder_one.name, + name=template_name, num_fields='2', ele_name_0=ele_name_0, ele_help_0=ele_help_0, + ele_name_1=ele_name_1, ele_help_1=ele_help_1 ) + self.home() + self.visit_url( '%s/admin/folder?id=%s&library_id=%s&information=True' % ( self.url, str( folder_one.id ), str( library_one.id ) ) ) + self.check_page_for_string( ele_name_0 ) + check_str = ele_help_0.replace( '+', ' ' ) + self.check_page_for_string( check_str ) + self.check_page_for_string( ele_name_1 ) + check_str = ele_help_1.replace( '+', ' ' ) + self.check_page_for_string( check_str ) + self.home() + def test_100_add_subfolder_to_folder( self ): + """Testing adding a folder to a library folder""" + name = "Folder One's Subfolder" + description = "This is the Folder One's subfolder" + self.add_folder( str( library_one.id ), str( folder_one.id ), name=name, description=description ) + global subfolder_one + subfolder_one = galaxy.model.LibraryFolder.filter( and_( galaxy.model.LibraryFolder.table.c.parent_id==folder_one.id, + galaxy.model.LibraryFolder.table.c.name==name, + galaxy.model.LibraryFolder.table.c.description==description ) ).first() + assert subfolder_one is not None, 'Problem retrieving library folder named "Folder Ones Subfolder" from the database' + self.home() + self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( name ) + self.check_page_for_string( description ) + # Make sure the parent folder's template is inherited + self.home() + self.visit_url( '%s/admin/folder?id=%s&library_id=%s&information=True' % ( self.url, str( folder_one.id ), str( library_one.id ) ) ) + self.check_page_for_string( 'Fu' ) + self.check_page_for_string( 'This is the Fu component' ) + self.check_page_for_string( 'Bar' ) + self.check_page_for_string( 'This is the Bar component' ) + # Make sure the library template is not inherited + try: + self.check_page_for_string( 'wind' ) + raise AssertionError( 'Library template inherited by folder when it should not have been.' ) + except: + pass + self.home() + def test_105_add_template_element( self ): + """Testing adding a new element to an existing library template""" + name = 'Library Template 1 renamed' + ele_name_1 = 'wind' + ele_desc_1 = 'This is the wind component' + ele_name_2 = 'bag' + ele_desc_2 = 'This is the bag component' + new_ele_name = 'Fubar' + new_ele_desc = 'This is the Fubar component' + library_one_template.refresh() + self.add_library_info_template_element( str( library_one.id ), + str( library_one_template.id ), + library_one_template.name, + ele_name_1, + ele_desc_1, + ele_name_2, + ele_desc_2, + new_ele_name=new_ele_name, + new_ele_desc=new_ele_desc ) + # Make sure the new template element shows up on the existing library info page + self.home() + self.visit_url( '%s/admin/library?id=%s&information=True' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( library_one.name ) + self.check_page_for_string( library_one.description ) + self.check_page_for_string( 'wind' ) + self.check_page_for_string( 'hello' ) + self.check_page_for_string( 'This is the wind component' ) + self.check_page_for_string( 'bag' ) + self.check_page_for_string( 'world' ) + self.check_page_for_string( 'This is the bag component' ) + self.check_page_for_string( 'Fubar' ) + self.check_page_for_string( 'This is the Fubar component' ) + # Make sure the new template element does not show up on existing info pages for folder_one since it has its own template + self.home() + self.visit_url( '%s/admin/folder?id=%s&library_id=%s&information=True' % ( self.url, str( folder_one.id ), str( library_one.id ) ) ) + self.check_page_for_string( 'Fu' ) + self.check_page_for_string( 'This is the Fu component' ) + self.check_page_for_string( 'Bar' ) + self.check_page_for_string( 'This is the Bar component' ) + try: + self.check_page_for_string( 'Fubar' ) + raise AssertionError( 'Changed library template inherited by folder "%s" when folder had an associated template of its own' ) + except: + pass + # Make sure the new template element shows up on existing info pages for ldda_one since it is contained in the root folder + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( folder_one.id ), str( ldda_one.id ) ) ) + # Visiting the above page will have resulted in the creation of a new LibraryItemInfoElement, so we'll retrieve it + # for later use + last_library_item_info_element = galaxy.model.LibraryItemInfoElement.query() \ + .order_by( desc( galaxy.model.LibraryItemInfoElement.table.c.id ) ).first() + global ldda_one_ele_3_field_name + ldda_one_ele_3_field_name = "info_element_%s" % str( last_library_item_info_element.id ) + self.check_page_for_string( 'wind' ) + self.check_page_for_string( 'This is the wind component' ) + self.check_page_for_string( 'bag' ) + self.check_page_for_string( 'This is the bag component' ) + self.check_page_for_string( 'Fubar' ) + self.check_page_for_string( 'This is the Fubar component' ) + self.home() + def test_110_add_2nd_new_folder_to_root_folder( self ): + """Testing adding a 2nd folder to a library root folder""" + root_folder = library_one.root_folder + name = "Folder Two" + description = "This is the root folder's Folder Two" + self.add_folder( str( library_one.id ), str( root_folder.id ), name=name, description=description ) + global folder_two + folder_two = galaxy.model.LibraryFolder.filter( and_( galaxy.model.LibraryFolder.table.c.parent_id==root_folder.id, + galaxy.model.LibraryFolder.table.c.name==name, + galaxy.model.LibraryFolder.table.c.description==description ) ).first() + assert folder_two is not None, 'Problem retrieving library folder named "%s" from the database' % name + self.home() + self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( name ) + self.check_page_for_string( description ) + # Make sure the changed library template is inherited to the new folder + self.home() + self.visit_url( '%s/admin/folder?id=%s&library_id=%s&information=True' % ( self.url, str( folder_two.id ), str( library_one.id ) ) ) + self.check_page_for_string( 'wind' ) + self.check_page_for_string( 'This is the wind component' ) + self.check_page_for_string( 'bag' ) + self.check_page_for_string( 'This is the bag component' ) + self.check_page_for_string( 'Fubar' ) + self.check_page_for_string( 'This is the Fubar component' ) + self.home() + def test_115_add_public_dataset_to_root_folders_2nd_subfolder( self ): + """Testing adding a public dataset to the root folder's 2nd sub-folder""" + actions = [ v.action for k, v in galaxy.model.Library.permitted_actions.items() ] + actions.sort() + message = "Testing adding a public dataset to the folder named %s" % folder_two.name + self.add_library_dataset( '2.bed', str( library_one.id ), - str( folder_one.id ), - folder_one.name, + str( folder_two.id ), + folder_two.name, file_format='bed', dbkey='hg18', - roles=[ str( regular_user1_private_role.id ) ], - message=message, + message=message.replace( ' ', '+' ), + root=False ) + global ldda_two + ldda_two = galaxy.model.LibraryDatasetDatasetAssociation.query() \ + .order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ).first() + assert ldda_two is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_two from the database' + self.home() + self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( "2.bed" ) + self.check_page_for_string( message ) + self.check_page_for_string( admin_user.email ) + def test_120_add_template_to_root_folders_2nd_subfolder( self ): + """Testing adding a template to the root folder's 2nd sub-folder""" + # Before adding the folder template, the inherited library template should be displayed + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( folder_two.id ), str( ldda_two.id ) ) ) + self.check_page_for_string( 'wind' ) + self.check_page_for_string( 'This is the wind component' ) + self.check_page_for_string( 'bag' ) + self.check_page_for_string( 'This is the bag component' ) + self.check_page_for_string( 'Fubar' ) + self.check_page_for_string( 'This is the Fubar component' ) + self.home() + # Add a new folde template + template_name = 'Folder 2 Template' + ele_name_0 = 'kill' + ele_help_0 = 'This is the kill component'.replace( ' ', '+' ) + ele_name_1 = 'bill' + ele_help_1 = 'This is the bill component'.replace( ' ', '+' ) + self.home() + self.add_folder_info_template( str( library_one.id ), library_one.name, str( folder_two.id ), folder_two.name, + name=template_name, num_fields='2', ele_name_0=ele_name_0, ele_help_0=ele_help_0, + ele_name_1=ele_name_1, ele_help_1=ele_help_1 ) + # Make sure the new template id displayed on the folder information page + self.home() + self.visit_url( '%s/admin/folder?id=%s&library_id=%s&information=True' % ( self.url, str( folder_two.id ), str( library_one.id ) ) ) + self.check_page_for_string( ele_name_0 ) + check_str = ele_help_0.replace( '+', ' ' ) + self.check_page_for_string( check_str ) + self.check_page_for_string( ele_name_1 ) + check_str = ele_help_1.replace( '+', ' ' ) + self.check_page_for_string( check_str ) + # The library dataset ldda_two had previously inherited the library template prior to the new folder template + # being introduced, so the library template should still be displayed on the ldda information page + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( folder_two.id ), str( ldda_two.id ) ) ) + self.check_page_for_string( 'wind' ) + self.check_page_for_string( 'This is the wind component' ) + self.check_page_for_string( 'bag' ) + self.check_page_for_string( 'This is the bag component' ) + self.check_page_for_string( 'Fubar' ) + self.check_page_for_string( 'This is the Fubar component' ) + # Make sure the new folder template is not displayed + try: + self.check_page_for_string( 'kill' ) + raise AssertionError( 'New folder template elements incorrectly included in information page for ldda "%s"' % ldda_two.name ) + except: + pass + self.home() + def test_125_add_2nd_public_dataset_to_root_folders_2nd_subfolder( self ): + """Testing adding a 2nd public dataset to the root folder's 2nd sub-folder""" + actions = [ v.action for k, v in galaxy.model.Library.permitted_actions.items() ] + actions.sort() + message = "Testing adding a 2nd public dataset to the folder named %s" % folder_two.name + self.add_library_dataset( '3.bed', + str( library_one.id ), + str( folder_two.id ), + folder_two.name, + file_format='bed', + dbkey='hg18', + message=message.replace( ' ', '+' ), root=False ) global ldda_three ldda_three = galaxy.model.LibraryDatasetDatasetAssociation.query() \ @@ -490,11 +867,67 @@ assert ldda_three is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_three from the database' self.home() self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) - self.check_page_for_string( "1.bed" ) + self.check_page_for_string( "3.bed" ) + self.check_page_for_string( message ) self.check_page_for_string( admin_user.email ) - def test_085_accessing_dataset_with_private_role_restriction( self ): + def test_130_editing_dataset_information_with_new_folder_template( self ): + """Testing editing dataset template element information with new inherited folder template""" + # Need the current library_item_info_element.id + last_library_item_info_element = galaxy.model.LibraryItemInfoElement.query() \ + .order_by( desc( galaxy.model.LibraryItemInfoElement.table.c.id ) ).first() + # Make sure the changed inherited template is included in the ldda information + ele_2_field_name = "info_element_%s" % str( last_library_item_info_element.id ) + ele_2_contents = 'II' + ele_2_help = 'This is the bill component' + ele_1_field_name = "info_element_%s" % ( str( last_library_item_info_element.id - 1 ) ) + ele_1_contents = 'Volume' + ele_1_help = 'This is the kill component' + self.edit_ldda_template_element_info( str( library_one.id ), str( folder_two.id ), str( ldda_three.id ), + ldda_three.name, ele_1_field_name, ele_1_contents, ele_2_field_name, ele_2_contents, + ele_1_help=ele_1_help, ele_2_help=ele_2_help ) + self.home() + def test_135_add_dataset_with_private_role_restriction_to_folder( self ): + """Testing adding a dataset with a private role restriction to a folder""" + # Add a dataset restricted by the following: + # DATASET_MANAGE_PERMISSIONS = "test@bx.psu.edu" via DefaultUserPermissions + # DATASET_ACCESS = "regular_user1" private role via this test method + # LIBRARY_ADD = "Role One" via inheritance from parent folder + # LIBRARY_MODIFY = "Role One" via inheritance from parent folder + # LIBRARY_MANAGE = "Role One" via inheritance from parent folder + # "Role One" members are: test@bx.psu.edu, test1@bx.psu.edu, test3@bx.psu.edu + # This means that only user test1@bx.psu.edu can see the dataset from the Libraries view + # + # TODO: this demonstrates a weakness in our logic: If test@bx.psu.edu cannot + # access the dataset from the Libraries view, then the DATASET_MANAGE_PERMISSIONS + # setting is useless if test@bx.psu.edu is not an admin. This should be corrected, + # by displaying a warning message on the permissions form. + message ='This is a test of the fourth dataset uploaded' + ele_name_0 = 'Fu' + ele_name_1 = 'Bar' + self.add_library_dataset( '4.bed', + str( library_one.id ), + str( folder_one.id ), + folder_one.name, + file_format='bed', + dbkey='hg18', + roles=[ str( regular_user1_private_role.id ) ], + message=message.replace( ' ', '+' ), + root=False, + check_template_str1=ele_name_0, + check_template_str2=ele_name_1 ) + global ldda_four + ldda_four = galaxy.model.LibraryDatasetDatasetAssociation.query() \ + .order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ).first() + assert ldda_four is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_four from the database' + self.home() + self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( "4.bed" ) + self.check_page_for_string( message ) + self.check_page_for_string( admin_user.email ) + self.home() + def test_140_accessing_dataset_with_private_role_restriction( self ): """Testing accessing a dataset with a private role restriction""" - # admin_user should not be able to see 1.bed from the analysis view's access librarys + # admin_user should not be able to see 2.bed from the analysis view's access libraries self.home() self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) try: @@ -502,21 +935,21 @@ raise AssertionError( '%s can see library folder %s when it contains only datasets restricted by role %s' \ % ( admin_user.email, folder_one.name, regular_user1_private_role.description ) ) except: - pass # This is the behavior we want + pass try: - self.check_page_for_string( '1.bed' ) - raise AssertionError( '%s can see dataset 1.bed in library folder %s when it was restricted by role %s' \ + self.check_page_for_string( '4.bed' ) + raise AssertionError( '%s can see dataset 4.bed in library folder %s when it was restricted by role %s' \ % ( admin_user.email, folder_one.name, regular_user1_private_role.description ) ) except: - pass # This is the behavior we want + pass self.logout() - # regular_user1 should be able to see 1.bed from the analysis view's access librarys + # regular_user1 should be able to see 4.bed from the analysis view's access librarys # since it was associated with regular_user1's private role self.login( email='test1@bx.psu.edu' ) self.home() self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) self.check_page_for_string( folder_one.name ) - self.check_page_for_string( '1.bed' ) + self.check_page_for_string( '4.bed' ) self.logout() # regular_user2 should not be able to see 1.bed from the analysis view's access librarys self.login( email='test2@bx.psu.edu' ) @@ -525,82 +958,139 @@ raise AssertionError( '%s can see library folder %s when it contains only datasets restricted by role %s' \ % ( regular_user2.email, folder_one.name, regular_user1_private_role.description ) ) except: - pass # This is the behavior we want + pass try: - self.check_page_for_string( '1.bed' ) - raise AssertionError( '%s can see dataset 1.bed in library folder %s when it was restricted by role %s' \ + self.check_page_for_string( '4.bed' ) + raise AssertionError( '%s can see dataset 4.bed in library folder %s when it was restricted by role %s' \ % ( regular_user2.email, folder_one.name, regular_user1_private_role.description ) ) except: - pass # This is the behavior we want + pass self.logout() - # regular_user3 should not be able to see 1.bed from the analysis view's access librarys + # regular_user3 should not be able to see 2.bed from the analysis view's access librarys self.login( email='test3@bx.psu.edu' ) try: self.check_page_for_string( folder_one.name ) raise AssertionError( '%s can see library folder %s when it contains only datasets restricted by role %s' \ % ( regular_user3.email, folder_one.name, regular_user1_private_role.description ) ) except: - pass # This is the behavior we want + pass try: - self.check_page_for_string( '1.bed' ) - raise AssertionError( '%s can see dataset 1.bed in library folder %s when it was restricted by role %s' \ + self.check_page_for_string( '4.bed' ) + raise AssertionError( '%s can see dataset 4.bed in library folder %s when it was restricted by role %s' \ % ( regular_user3.email, folder_one.name, regular_user1_private_role.description ) ) except: pass # This is the behavior we want self.logout() - def test_090_add_dataset_with_role_restriction_to_folder( self ): - """Testing adding a dataset with a role restriction to a folder""" + self.login( email=admin_user.email ) + self.home() + def test_145_change_dataset_access_permission( self ): + """Testing changing the access permission on a dataset with a private role restriction""" + # We need admin_user to be able to access 2.bed + permissions_in = [ k for k, v in galaxy.model.Dataset.permitted_actions.items() ] + \ + [ k for k, v in galaxy.model.Library.permitted_actions.items() ] + permissions_out = [] + role_ids = "%s,%s" % ( str( role_one.id ), str( admin_user_private_role.id ) ) + self.set_library_dataset_permissions( str( library_one.id ), str( folder_one.id ), str( ldda_four.id ), ldda_four.name, + role_ids, permissions_in, permissions_out ) + # admin_user should now be able to see 4.bed from the analysis view's access libraries + self.home() + self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( ldda_four.name ) + self.home() + def test_150_editing_restricted_datasets_information( self ): + """Testing editing a restricted library dataset's template element information""" + ele_1_contents = '' + ele_2_contents = '' + ele_3_contents = 'Adding Fubar text' + self.edit_ldda_template_element_info( str( library_one.id ), str( library_one.root_folder.id ), str( ldda_one.id ), + ldda_one.name, ldda_one_ele_1_field_name, ele_1_contents, ldda_one_ele_2_field_name, ele_2_contents, + ele_1_help='This is the wind component'.replace( ' ', '+' ), + ele_2_help='This is the bag component'.replace( ' ', '+' ), + ele_3_field_name=ldda_one_ele_3_field_name, ele_3_contents=ele_3_contents.replace( ' ', '+' ) ) + # Check the updated information from the libraries view + self.home() + self.visit_url( '%s/library/library_dataset_dataset_association?info=True&library_id=%s&folder_id=%s&id=%s' \ + % ( self.url, str( library_one.id ), str( library_one.root_folder.id ), str( ldda_one.id ) ) ) + self.check_page_for_string( ele_3_contents ) + try: + self.check_page_for_string( 'blown' ) + raise AssertionError( 'Element contents were not correctly eliminated when the information was edited for ldda %s' % ldda_one.name) + except: + pass + self.home() + def test_155_add_dataset_with_role_associated_with_group_and_users( self ): + """Testing adding a dataset with a role that is associated with a group and users""" self.login( email='test@bx.psu.edu' ) # Add a dataset restricted by role_two, which is currently associated as follows: # groups: group_two # users: test@bx.psu.edu, test1@bx.psu.edu via group_two - message ='This+is+a+test' - self.add_library_dataset( '2.bed', + message = 'Testing adding a dataset with a role that is associated with a group and users' + ele_name_0 = 'Fu' + ele_name_1 = 'Bar' + self.add_library_dataset( '5.bed', str( library_one.id ), str( folder_one.id ), folder_one.name, file_format='bed', dbkey='hg17', roles=[ str( role_two.id ) ], - message=message, - root=False ) - global ldda_two - ldda_two = galaxy.model.LibraryDatasetDatasetAssociation.query() \ + message=message.replace( ' ', '+' ), + root=False, + check_template_str1=ele_name_0, + check_template_str2=ele_name_1 ) + global ldda_five + ldda_five = galaxy.model.LibraryDatasetDatasetAssociation.query() \ .order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ).first() - assert ldda_two is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_two from the database' + assert ldda_five is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_five from the database' self.home() self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) - self.check_page_for_string( "2.bed" ) + self.check_page_for_string( "5.bed" ) + self.check_page_for_string( message ) self.check_page_for_string( admin_user.email ) - def test_095_accessing_datasets_with_role_restriction( self ): - """Testing accessing a dataset with a role restriction""" - # admin_user should be able to see 2.bed since she is associated with role_two + self.home() + def test_160_accessing_dataset_with_role_associated_with_group_and_users( self ): + """Testing accessing a dataset with a role that is associated with a group and users""" + # admin_user should be able to see 5.bed since she is associated with role_two self.home() self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) - self.check_page_for_string( "2.bed" ) + self.check_page_for_string( "5.bed" ) self.check_page_for_string( admin_user.email ) self.logout() - # regular_user1 should be able to see 2.bed since she is associated with group_two + # regular_user1 should be able to see 5.bed since she is associated with group_two self.login( email = 'test1@bx.psu.edu' ) self.home() self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) self.check_page_for_string( folder_one.name ) - self.check_page_for_string( '2.bed' ) + self.check_page_for_string( '5.bed' ) self.check_page_for_string( admin_user.email ) - # Check the permissions on the dataset - should be 'access', which only allows viewing the information + # Check the permissions on the dataset 5.bed - they are as folows: + # DATASET_MANAGE_PERMISSIONS = test@bx.psu.edu + # DATASET_ACCESS = Role Two + # Role Two associations: test@bx.psu.edu and Group Two + # Group Two members: Role One, Role Two, test1@bx.psu.edu + # Role One associations: test@bx.psu.edu, test1@bx.psu.edu, test3@bx.psu.edu + # LIBRARY_ADD = Role One + # Role One aassociations: test@bx.psu.edu, test1@bx.psu.edu, test3@bx.psu.edu + # LIBRARY_MODIFY = Role One + # Role One aassociations: test@bx.psu.edu, test1@bx.psu.edu, test3@bx.psu.edu + # LIBRARY_MANAGE = Role One + # Role One aassociations: test@bx.psu.edu, test1@bx.psu.edu, test3@bx.psu.edu self.home() - self.visit_url( '%s/library/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s' % ( self.url, str( library_one.id ), str( folder_one.id ), str( ldda_two.id ) ) ) - self.check_page_for_string( '2.bed' ) + self.visit_url( '%s/library/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s' \ + % ( self.url, str( library_one.id ), str( folder_one.id ), str( ldda_five.id ) ) ) + self.check_page_for_string( '5.bed' ) self.check_page_for_string( 'This is the latest version of this library dataset' ) - self.check_page_for_string( 'View attributes of 2.bed' ) + # Current user test1@bx.psu.edu has Role One, which has the LIBRARY_MODIFY permission + self.check_page_for_string( 'Edit attributes of 5.bed' ) self.home() # Test importing the restricted dataset into a history, can't use the # ~/admin/libraries form as twill barfs on it so we'll simulate the form submission # by going directly to the form action - self.visit_url( '%s/library/datasets?do_action=add&ldda_ids=%d&library_id=%s' % ( self.url, ldda_two.id, str( library_one.id ) ) ) + self.visit_url( '%s/library/datasets?do_action=add&ldda_ids=%d&library_id=%s' \ + % ( self.url, ldda_five.id, str( library_one.id ) ) ) self.check_page_for_string( '1 dataset(s) have been imported into your history' ) self.logout() - # regular_user2 should not be able to see 2.bed + # regular_user2 should not be able to see 5.bed self.login( email = 'test2@bx.psu.edu' ) self.home() self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) @@ -609,96 +1099,35 @@ raise AssertionError( '%s can see library folder %s when it contains only datasets restricted by role %s' \ % ( regular_user2.email, folder_one.name, regular_user1_private_role.description ) ) except: - pass # This is the behavior we want + pass try: - self.check_page_for_string( '2.bed' ) - raise AssertionError( '%s can see dataset 2.bed in library folder %s when it was restricted by role %s' \ + self.check_page_for_string( '5.bed' ) + raise AssertionError( '%s can see dataset 5.bed in library folder %s when it was restricted by role %s' \ % ( regular_user2.email, folder_one.name, regular_user1_private_role.description ) ) except: - pass # This is the behavior we want - # regular_user3 should not be able to see 2.bed + pass + # regular_user3 should not be able to see folder_one ( even though it does not contain any datasets that she + # can access ) since she has Role One, and Role One has all library permissions ( see above ). self.login( email = 'test3@bx.psu.edu' ) self.home() self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( folder_one.name ) + # regular_user3 should not be able to see 5.bed since users must have every role associated + # with the dataset in order to access it, and regular_user3 isnot associated with Role Two try: - self.check_page_for_string( folder_one.name ) - raise AssertionError( '%s can see library folder %s when it contains only datasets restricted by role %s' \ + self.check_page_for_string( '5.bed' ) + raise AssertionError( '%s can see dataset 5.bed in library folder %s when it was restricted by role %s' \ % ( regular_user3.email, folder_one.name, regular_user1_private_role.description ) ) except: - pass # This is the behavior we want - try: - self.check_page_for_string( '2.bed' ) - raise AssertionError( '%s can see dataset 2.bed in library folder %s when it was restricted by role %s' \ - % ( regular_user3.email, folder_one.name, regular_user1_private_role.description ) ) - except: - pass # This is the behavior we want + pass self.logout() - def test_100_add_public_dataset_to_root_folder( self ): - """Testing adding a public dataset to a library root folder""" self.login( email='test@bx.psu.edu' ) - folder = library_one.root_folder - message ='This+is+a+test' - self.add_library_dataset( '3.bed', - str( library_one.id ), - str( folder.id ), - folder.name, - file_format='bed', - dbkey='hg16', - roles=[], - message=message, - root=True ) - global ldda_three - ldda_three = galaxy.model.LibraryDatasetDatasetAssociation.query() \ - .order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ).first() - assert ldda_three is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_three from the database' - self.visit_page( 'admin/browse_library?id=%s' % ( str( library_one.id ) ) ) - self.check_page_for_string( "3.bed" ) - self.check_page_for_string( admin_user.email ) - self.logout() - def test_105_access_public_library_dataset( self ): - """Testing accessing a public library dataset""" - # regular_user1 should not be able to see 3.bed - self.login( email = 'test1@bx.psu.edu' ) - self.home() - self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) - self.check_page_for_string( library_one.name ) - self.check_page_for_string( '3.bed' ) - self.check_page_for_string( admin_user.email ) - self.logout() - # regular_user2 should not be able to see 3.bed - self.login( email = 'test2@bx.psu.edu' ) - self.home() - self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) - self.check_page_for_string( library_one.name ) - self.check_page_for_string( '3.bed' ) - self.check_page_for_string( admin_user.email ) - self.logout() - # regular_user3 should not be able to see 3.bed - self.login( email = 'test3@bx.psu.edu' ) - self.home() - self.visit_url( '%s/library/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) - self.check_page_for_string( library_one.name ) - self.check_page_for_string( '3.bed' ) - self.check_page_for_string( admin_user.email ) - # Test selecting "View this dataset's information" - self.home() - self.visit_url( '%s/library/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s' % ( self.url, str( library_one.id ), str( folder_one.id ), str( ldda_three.id ) ) ) - self.check_page_for_string( '3.bed' ) - self.check_page_for_string( 'This is the latest version of this library dataset' ) - self.check_page_for_string( 'View attributes of 3.bed' ) - # Test importing a library dataset into a history - self.home() - self.visit_url( '%s/library/datasets?library_id=%s&do_action=add&ldda_ids=%d' % ( self.url, str( library_one.id ), ldda_three.id ) ) - self.check_page_for_string( '1 dataset(s) have been imported into your history' ) - self.logout() - def test_110_copy_dataset_from_history_to_root_folder( self ): - """Testing copying a dataset from the current history to a library root folder""" - folder = library_one.root_folder - self.login( email='test@bx.psu.edu' ) + def test_165_copy_dataset_from_history_to_subfolder( self ): + """Testing copying a dataset from the current history to a subfolder""" self.new_history() - self.upload_file( "1.bed" ) + self.upload_file( "6.bed" ) latest_hda = galaxy.model.HistoryDatasetAssociation.query().order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ).first() - self.add_history_datasets_to_library( str( library_one.id ), str( folder.id ), folder.name, str( latest_hda.id ), root=True ) + self.add_history_datasets_to_library( str( library_one.id ), str( subfolder_one.id ), subfolder_one.name, str( latest_hda.id ), root=False ) # Test for DatasetPermissionss, the default setting is "manage permissions" last_dataset_created = galaxy.model.Dataset.query().order_by( desc( galaxy.model.Dataset.table.c.create_time ) ).first() dps = galaxy.model.DatasetPermissions.filter( galaxy.model.DatasetPermissions.table.c.dataset_id==last_dataset_created.id ).all() @@ -708,14 +1137,145 @@ raise AssertionError( 'More than 1 DatasetPermissionss created for dataset id: %d' % last_dataset_created.id ) for dp in dps: if not dp.action == 'manage permissions': - raise AssertionError( 'DatasetPermissions.action "%s" is not the DefaultHistoryPermission setting of "manage permissions"' % \ - str( dp.action ) ) - def test_115_add_datasets_from_library_dir( self ): - """Testing adding 3 datasets from a library directory to a folder""" + raise AssertionError( 'DatasetPermissions.action "%s" is not the DefaultHistoryPermission setting of "manage permissions"' \ + % str( dp.action ) ) + global ldda_six + ldda_six = galaxy.model.LibraryDatasetDatasetAssociation.query() \ + .order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ).first() + assert ldda_six is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_six from the database' + # Make sure the correct template was inherited + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?edit_info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( subfolder_one.id ), str( ldda_six.id ) ) ) + self.check_page_for_string( 'Fu' ) + self.check_page_for_string( 'This is the Fu component' ) + self.check_page_for_string( 'Bar' ) + self.check_page_for_string( 'This is the Bar component' ) + def test_170_editing_dataset_attribute_info( self ): + """Testing editing a datasets attribute information""" + new_ldda_name = '6.bed ( version 1 )' + self.edit_ldda_attribute_info( str( library_one.id ), str( subfolder_one.id ), str( ldda_six.id ), ldda_six.name, new_ldda_name ) + self.home() + ldda_six.refresh() + self.visit_url( '%s/admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( ldda_six.name ) + self.home() + def test_175_uploading_new_dataset_version( self ): + """Testing uploading a new version of a dataset""" + message = 'Testing uploading a new version of a dataset' + self.upload_new_dataset_version( '6.bed', + str( library_one.id ), + str( subfolder_one.id ), + str( subfolder_one.name ), + str( ldda_six.library_dataset.id ), + ldda_six.name, + file_format='auto', + dbkey='hg18', + message=message.replace( ' ', '+' ), + check_template_str1='Fu', + check_template_str2='Bar' ) + global ldda_six_version_two + ldda_six_version_two = galaxy.model.LibraryDatasetDatasetAssociation.query() \ + .order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ).first() + assert ldda_six_version_two is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_six_version_two from the database' + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( subfolder_one.id ), str( ldda_six_version_two.id ) ) ) + self.check_page_for_string( 'This is the latest version of this library dataset' ) + # Make sure the correct template was inherited + self.check_page_for_string( 'Fu' ) + self.check_page_for_string( 'This is the Fu component' ) + self.check_page_for_string( 'Bar' ) + self.check_page_for_string( 'This is the Bar component' ) + check_str = 'Expired versions of %s' % ldda_six_version_two.name + self.check_page_for_string( check_str ) + self.check_page_for_string( ldda_six.name ) + self.home() + # Make sure th permissions are the same + ldda_six.refresh() + if len( ldda_six.actions ) != len( ldda_six_version_two.actions ): + raise AssertionError( 'ldda "%s" actions "%s" != ldda "%s" actions "%s"' \ + % ( ldda_six.name, str( ldda_six.actions ), + ldda_six_version_two.name, str( ldda_six_version_two.actions ) ) ) + if len( ldda_six.library_dataset.actions ) != len( ldda_six_version_two.library_dataset.actions ): + raise AssertionError( 'ldda.library_dataset "%s" actions "%s" != ldda.library_dataset "%s" actions "%s"' \ + % ( ldda_six.name, str( ldda_six.library_dataset.actions ), ldda_six_version_two.name, str( ldda_six_version_two.library_dataset.actions ) ) ) + if len( ldda_six.dataset.actions ) != len( ldda_six_version_two.dataset.actions ): + raise AssertionError( 'ldda.dataset "%s" actions "%s" != ldda.dataset "%s" actions "%s"' \ + % ( ldda_six.name, str( ldda_six.dataset.actions ), ldda_six_version_two.name, str( ldda_six_version_two.dataset.actions ) ) ) + # Check the previous version + self.visit_url( "%s/admin/library_dataset_dataset_association?info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( subfolder_one.id ), str( ldda_six.id ) ) ) + self.check_page_for_string( 'This is an expired version of this library dataset' ) + self.home() + def test_180_uploading_new_dataset_versions( self ): + """Testing uploading new versions of a dataset using a directory of files""" + message = 'Testing uploading new versions of a dataset using a directory of files' + ldda_six_version_two.refresh() + self.upload_new_dataset_versions( str( library_one.id ), + str( subfolder_one.id ), + str( subfolder_one.name ), + str( ldda_six_version_two.library_dataset.id ), + ldda_six_version_two.name, + file_format='auto', + dbkey='hg18', + message=message.replace( ' ', '+' ), + check_template_str1='Fu', + check_template_str2='Bar' ) + global ldda_six_version_five + ldda_six_version_five = galaxy.model.LibraryDatasetDatasetAssociation.query() \ + .order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ).first() + assert ldda_six_version_five is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda_six_version_five from the database' + self.home() + self.visit_url( "%s/admin/library_dataset_dataset_association?info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( subfolder_one.id ), str( ldda_six_version_five.id ) ) ) + self.check_page_for_string( 'This is the latest version of this library dataset' ) + # Make sure the correct template was inherited + self.check_page_for_string( 'Fu' ) + self.check_page_for_string( 'This is the Fu component' ) + self.check_page_for_string( 'Bar' ) + self.check_page_for_string( 'This is the Bar component' ) + check_str = 'Expired versions of %s' % ldda_six_version_five.name + self.check_page_for_string( check_str ) + self.check_page_for_string( ldda_six.name ) + self.home() + # Make sure th permissions are the same + ldda_six.refresh() + if len( ldda_six.actions ) != len( ldda_six_version_five.actions ): + raise AssertionError( 'ldda "%s" actions "%s" != ldda "%s" actions "%s"' \ + % ( ldda_six.name, str( ldda_six.actions ), + ldda_six_version_five.name, str( ldda_six_version_five.actions ) ) ) + if len( ldda_six.library_dataset.actions ) != len( ldda_six_version_five.library_dataset.actions ): + raise AssertionError( 'ldda.library_dataset "%s" actions "%s" != ldda.library_dataset "%s" actions "%s"' \ + % ( ldda_six.name, str( ldda_six.library_dataset.actions ), ldda_six_version_five.name, str( ldda_six_version_five.library_dataset.actions ) ) ) + if len( ldda_six.dataset.actions ) != len( ldda_six_version_five.dataset.actions ): + raise AssertionError( 'ldda.dataset "%s" actions "%s" != ldda.dataset "%s" actions "%s"' \ + % ( ldda_six.name, str( ldda_six.dataset.actions ), ldda_six_version_five.name, str( ldda_six_version_five.dataset.actions ) ) ) + # Check the previous version + self.visit_url( "%s/admin/library_dataset_dataset_association?info=True&library_id=%s&folder_id=%s&id=%s" % \ + ( self.url, str( library_one.id ), str( subfolder_one.id ), str( ldda_six_version_two.id ) ) ) + self.check_page_for_string( 'This is an expired version of this library dataset' ) + self.home() + def test_185_upload_datasets_from_library_dir( self ): + """Testing uploading 3 datasets from a library directory to a root folder""" + message = 'This is a test for uploading a directory of files' roles_tuple = [ ( str( role_one.id ), role_one.name ) ] - self.add_datasets_from_library_dir( str( library_one.id ), str( folder_one.id ), folder_one.name, roles_tuple=roles_tuple, root=False ) - def test_120_change_permissions_on_datasets_imported_from_library( self ): - """Testing changing the permissions on library datasets imported into a history""" + self.add_datasets_from_library_dir( str( library_one.id ), + str( library_one.root_folder.id ), + library_one.root_folder.name, + roles_tuple=roles_tuple, + message=message.replace( '+', ' ' ), + root=True, + check_template_str1='wind', + check_template_str2='bag', + check_template_str3='Fubar' ) + self.home() + self.visit_page( 'admin/browse_library?id=%s' % ( str( library_one.id ) ) ) + self.check_page_for_string( admin_user.email ) + self.check_page_for_string( message ) + self.home() + def test_190_change_permissions_on_datasets_uploaded_from_library_dir( self ): + """Testing changing the permissions on datasets uploaded from a directory""" # It would be nice if twill functioned such that the above test resulted in a # form with the uploaded datasets selected, but it does not ( they're not checked ), # so we'll have to simulate this behavior ( not ideal ) for the 'edit' action. We @@ -807,21 +1367,22 @@ self.check_page_for_string( check_str ) raise AssertionError( '%s incorrectly has DATASET_MANAGE_PERMISSIONS on datasets imported from a library' % admin_user.email ) except: - pass # This is the behavior we want + pass try: # This should no longer be possible self.check_page_for_string( 'Role members can manage the roles associated with this dataset' ) raise AssertionError( '%s incorrectly has DATASET_MANAGE_PERMISSIONS on datasets imported from a library' % admin_user.email ) except: - pass # This is the behavior we want + pass try: # This should no longer be possible self.check_page_for_string( 'Role members can import this dataset into their history for analysis' ) raise AssertionError( '%s incorrectly has DATASET_MANAGE_PERMISSIONS on datasets imported from a library' % admin_user.email ) except: - pass # This is the behavior we want + pass check_edit_page2( latest_3_lddas ) - def test_125_mark_group_deleted( self ): + self.home() + def test_195_mark_group_deleted( self ): """Testing marking a group as deleted""" self.home() self.visit_url( '%s/admin/groups' % self.url ) @@ -835,13 +1396,13 @@ raise AssertionError( '%s incorrectly lost all members when it was marked as deleted.' % group_two.name ) if not group_two.roles: raise AssertionError( '%s incorrectly lost all role associations when it was marked as deleted.' % group_two.name ) - def test_130_undelete_group( self ): + def test_200_undelete_group( self ): """Testing undeleting a deleted group""" self.undelete_group( str( group_two.id ), group_two.name ) group_two.refresh() if group_two.deleted: raise AssertionError( '%s was not correctly marked as not deleted.' % group_two.name ) - def test_135_mark_role_deleted( self ): + def test_205_mark_role_deleted( self ): """Testing marking a role as deleted""" self.home() self.visit_url( '%s/admin/roles' % self.url ) @@ -855,83 +1416,90 @@ raise AssertionError( '%s incorrectly lost all user associations when it was marked as deleted.' % role_two.name ) if not role_two.groups: raise AssertionError( '%s incorrectly lost all group associations when it was marked as deleted.' % role_two.name ) - def test_140_undelete_role( self ): + def test_210_undelete_role( self ): """Testing undeleting a deleted role""" self.undelete_role( str( role_two.id ), role_two.name ) - def test_145_mark_library_deleted( self ): + def test_215_mark_dataset_deleted( self ): + """Testing marking a library dataset as deleted""" + self.home() + self.delete_library_item( str( library_one.id ), str( ldda_two.library_dataset.id ), ldda_two.name, library_item_type='library_dataset' ) + self.home() + self.visit_page( 'admin/browse_library?id=%s' % ( str( library_one.id ) ) ) + try: + # 2.bed was only contained in the library in 1 place, so it should no longer display + self.check_page_for_string( ldda_two.name ) + raise AssertionError( "Dataset '%s' is incorrectly displayed in the library after it has been deleted." % ldda_two.name ) + except: + pass + self.home() + def test_220_display_deleted_dataset( self ): + """Testing displaying deleted dataset""" + self.home() + self.visit_url( "%s/admin/browse_library?id=%s&show_deleted=True" % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( ldda_two.name ) + self.home() + def test_225_hide_deleted_dataset( self ): + """Testing hiding deleted dataset""" + self.home() + self.visit_url( "%s/admin/browse_library?id=%s&show_deleted=False" % ( self.url, str( library_one.id ) ) ) + try: + self.check_page_for_string( ldda_two.name ) + raise AssertionError( "Dataset '%s' is incorrectly displayed in the library after it has been deleted." % ldda_two.name ) + except: + pass + self.home() + def test_230_mark_folder_deleted( self ): + """Testing marking a library folder as deleted""" + self.home() + self.delete_library_item( str( library_one.id ), str( folder_two.id ), folder_two.name, library_item_type='folder' ) + self.home() + self.visit_page( 'admin/browse_library?id=%s' % ( str( library_one.id ) ) ) + try: + self.check_page_for_string( folder_two.name ) + raise AssertionError( "Folder '%s' is incorrectly displayed in the library after it has been deleted." % folder_two.name ) + except: + pass + self.home() + def test_230_mark_folder_undeleted( self ): + """Testing marking a library folder as undeleted""" + self.home() + self.undelete_library_item( str( library_one.id ), str( folder_two.id ), folder_two.name, library_item_type='folder' ) + self.home() + self.visit_page( 'admin/browse_library?id=%s' % ( str( library_one.id ) ) ) + self.check_page_for_string( folder_two.name ) + try: + # 2.bed was deleted before the folder was deleted, so state should have been saved. In order + # fro 2.bed to be displayed, it would itself have to be marked undeleted. + self.check_page_for_string( ldda_two.name ) + raise AssertionError( "Dataset '%s' is incorrectly displayed in the library after parent folder was undeleted." % ldda_two.name ) + except: + pass + self.home() + def test_235_mark_library_deleted( self ): """Testing marking a library as deleted""" - # TODO: this needs to be re-engineered... - self.mark_library_deleted( str( library_one.id ), library_one.name ) - # Make sure the library was deleted - library_one.refresh() - if not library_one.deleted: - raise AssertionError( 'The library id %s named "%s" has not been marked as deleted.' % ( str( library_one.id ), library_one.name ) ) - def check_folder( library_folder ): - for folder in library_folder.folders: - folder.refresh() - # Make sure all of the library_folders are deleted - if not folder.deleted: - raise AssertionError( 'The library_folder named "%s" has not been marked as deleted ( library.id: %s ).' % \ - ( folder.name, str( library_one.id ) ) ) - check_folder( folder ) - # Make sure all of the LibraryDatasets and associated objects are deleted - library_folder.refresh() - for library_dataset in library_folder.datasets: - library_dataset.refresh() - ldda = library_dataset.library_dataset_dataset_association - if ldda: - ldda.refresh() - if not ldda.deleted: - raise AssertionError( 'The library_dataset_dataset_association id %s named "%s" has not been marked as deleted ( library.id: %s ).' % \ - ( str( ldda.id ), ldda.name, str( library_one.id ) ) ) - # Make sure none of the datasets have been deleted since that should occur only when the library is purged - ldda.dataset.refresh() - if ldda.dataset.deleted: - raise AssertionError( 'The dataset with id "%s" has been marked as deleted when it should not have been.' % ldda.dataset.id ) - if not library_dataset.deleted: - raise AssertionError( 'The library_dataset id %s named "%s" has not been marked as deleted ( library.id: %s ).' % \ - ( str( library_dataset.id ), library_dataset.name, str( library_one.id ) ) ) - check_folder( library_one.root_folder ) - def test_150_undelete_library( self ): - """Testing marking a library as not deleted""" - self.undelete_library( str( library_one.id ), library_one.name ) - # Make sure the library is undeleted - library_one.refresh() - if library_one.deleted: - raise AssertionError( 'The library id %s named "%s" has not been marked as undeleted.' % ( str( library_one.id ), library_one.name ) ) - def check_folder( library_folder ): - for folder in library_folder.folders: - folder.refresh() - # Make sure all of the library_folders are undeleted - if folder.deleted: - raise AssertionError( 'The library_folder id %s named "%s" has not been marked as undeleted ( library.id: %s ).' % \ - ( str( folder.id ), folder.name, str( library_one.id ) ) ) - check_folder( folder ) - # Make sure all of the LibraryDatasets and associated objects are undeleted - library_folder.refresh() - for library_dataset in library_folder.datasets: - library_dataset.refresh() - ldda = library_dataset.library_dataset_dataset_association - if ldda: - ldda.refresh() - if ldda.deleted: - raise AssertionError( 'The library_dataset_dataset_association id %s named "%s" has not been marked as undeleted ( library.id: %s ).' % \ - ( str( ldda.id ), ldda.name, str( library_one.id ) ) ) - # Make sure all of the datasets have been undeleted - if ldda.dataset.deleted: - raise AssertionError( 'The dataset with id "%s" has not been marked as undeleted.' % ldda.dataset.id ) - if library_dataset.deleted: - raise AssertionError( 'The library_dataset id %s named "%s" has not been marked as undeleted ( library.id: %s ).' % \ - ( str( library_dataset.id ), library_dataset.name, str( library_one.id ) ) ) - check_folder( library_one.root_folder ) - # Mark library as deleted again so we can test purging it - self.mark_library_deleted( str( library_one.id ), library_one.name ) - # Make sure the library is deleted again - library_one.refresh() - if not library_one.deleted: - raise AssertionError( 'The library id %s named "%s" has not been marked as deleted after it was undeleted.' % \ - ( str( library_one.id ), library_one.name ) ) - def test_155_purge_user( self ): + self.home() + # First mark folder_two as deleted to further test state saving when we undelete the library + self.delete_library_item( str( library_one.id ), str( folder_two.id ), folder_two.name, library_item_type='folder' ) + self.delete_library_item( str( library_one.id ), str( library_one.id ), library_one.name, library_item_type='library' ) + self.home() + self.visit_page( 'admin/deleted_libraries' ) + self.check_page_for_string( library_one.name ) + self.home() + def test_240_mark_library_undeleted( self ): + """Testing marking a library as undeleted""" + self.home() + self.undelete_library_item( str( library_one.id ), str( library_one.id ), library_one.name, library_item_type='library' ) + self.home() + self.visit_page( 'admin/browse_library?id=%s' % ( str( library_one.id ) ) ) + self.check_page_for_string( library_one.name ) + try: + # folder_two was marked deleted before the library was deleted, so it should not be displayed + self.check_page_for_string( folder_two.name ) + raise AssertionError( "Deleted folder '%s' is incorrectly displayed in the library after the library was undeleted." % folder_two.name ) + except: + pass + self.home() + def test_245_purge_user( self ): """Testing purging a user account""" self.mark_user_deleted( user_id=regular_user3.id, email=regular_user3.email ) self.purge_user( str( regular_user3.id ), regular_user3.email ) @@ -976,7 +1544,7 @@ role = galaxy.model.Role.get( ura.role_id ) if role.type != 'private': raise AssertionError( 'UserRoleAssociations for user %s are not related with the private role.' % regular_user3.email ) - def test_160_manually_unpurge_user( self ): + def test_250_manually_unpurge_user( self ): """Testing manually un-purging a user account""" # Reset the user for later test runs. The user's private Role and DefaultUserPermissions for that role # should have been preserved, so all we need to do is reset purged and deleted. @@ -984,7 +1552,7 @@ regular_user3.purged = False regular_user3.deleted = False regular_user3.flush() - def test_165_purge_group( self ): + def test_255_purge_group( self ): """Testing purging a group""" group_id = str( group_two.id ) self.mark_group_deleted( group_id, group_two.name ) @@ -999,7 +1567,7 @@ raise AssertionError( "Purging the group did not delete the GroupRoleAssociations for group_id '%s'" % group_id ) # Undelete the group for later test runs self.undelete_group( group_id, group_two.name ) - def test_170_purge_role( self ): + def test_260_purge_role( self ): """Testing purging a role""" role_id = str( role_two.id ) self.mark_role_deleted( role_id, role_two.name ) @@ -1024,14 +1592,14 @@ dp = galaxy.model.DatasetPermissions.filter( galaxy.model.DatasetPermissions.table.c.role_id == role_id ).all() if dp: raise AssertionError( "Purging the role did not delete the DatasetPermissionss for role_id '%s'" % role_id ) - def test_175_manually_unpurge_role( self ): + def test_265_manually_unpurge_role( self ): """Testing manually un-purging a role""" # Manually unpurge, then undelete the role for later test runs # TODO: If we decide to implement the GUI feature for un-purging a role, replace this with a method call role_two.purged = False role_two.flush() self.undelete_role( str( role_two.id ), role_two.name ) - def test_180_purge_library( self ): + def test_270_purge_library( self ): """Testing purging a library""" self.purge_library( str( library_one.id ), library_one.name ) # Make sure the library was purged @@ -1065,8 +1633,17 @@ raise AssertionError( 'The library_dataset id %s named "%s" has not been marked as deleted.' % \ ( str( library_dataset.id ), library_dataset.name ) ) check_folder( library_one.root_folder ) - def test_185_reset_data_for_later_test_runs( self ): + def test_275_reset_data_for_later_test_runs( self ): """Reseting data to enable later test runs to pass""" + ################## + # Eliminate all templates and info associations + ################## + for lia in library_one.library_info_associations: + lia.delete() + lia.flush() + for lita in library_one.library_info_template_associations: + lita.delete() + lita.flush() ################## # Eliminate all non-private roles ################## @@ -1080,7 +1657,7 @@ ################## # Eliminate all groups ################## - for group in [ group_one, group_two ]: + for group in [ group_zero, group_one, group_two ]: self.mark_group_deleted( str( group.id ), group.name ) self.purge_group( str( group.id ), group.name ) # Manually delete the group from the database