Separate information from permissions at the LibraryDataset level, and fix a whole slew of bugs. There are still a few known weaknesses / issues, but this rev is fairly close to concluding phase 1 of the new library features for Encode.

This commit is contained in:
Greg Von Kuster
2009-02-20 15:43:10 -05:00
parent 6fd54350eb
commit bef705eb14
21 changed files with 1000 additions and 667 deletions
+177 -133
View File
@@ -1108,6 +1108,13 @@ class Admin( BaseController ):
params = util.Params( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
if params.get( 'permissions', False ):
action = 'permissions'
elif params.get( 'versions', False ):
action = 'versions'
else:
# 'information' will be the default
action = 'information'
library_dataset = trans.app.model.LibraryDataset.get( id )
if not library_dataset:
msg = "Invalid library dataset specified, id: %s" %str( id )
@@ -1116,33 +1123,59 @@ class Admin( BaseController ):
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if params.get( 'edit_attributes_button', False ):
library_dataset.name = name
library_dataset.info = info
msg = 'Attributes updated for library dataset %s' % library_dataset.name
elif params.get( 'change_version', False ):
target_lda = trans.app.model.LibraryDatasetDatasetAssociation.get( kwd.get( 'set_lda_id' ) )
library_dataset.library_dataset_dataset_association = target_lda
trans.app.model.flush()
msg = 'The current version of this library dataset has been updated to be %s' % target_lda.name
elif params.get( 'update_roles_button', False ):
# The user clicked the Save button on the 'Edit permissions and role associations' form
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
trans.app.security_agent.set_all_library_permissions( library_dataset, permissions )
library_dataset.refresh()
msg = 'Permissions and roles have been updated for library dataset %s' % library_dataset.name
return trans.fill_template( "/admin/library/manage_library_dataset.mako",
library_dataset=library_dataset,
library_id=library_id,
msg=msg,
messagetype=messagetype )
if action == 'information':
if params.get( 'edit_attributes_button', False ):
old_name = library_dataset.name
new_name = util.restore_text( name )
new_info = util.restore_text( info )
if not new_name:
msg = 'Enter a valid name'
messagetype = 'error'
else:
library_dataset.name = new_name
library_dataset.info = new_info
library_dataset.flush()
msg = "Dataset '%s' has been renamed to '%s'" % ( old_name, new_name )
messagetype = 'done'
return trans.fill_template( '/admin/library/library_dataset_info.mako',
library_dataset=library_dataset,
library_id=library_id,
msg=msg,
messagetype=messagetype )
elif action == 'versions':
if params.get( 'change_version_button', False ):
target_lda = trans.app.model.LibraryDatasetDatasetAssociation.get( kwd.get( 'set_lda_id' ) )
library_dataset.library_dataset_dataset_association = target_lda
trans.app.model.flush()
msg = 'The current version of this library dataset has been updated to be %s' % target_lda.name
return trans.fill_template( '/admin/library/library_dataset_versions.mako',
library_dataset=library_dataset,
library_id=library_id,
msg=msg,
messagetype=messagetype )
elif action == 'permissions':
if params.get( 'update_roles_button', False ):
# The user clicked the Save button on the 'Edit permissions and role associations' form
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
# Set the LIBRARY permissions on the LibraryDataset
# NOTE: the LibraryDataset and LibraryDatasetDatasetAssociation will be set with the same permissions
trans.app.security_agent.set_all_library_permissions( library_dataset, permissions )
library_dataset.refresh()
# Set the LIBRARY permissions on the LibraryDatasetDatasetAssociation
trans.app.security_agent.set_all_library_permissions( library_dataset.library_dataset_dataset_association, permissions )
library_dataset.library_dataset_dataset_association.refresh()
msg = 'Permissions and roles have been updated for library dataset %s' % library_dataset.name
return trans.fill_template( '/admin/library/library_dataset_permissions.mako',
library_dataset=library_dataset,
library_id=library_id,
msg=msg,
messagetype=messagetype )
@web.expose
@web.require_admin
def library_dataset_dataset_association( self, trans, id=None, name="Unnamed", info='no info',
extension=None, folder_id=None, library_id=None, **kwd ):
def library_dataset_dataset_association( self, trans, id=None, name="Unnamed", info='no info', folder_id=None, library_id=None, **kwd ):
params = util.Params( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
@@ -1151,14 +1184,20 @@ class Admin( BaseController ):
last_used_build = dbkey[0]
else:
last_used_build = dbkey
if folder_id and not last_used_build:
if folder_id:
folder = trans.app.model.LibraryFolder.get( folder_id )
else:
folder = None
if folder and not last_used_build:
last_used_build = folder.genome_build
data_files = []
try:
replace_dataset = trans.app.model.LibraryDataset.get( params.get( 'replace_id', None ) )
except:
replace_dataset = None
# Let's not overwrite the imported datatypes module with the variable datatypes?
# The built-in 'id' is overwritten in lots of places as well
ldatatypes = [ x for x in trans.app.datatypes_registry.datatypes_by_extension.iterkeys() ]
ldatatypes.sort()
if params.get( 'new_dataset_button', False ):
created_ldda_ids = upload_dataset( trans,
controller='admin',
@@ -1169,23 +1208,19 @@ class Admin( BaseController ):
total_added = len( created_ldda_ids.split( ',' ) )
msg = "%i new datasets added to the library ( each is selected below ). " % total_added
msg += "Click the Go button at the bottom of this page to edit the permissions on these datasets if necessary."
trans.response.send_redirect( web.url_for( controller='admin',
action='browse_library',
id=library_id,
created_ldda_ids=created_ldda_ids,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
messagetype='done'
else:
msg = "Upload failed"
trans.response.send_redirect( web.url_for( controller='admin',
action='browse_library',
id=library_id,
created_ldda_ids=created_ldda_ids,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
messagetype='error'
trans.response.send_redirect( web.url_for( controller='admin',
action='browse_library',
id=library_id,
created_ldda_ids=created_ldda_ids,
msg=util.sanitize_text( msg ),
messagetype=messagetype ) )
elif not id or replace_dataset:
# No dataset(s) specified, so display the upload form.
# Send list of data formats to the form so the "extension" select list can be populated dynamically
# No dataset(s) specified, so display the upload form. Send list of data formats to the form
# so the "extension" select list can be populated dynamically
file_formats = trans.app.datatypes_registry.upload_file_formats
# Send list of genome builds to the form so the "dbkey" select list can be populated dynamically
def get_dbkey_options( last_used_build ):
@@ -1194,7 +1229,7 @@ class Admin( BaseController ):
dbkeys = get_dbkey_options( last_used_build )
# Send list of roles to the form so the dataset can be associated with 1 or more of them.
roles = trans.app.model.Role.filter( trans.app.model.Role.table.c.deleted==False ).order_by( trans.app.model.Role.c.name ).all()
# Send the current history to enable importing datasets from history to library
# Send the current history to the form to enable importing datasets from history to library
history = trans.get_history()
history.refresh()
return trans.fill_template( '/admin/library/new_dataset.mako',
@@ -1236,35 +1271,38 @@ class Admin( BaseController ):
for k, v in trans.app.model.Dataset.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
# Set the DATASET permissions on the Dataset
trans.app.security_agent.set_all_dataset_permissions( ldda.dataset, permissions )
# Set/display library security info
ldda.dataset.refresh()
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
# Set the LIBRARY permissions on the LibraryDataset
# NOTE: the LibraryDataset and LibraryDatasetDatasetAssociation will be set with the same permissions
trans.app.security_agent.set_all_library_permissions( ldda.library_dataset, permissions )
ldda.library_dataset.refresh()
# Set the LIBRARY permissions on the LibraryDatasetDatasetAssociation
trans.app.security_agent.set_all_library_permissions( ldda, permissions )
ldda.dataset.refresh()
ldda.refresh()
msg = "Permissions updated for dataset '%s'" % ldda.name
return trans.response.send_redirect( web.url_for( controller='admin',
action='library_dataset_dataset_association',
id=id,
permissions=True,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( '/admin/library/ldda_permissions.mako', ldda=ldda, library_id=library_id, msg=msg, messagetype=messagetype )
return trans.fill_template( '/admin/library/ldda_permissions.mako',
ldda=ldda,
library_id=library_id,
msg=msg,
messagetype=messagetype )
elif action == 'information':
if params.get( 'change', False ):
# The user clicked the Save button on the 'Change data type' form
trans.app.datatypes_registry.change_datatype( ldda, params.datatype )
trans.app.model.flush()
msg = "Data type changed for dataset '%s'" % ldda.name
return trans.response.send_redirect( web.url_for( controller='admin',
action='library_dataset_dataset_association',
id=id,
library_id=library_id,
information=True,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
msg = "Data type changed for library dataset '%s'" % ldda.name
return trans.fill_template( "/admin/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
elif params.get( 'save', False ):
# The user clicked the Save button on the 'Edit Attributes' form
ldda.name = name
@@ -1282,14 +1320,13 @@ class Admin( BaseController ):
ldda.metadata.dbkey = dbkey
ldda.datatype.after_edit( ldda )
trans.app.model.flush()
msg = 'Attributes updated for dataset %s' % ldda.name
return trans.response.send_redirect( web.url_for( controller='admin',
action='library_dataset_dataset_association',
id=id,
library_id=library_id,
information=True,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
msg = 'Attributes updated for library dataset %s' % ldda.name
return trans.fill_template( "/admin/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
elif params.get( 'detect', False ):
# The user clicked the Auto-detect button on the 'Edit Attributes' form
for name, spec in ldda.datatype.metadata_spec.items():
@@ -1300,25 +1337,25 @@ class Admin( BaseController ):
ldda.datatype.set_meta( ldda )
ldda.datatype.after_edit( ldda )
trans.app.model.flush()
msg = 'Attributes updated for dataset %s' % ldda.name
return trans.response.send_redirect( web.url_for( controller='admin',
action='library_dataset_dataset_association',
id=id,
library_id=library_id,
information=True,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
msg = 'Attributes updated for library dataset %s' % ldda.name
return trans.fill_template( "/admin/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
elif params.get( 'delete', False ):
# TODO: need to revamp the way we remove datasets from disk.
# The user selected the "Remove this dataset from the library" pop-up menu option
ldda.deleted = True
ldda.flush()
msg = 'Dataset %s has been removed from this library' % ldda.name
trans.response.send_redirect( web.url_for( controller='admin',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( "/admin/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
ldda.datatype.before_edit( ldda )
if "dbkey" in ldda.datatype.metadata_spec and not ldda.metadata.dbkey:
# Copy dbkey into metadata, for backwards compatability
@@ -1327,10 +1364,6 @@ class Admin( BaseController ):
# case it resorts to the old dbkey. Setting the dbkey
# sets it properly in the metadata
ldda.metadata.dbkey = ldda.dbkey
# let's not overwrite the imported datatypes module with the variable datatypes?
### the built-in 'id' is overwritten in lots of places as well
ldatatypes = [x for x in trans.app.datatypes_registry.datatypes_by_extension.iterkeys()]
ldatatypes.sort()
return trans.fill_template( "/admin/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
@@ -1359,14 +1392,26 @@ class Admin( BaseController ):
messagetype='error' ) )
if action == 'permissions':
if params.get( 'update_roles_button', False ):
#p = util.Params( kwd )
permissions = {}
for k, v in trans.app.model.Dataset.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
for ldda in lddas:
# Set the DATASET permissions on the Dataset
trans.app.security_agent.set_all_dataset_permissions( ldda.dataset, permissions )
ldda.dataset.refresh()
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
for ldda in lddas:
# Set the LIBRARY permissions on the LibraryDataset
# NOTE: the LibraryDataset and LibraryDatasetDatasetAssociation will be set with the same permissions
trans.app.security_agent.set_all_library_permissions( ldda.library_dataset, permissions )
ldda.library_dataset.refresh()
# Set the LIBRARY permissions on the LibraryDatasetDatasetAssociation
trans.app.security_agent.set_all_library_permissions( ldda, permissions )
ldda.refresh()
msg = 'Permissions and roles have been updated on %d datasets' % len( lddas )
return trans.fill_template( "/admin/library/ldda_permissions.mako",
ldda=lddas,
@@ -1374,6 +1419,9 @@ class Admin( BaseController ):
msg=msg,
messagetype=messagetype )
# Ensure that the permissions across all datasets are identical. Otherwise, we can't update together.
# TODO: this doesn't really work as it should - we need to check permissions on associated
# LibraryDatasetDatasetAssociation and LibraryDataset as well. Improvement can also be made in the way
# we are checking...
tmp = []
for ldda in lddas:
perms = trans.app.security_agent.get_dataset_permissions( ldda.dataset )
@@ -1558,6 +1606,7 @@ class Admin( BaseController ):
@web.expose
@web.require_admin
def library_item_info( self, trans, do_action='display', id=None, library_item_id=None, library_item_type=None, library_id=None, **kwd ):
# TODO: this needs to be cleaned up...
params = util.Params( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
@@ -1595,54 +1644,49 @@ class Admin( BaseController ):
messagetype=messagetype )
elif do_action == 'new_info':
if library_item:
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_ADD,
library_item=library_item ):
if params.get( 'create_new_info_button', False ):
user = trans.get_user()
#create new info then send back to make more
library_item_info_template_id = params.get( 'library_item_info_template_id', None )
library_item_info_template = trans.app.model.LibraryItemInfoTemplate.get( library_item_info_template_id )
library_item_info = trans.app.model.LibraryItemInfo()
library_item_info.library_item_info_template = library_item_info_template
library_item_info.user = user
library_item_info.flush()
trans.app.security_agent.copy_library_permissions( library_item_info_template, library_item_info, user=user )
for template_element in library_item_info_template.elements:
info_element_value = params.get( "info_element_%s_%s" % ( library_item_info_template.id, template_element.id), None )
info_element = trans.app.model.LibraryItemInfoElement()
info_element.contents = info_element_value
info_element.library_item_info_template_element = template_element
info_element.library_item_info = library_item_info
info_element.flush()
info_association_class = None
for item_class, permission_class, info_association_class in trans.app.security_agent.library_item_assocs:
if isinstance( library_item, item_class ):
break
if info_association_class:
library_item_info_association = info_association_class()
library_item_info_association.set_library_item( library_item )
library_item_info_association.library_item_info = library_item_info
library_item_info_association.user = user
library_item_info_association.flush()
else:
raise 'Invalid class (%s) specified for library_item (%s)' % ( library_item.__class__, library_item.__class__.__name__ )
# TODO: make sure we don't need to set permissions on the association object.
msg = 'The information has been saved. You can add more information if necessary.'
return trans.response.send_redirect( web.url_for( controller='admin',
action=library_item_type,
id=library_item.id,
library_id=library_id,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( "/admin/library/new_info.mako",
library_item=library_item,
library_item_type=library_item_type,
library_id=library_id,
msg=msg,
messagetype=messagetype )
else:
return trans.show_error_message( "You do not have permission to add information to this library item." )
if params.get( 'create_new_info_button', False ):
user = trans.get_user()
#create new info then send back to make more
library_item_info_template_id = params.get( 'library_item_info_template_id', None )
library_item_info_template = trans.app.model.LibraryItemInfoTemplate.get( library_item_info_template_id )
library_item_info = trans.app.model.LibraryItemInfo()
library_item_info.library_item_info_template = library_item_info_template
library_item_info.user = user
library_item_info.flush()
trans.app.security_agent.copy_library_permissions( library_item_info_template, library_item_info, user=user )
for template_element in library_item_info_template.elements:
info_element_value = params.get( "info_element_%s_%s" % ( library_item_info_template.id, template_element.id), None )
info_element = trans.app.model.LibraryItemInfoElement()
info_element.contents = info_element_value
info_element.library_item_info_template_element = template_element
info_element.library_item_info = library_item_info
info_element.flush()
info_association_class = None
for item_class, permission_class, info_association_class in trans.app.security_agent.library_item_assocs:
if isinstance( library_item, item_class ):
break
if info_association_class:
library_item_info_association = info_association_class()
library_item_info_association.set_library_item( library_item )
library_item_info_association.library_item_info = library_item_info
library_item_info_association.user = user
library_item_info_association.flush()
else:
raise 'Invalid class (%s) specified for library_item (%s)' % ( library_item.__class__, library_item.__class__.__name__ )
# TODO: make sure we don't need to set permissions on the association object.
msg = 'The information has been saved. You can add more information if necessary.'
return trans.response.send_redirect( web.url_for( controller='admin',
action=library_item_type,
id=library_item.id,
library_id=library_id,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( "/admin/library/new_info.mako",
library_item=library_item,
library_item_type=library_item_type,
library_id=library_id,
msg=msg,
messagetype=messagetype )
# TODO: add more functionality -> user's should be able to edit/delete, etc, and create/delete and edit templates
return trans.fill_template( "/admin/library/display_info.mako",
item_info=item_info,
+4
View File
@@ -287,6 +287,10 @@ def add_file( trans, file_obj, name, extension, dbkey, roles, info='no info', sp
library_dataset = trans.app.model.LibraryDataset( name=name, info=info, extension=data_type, dbkey=dbkey )
library_dataset.flush()
if permission_source:
# permission_source is a LibraryFolder or a LibraryDataset
# TODO: we need to ensure we copy permissions on all 3 levels:
# LibraryDatasetDatasetAssociation, LibraryDataset, and Dataset
# This is currently not being done and must be fixed ASAP!!
trans.app.security_agent.copy_library_permissions( permission_source, library_dataset, user=trans.get_user() )
ldda = trans.app.model.LibraryDatasetDatasetAssociation( name=name,
info=info,
+418 -236
View File
@@ -53,6 +53,72 @@ class Library( BaseController ):
msg=msg,
messagetype=messagetype )
@web.expose
def library( self, trans, id=None, **kwd ):
params = util.Params( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
if not id:
msg = "You must specify a library."
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_libraries',
msg=util.sanitize_text( msg ),
messagetype='error' ) )
library = trans.app.model.Library.get( int( id ) )
if not library:
msg = "Invalid library id ( %s ) specified." % str( id )
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_libraries',
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if params.get( 'delete', False ):
action = 'delete'
elif params.get( 'permissions', False ):
action = 'permissions'
else:
# 'information' is the default
action = 'information'
if action == 'information':
if params.get( 'rename_library_button', False ):
old_name = library.name
new_name = util.restore_text( params.name )
new_description = util.restore_text( params.description )
if not new_name:
msg = 'Enter a valid name'
return trans.fill_template( '/library/library_info.mako', library=library, msg=msg, messagetype='error' )
else:
if params.get( 'root_folder', False ):
root_folder = library.root_folder
root_folder.name = new_name
root_folder.flush()
library.name = new_name
library.description = new_description
library.flush()
msg = "Library '%s' has been renamed to '%s'" % ( old_name, new_name )
return trans.response.send_redirect( web.url_for( controller='library',
action='library',
id=id,
information=True,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( '/library/library_info.mako', library=library, msg=msg, messagetype=messagetype )
elif action == 'permissions':
if params.get( 'update_roles_button', False ):
# The user clicked the Save button on the 'Associate With Roles' form
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
trans.app.security_agent.set_all_library_permissions( library, permissions )
library.refresh()
msg = "Permissions updated for library '%s'" % library.name
return trans.response.send_redirect( web.url_for( controller='library',
action='library',
id=id,
permissions=True,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( '/library/manage_library_permissions.mako', library=library, msg=msg, messagetype=messagetype )
@web.expose
def datasets( self, trans, ldda_ids=[], library_id=None, **kwd ):
# This method is used by the select list labeled "Perform action on selected datasets"
# on the analysis library browser.
@@ -214,8 +280,98 @@ class Library( BaseController ):
msg=msg,
messagetype='error' ) )
@web.expose
def library_dataset_dataset_association( self, trans, id=None, name=None, info=None, folder_id=None,
replace_id=None, refer_id=None, library_id=None, **kwd ):
def library_dataset( self, trans, id, name=None, info=None, library_id=None, **kwd ):
params = util.Params( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
if params.get( 'permissions', False ):
action = 'permissions'
elif params.get( 'versions', False ):
action = 'versions'
else:
# 'information' will be the default
action = 'information'
library_dataset = trans.app.model.LibraryDataset.get( id )
if not library_dataset:
msg = "Invalid library dataset specified, id: %s" %str( id )
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if action == 'information':
if params.get( 'edit_attributes_button', False ):
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
library_item=library_dataset ):
if params.get( 'edit_attributes_button', False ):
old_name = library_dataset.name
new_name = util.restore_text( name )
new_info = util.restore_text( info )
if not new_name:
msg = 'Enter a valid name'
messagetype = 'error'
else:
library_dataset.name = new_name
library_dataset.info = new_info
library_dataset.flush()
msg = "Dataset '%s' has been renamed to '%s'" % ( old_name, new_name )
messagetype = 'done'
else:
msg = "You are not authorized to change the attributes of this dataset"
messagetype = "error"
return trans.fill_template( '/library/library_dataset_info.mako',
library_dataset=library_dataset,
library_id=library_id,
msg=msg,
messagetype=messagetype )
elif action == 'versions':
if params.get( 'change_version_button', False ):
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
library_item=library_dataset ):
target_lda = trans.app.model.LibraryDatasetDatasetAssociation.get( kwd.get( 'set_lda_id' ) )
library_dataset.library_dataset_dataset_association = target_lda
trans.app.model.flush()
msg = 'The current version of this library dataset has been updated to be %s' % target_lda.name
messagetype = 'done'
else:
msg = "You are not authorized to change the versions of this dataset"
messagetype = "error"
return trans.fill_template( '/library/library_dataset_versions.mako',
library_dataset=library_dataset,
library_id=library_id,
msg=msg,
messagetype=messagetype )
elif action == 'permissions':
if params.get( 'update_roles_button', False ):
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MANAGE,
library_item=library_dataset ):
# The user clicked the Save button on the 'Associate With Roles' form
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
# Set the LIBRARY permissions on the LibraryDataset
# NOTE: the LibraryDataset and LibraryDatasetDatasetAssociation will be set with the same permissions
trans.app.security_agent.set_all_library_permissions( library_dataset, permissions )
library_dataset.refresh()
# Set the LIBRARY permissions on the LibraryDatasetDatasetAssociation
trans.app.security_agent.set_all_library_permissions( library_dataset.library_dataset_dataset_association, permissions )
library_dataset.library_dataset_dataset_association.refresh()
msg = 'Permissions and roles have been updated for library dataset %s' % library_dataset.name
messagetype = 'done'
else:
msg = "You are not authorized to managed the permissions of this dataset"
messagetype = "error"
return trans.fill_template( '/library/library_dataset_permissions.mako',
library_dataset=library_dataset,
library_id=library_id,
msg=msg,
messagetype=messagetype )
@web.expose
def library_dataset_dataset_association( self, trans, id=None, name="Unnamed", info='no info', folder_id=None, library_id=None, **kwd ):
params = util.Params( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
@@ -227,59 +383,184 @@ class Library( BaseController ):
if not last_used_build:
last_used_build = folder.genome_build
permission_source = folder
# permission_source is a LibraryFolder or a LibraryDataset
# TODO: we need to ensure we copy permissions on all 3 levels:
# LibraryDatasetDatasetAssociation, LibraryDataset, and Dataset
# This is currently not being done and must be fixed ASAP!!
try:
replace_dataset = trans.app.model.LibraryDataset.get( params.get( 'replace_id', None ) )
if not last_used_build:
last_used_build = replace_dataset.library_dataset_dataset_association.dbkey
permission_source = replace_dataset
# permission_source is a LibraryFolder or a LibraryDataset
# TODO: we need to ensure we copy permissions on all 3 levels:
# LibraryDatasetDatasetAssociation, LibraryDataset, and Dataset
# This is currently not being done and must be fixed ASAP!!
except:
replace_dataset = None
# Let's not overwrite the imported datatypes module with the variable datatypes?
# The built-in 'id' is overwritten in lots of places as well
ldatatypes = [ x for x in trans.app.datatypes_registry.datatypes_by_extension.iterkeys() ]
ldatatypes.sort()
if id:
if params.get( 'permissions', False ):
action = 'permissions'
else:
# 'information' will be the default
action = 'information'
# The user is updating the permissions on 1 or more datasets
if id.count( ',' ):
ids = id.split( ',' )
id = None
else:
ids = None
if id:
# id specified, display attributes form
ldda = trans.app.model.LibraryDatasetDatasetAssociation.get( id )
if not ldda:
msg = "Invalid LibraryDatasetDatasetAssociation specified, id: %s" % str( id )
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if action == 'permissions':
if params.get( 'update_roles_button', False ):
# The user clicked the Save button on the 'Associate With Roles' form
else:
ids = None
if id:
# ldda_id specified, display attributes form
ldda = trans.app.model.LibraryDatasetDatasetAssociation.get( id )
if not ldda:
msg = "Invalid LibraryDatasetDatasetAssociation specified, id: %s" % str( id )
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if action == 'permissions':
if params.get( 'update_roles_button', False ):
# The user clicked the Save button on the 'Associate With Roles' form
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MANAGE,
library_item=ldda ) and \
trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MANAGE,
library_item=ldda.library_dataset ) and \
trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.DATASET_MANAGE_PERMISSIONS,
dataset=ldda.dataset ):
permissions = {}
for k, v in trans.app.model.Dataset.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
# Set the DATASET permissions on the Dataset
trans.app.security_agent.set_all_dataset_permissions( ldda.dataset, permissions )
# Set/display library security info
ldda.dataset.refresh()
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ]
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
# Set the LIBRARY permissions on the LibraryDataset
# NOTE: the LibraryDataset and LibraryDatasetDatasetAssociation will be set with the same permissions
trans.app.security_agent.set_all_library_permissions( ldda.library_dataset, permissions )
ldda.library_dataset.refresh()
# Set the LIBRARY permissions on the LibraryDatasetDatasetAssociation
trans.app.security_agent.set_all_library_permissions( ldda, permissions )
ldda.dataset.refresh()
ldda.refresh()
msg = "Permissions updated for dataset '%s'" % ldda.name
return trans.response.send_redirect( web.url_for( controller='library',
action='library_dataset_dataset_association',
id=id,
library_id=library_id,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( '/library/ldda_permissions.mako', ldda=ldda, library_id=library_id, msg=msg, messagetype=messagetype )
elif action == 'information':
messagetype = 'done'
else:
msg = "You are not authorized to change the permissions of dataset '%s'" % ldda.name
messagetype = 'error'
return trans.fill_template( '/library/ldda_permissions.mako',
ldda=ldda,
library_id=library_id,
msg=msg,
messagetype=messagetype )
elif action == 'information':
if params.get( 'change', False ):
# The user clicked the Save button on the 'Change data type' form
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
library_item=ldda ):
trans.app.datatypes_registry.change_datatype( ldda, params.datatype )
trans.app.model.flush()
msg = "Data type changed for library dataset '%s'" % ldda.name
messagetype = 'done'
else:
msg = "You are not authorized to change the data type of dataset '%s'" % ldda.name
messagetype = 'error'
return trans.fill_template( "/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
elif params.get( 'save', False ):
# The user clicked the Save button on the 'Edit Attributes' form
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
library_item=ldda ):
ldda.name = name
ldda.info = info
# The following for loop will save all metadata_spec items
for name, spec in ldda.datatype.metadata_spec.items():
if spec.get("readonly"):
continue
optional = params.get( "is_" + name, None )
if optional and optional == 'true':
# optional element... == 'true' actually means it is NOT checked (and therefore ommitted)
setattr( ldda.metadata, name, None )
else:
setattr( ldda.metadata, name, spec.unwrap( params.get ( name, None ) ) )
ldda.metadata.dbkey = dbkey
ldda.datatype.after_edit( ldda )
trans.app.model.flush()
msg = 'Attributes updated for library dataset %s' % ldda.name
messagetype = 'done'
else:
msg = "you are not authorized to edit the attributes of dataset '%s'" % ldda.name
messagetype = 'error'
return trans.fill_template( "/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
elif params.get( 'detect', False ):
# The user clicked the Auto-detect button on the 'Edit Attributes' form
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
library_item=ldda ):
for name, spec in ldda.datatype.metadata_spec.items():
# We need to be careful about the attributes we are resetting
if name not in [ 'name', 'info', 'dbkey' ]:
if spec.get( 'default' ):
setattr( ldda.metadata, name, spec.unwrap( spec.get( 'default' ) ) )
ldda.datatype.set_meta( ldda )
ldda.datatype.after_edit( ldda )
trans.app.model.flush()
msg = 'Attributes updated for library dataset %s' % ldda.name
messagetype = 'done'
else:
msg = "you are not authorized to edit the attributes of dataset '%s'" % ldda.name
messagetype = 'error'
return trans.fill_template( "/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
elif params.get( 'delete', False ):
# TODO: need to revamp the way we remove datasets from disk.
# The user selected the "Remove this dataset from the library" pop-up menu option
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
library_item=folder ):
ldda.deleted = True
ldda.flush()
msg = 'Dataset %s has been removed from this library' % ldda.name
messagetype = 'done'
else:
msg = "you are not authorized to delete dataset '%s'" % ldda.name
messagetype = 'error'
return trans.fill_template( "/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
library_item=ldda ):
ldda.datatype.before_edit( ldda )
if "dbkey" in ldda.datatype.metadata_spec and not ldda.metadata.dbkey:
# Copy dbkey into metadata, for backwards compatability
@@ -288,72 +569,108 @@ class Library( BaseController ):
# case it resorts to the old dbkey. Setting the dbkey
# sets it properly in the metadata
ldda.metadata.dbkey = ldda.dbkey
# let's not overwrite the imported datatypes module with the variable datatypes?
### the built-in 'id' is overwritten in lots of places as well
ldatatypes = [x for x in trans.app.datatypes_registry.datatypes_by_extension.iterkeys()]
ldatatypes.sort()
return trans.fill_template( "/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
elif ids:
# Multiple ids specfied, display permission form, permissions will be updated for all simultaneously.
lddas = []
for id in [ int( id ) for id in ids ]:
ldda = trans.app.model.LibraryDatasetDatasetAssociation.get( id )
if ldda is None:
msg = 'You specified an invalid LibraryDatasetDatasetAssociation id: %s' %str( id )
trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
lddas.append( ldda )
if len( lddas ) < 2:
msg = 'You must specify at least two datasets on which to modify permissions, ids you sent: %s' % str( ids )
return trans.fill_template( "/library/ldda_info.mako",
ldda=ldda,
library_id=library_id,
datatypes=ldatatypes,
msg=msg,
messagetype=messagetype )
elif ids:
# Multiple ids specfied, display permission form, permissions will be updated for all simultaneously.
lddas = []
for id in [ int( id ) for id in ids ]:
ldda = trans.app.model.LibraryDatasetDatasetAssociation.get( id )
if ldda is None:
msg = 'You specified an invalid LibraryDatasetDatasetAssociation id: %s' %str( id )
trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if action == 'permissions':
if params.get( 'update_roles_button', False ):
lddas.append( ldda )
if len( lddas ) < 2:
msg = 'You must specify at least two datasets on which to modify permissions, ids you sent: %s' % str( ids )
trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if action == 'permissions':
if params.get( 'update_roles_button', False ):
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MANAGE,
library_item=ldda ) and \
trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MANAGE,
library_item=ldda.library_dataset ) and \
trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.DATASET_MANAGE_PERMISSIONS,
dataset=ldda.dataset ):
permissions = {}
for k, v in trans.app.model.Dataset.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
for ldda in lddas:
# Set the DATASET permissions on the Dataset
trans.app.security_agent.set_all_dataset_permissions( ldda.dataset, permissions )
ldda.dataset.refresh()
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
for ldda in lddas:
# Set the LIBRARY permissions on the LibraryDataset
# NOTE: the LibraryDataset and LibraryDatasetDatasetAssociation will be set with the same permissions
trans.app.security_agent.set_all_library_permissions( ldda.library_dataset, permissions )
ldda.library_dataset.refresh()
# Set the LIBRARY permissions on the LibraryDatasetDatasetAssociation
trans.app.security_agent.set_all_library_permissions( ldda, permissions )
ldda.refresh()
msg = 'Permissions and roles have been updated on %d datasets' % len( lddas )
return trans.fill_template( "/library/ldda_permissions.mako",
ldda=lddas,
library_id=library_id,
msg=msg,
messagetype=messagetype )
# Ensure that the permissions across all datasets are identical. Otherwise, we can't update together.
tmp = []
for ldda in lddas:
perms = trans.app.security_agent.get_dataset_permissions( ldda.dataset )
if perms not in tmp:
tmp.append( perms )
if len( tmp ) != 1:
msg = 'The datasets you selected do not have identical permissions, so they can not be updated together'
trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
else:
messagetype = 'done'
else:
msg = "You are not authorized to change the permissions of dataset '%s'" % ldda.name
messagetype = 'error'
return trans.fill_template( "/library/ldda_permissions.mako",
ldda=lddas,
library_id=library_id,
msg=msg,
messagetype=messagetype )
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MANAGE,
library_item=ldda ) and \
trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MANAGE,
library_item=ldda.library_dataset ) and \
trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.DATASET_MANAGE_PERMISSIONS,
dataset=ldda.dataset ):
# Ensure that the permissions across all datasets are identical. Otherwise, we can't update together.
# TODO: this doesn't really work as it should - we need to check permissions on associated
# LibraryDatasetDatasetAssociation and LibraryDataset as well. Improvement can also be made in the way
# we are checking...
tmp = []
for ldda in lddas:
perms = trans.app.security_agent.get_dataset_permissions( ldda.dataset )
if perms not in tmp:
tmp.append( perms )
if len( tmp ) != 1:
msg = 'The datasets you selected do not have identical permissions, so they can not be updated together'
trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
else:
msg = "You are not authorized to change the permissions of dataset '%s'" % ldda.name
messagetype = 'error'
return trans.fill_template( "/library/ldda_permissions.mako",
ldda=lddas,
library_id=library_id,
msg=msg,
messagetype=messagetype )
if not folder and not replace_dataset:
msg = "Invalid library target specified (LibraryFolder id: %s, LibraryDataset id: %s)" % ( str( folder_id ), str( replace_id ) )
msg = "Invalid library target specified ( LibraryFolder id: %s, LibraryDataset id: %s )" % ( str( folder_id ), str( replace_id ) )
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
@@ -399,7 +716,7 @@ class Library( BaseController ):
created_ldda_ids=created_ldda_ids,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
elif params.get( "add_dataset_from_history_button", False):
elif params.get( "add_dataset_from_history_button", False ):
# See if the current history is empty
history = trans.get_history()
history.refresh()
@@ -447,100 +764,31 @@ class Library( BaseController ):
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
else:
# No dataset(s) specified, display upload form
file_formats = trans.app.datatypes_registry.upload_file_formats
# Send list of genome builds to the form so the "dbkey" select list can be populated dynamically
def get_dbkey_options( last_used_build ):
for dbkey, build_name in util.dbnames:
yield build_name, dbkey, ( dbkey==last_used_build )
dbkeys = get_dbkey_options( last_used_build )
# Send list of roles to the form so the dataset can be associated with 1 or more of them.
roles = trans.app.model.Role.filter( trans.app.model.Role.table.c.deleted==False ).order_by( trans.app.model.Role.c.name ).all()
msg = 'Select at least one dataset from the list'
return trans.fill_template( "/library/new_dataset.mako",
history=history,
library_id=library_id,
folder_id=folder_id,
file_formats=file_formats,
dbkeys=dbkeys,
last_used_build=last_used_build,
roles=roles,
replace_dataset=replace_dataset,
msg=msg,
messagetype='error' )
#copied...
def get_dbkey_options( last_used_build ):
for dbkey, build_name in util.dbnames:
yield build_name, dbkey, ( dbkey==last_used_build )
return trans.fill_template( "/library/new_dataset.mako",
library_id=library_id,
folder_id=folder_id,
replace_dataset=replace_dataset,
file_formats=trans.app.datatypes_registry.upload_file_formats,
dbkeys=get_dbkey_options( '?' ),
last_used_build=last_used_build,
msg=msg,
messagetype=messagetype )
@web.expose
def library_dataset( self, trans, id, name=None, info=None, refer_id=None, library_id=None, **kwd ):
params = util.Params( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
library_dataset = trans.app.model.LibraryDataset.get( id )
if not library_dataset:
msg = "Invalid library dataset specified, id: %s" %str( id )
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if refer_id:
refered_lda = trans.app.model.LibraryDatasetDatasetAssociation.get( refer_id )
else:
refered_lda=None
if params.get( 'save', False ):
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
library_item=library_dataset ):
library_dataset.name = name
library_dataset.info = info
target_lda = trans.app.model.LibraryDatasetDatasetAssociation.get( params.get( 'set_lda_id' ) )
library_dataset.library_dataset_dataset_association = target_lda
trans.app.model.flush()
msg = 'Attributes updated for library dataset %s' % library_dataset.name
messagetype = 'done'
else:
msg = "You are not authorized to changed the attributes of this dataset"
messagetype = "error"
return trans.response.send_redirect( web.url_for( controller='library',
action='library_dataset',
id=id,
library_id=library_id,
msg=util.sanitize_text( msg ),
messagetype=messagetype ) )
elif 'update_roles_button' in kwd:
if trans.app.security_agent.allow_action( trans.user,
trans.app.security_agent.permitted_actions.LIBRARY_MANAGE,
library_item=library_dataset ):
# The user clicked the Save button on the 'Associate With Roles' form
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
trans.app.security_agent.set_all_library_permissions( library_dataset, permissions )
library_dataset.refresh()
msg = 'Permissions updated for library dataset %s' % library_dataset.name
else:
msg = "Permission Denied"
messagetype = "error"
return trans.fill_template( "/library/manage_library_dataset.mako",
library_dataset=library_dataset,
refered_lda=refered_lda,
library_id=library_id,
msg=msg,
messagetype=messagetype )
if not id or replace_dataset:
# No dataset(s) specified, so display the upload form. Send list of data formats to the form
# so the "extension" select list can be populated dynamically
file_formats = trans.app.datatypes_registry.upload_file_formats
# Send list of genome builds to the form so the "dbkey" select list can be populated dynamically
def get_dbkey_options( last_used_build ):
for dbkey, build_name in util.dbnames:
yield build_name, dbkey, ( dbkey==last_used_build )
dbkeys = get_dbkey_options( last_used_build )
# Send list of roles to the form so the dataset can be associated with 1 or more of them.
roles = trans.app.model.Role.filter( trans.app.model.Role.table.c.deleted==False ).order_by( trans.app.model.Role.c.name ).all()
# Send the current history to the form to enable importing datasets from history to library
history = trans.get_history()
history.refresh()
return trans.fill_template( '/library/new_dataset.mako',
library_id=library_id,
folder_id=folder_id,
file_formats=file_formats,
dbkeys=dbkeys,
last_used_build=last_used_build,
roles=roles,
history=history,
msg=msg,
messagetype=messagetype,
replace_dataset=replace_dataset )
@web.expose
def folder( self, trans, id, library_id, **kwd ):
params = util.Params( kwd )
@@ -663,72 +911,6 @@ class Library( BaseController ):
msg=msg,
messagetype=messagetype )
@web.expose
def library( self, trans, id=None, **kwd ):
params = util.Params( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
if not id:
msg = "You must specify a library."
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_libraries',
msg=util.sanitize_text( msg ),
messagetype='error' ) )
library = trans.app.model.Library.get( int( id ) )
if not library:
msg = "Invalid library id ( %s ) specified." % str( id )
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_libraries',
msg=util.sanitize_text( msg ),
messagetype='error' ) )
if params.get( 'delete', False ):
action = 'delete'
elif params.get( 'permissions', False ):
action = 'permissions'
else:
# 'information' is the default
action = 'information'
if action == 'information':
if params.get( 'rename_library_button', False ):
old_name = library.name
new_name = util.restore_text( params.name )
new_description = util.restore_text( params.description )
if not new_name:
msg = 'Enter a valid name'
return trans.fill_template( '/library/library_info.mako', library=library, msg=msg, messagetype='error' )
else:
if params.get( 'root_folder', False ):
root_folder = library.root_folder
root_folder.name = new_name
root_folder.flush()
library.name = new_name
library.description = new_description
library.flush()
msg = "Library '%s' has been renamed to '%s'" % ( old_name, new_name )
return trans.response.send_redirect( web.url_for( controller='library',
action='library',
id=id,
information=True,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( '/library/library_info.mako', library=library, msg=msg, messagetype=messagetype )
elif action == 'permissions':
if params.get( 'update_roles_button', False ):
# The user clicked the Save button on the 'Associate With Roles' form
permissions = {}
for k, v in trans.app.model.Library.permitted_actions.items():
in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( params.get( k + '_in', [] ) ) ]
permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles
trans.app.security_agent.set_all_library_permissions( library, permissions )
library.refresh()
msg = "Permissions updated for library '%s'" % library.name
return trans.response.send_redirect( web.url_for( controller='library',
action='library',
id=id,
permissions=True,
msg=util.sanitize_text( msg ),
messagetype='done' ) )
return trans.fill_template( '/admin/library/manage_library_permissions.mako', library=library, msg=msg, messagetype=messagetype )
@web.expose
def library_item_info_template( self, trans, id=None, new_element_count=0, library_id=None,
folder_id=None, library_dataset_id=None, ldda_id=None, **kwd ):
params = util.Params( kwd )
@@ -742,7 +924,7 @@ class Library( BaseController ):
except:
msg = "Invalid library info template specified, id: %s" % str( id )
# TODO: this should probably redirect to the library_dataset_dataset_association method...
return trans.response.send_redirect( web.url_for( controller='admin',
return trans.response.send_redirect( web.url_for( controller='library',
action='browse_library',
id=library_id,
msg=util.sanitize_text( msg ),
@@ -40,7 +40,7 @@
</tr>
</thead>
<tbody>
%for i, library in enumerate( libraries ):
%for library in libraries:
<tr class="libraryRow libraryOrFolderRow" id="libraryRow">
<td><a href="${h.url_for( controller='admin', action='browse_library', id=library.id )}">${library.name}</a></td>
<td><i>${library.description}</i></td>
+3 -2
View File
@@ -28,7 +28,7 @@
<div popupmenu="dataset-${ldda.id}-popup">
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset_dataset_association', id=ldda.id, library_id=library.id, information=True )}">Edit this dataset's information</a>
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset_dataset_association', id=ldda.id, library_id=library.id, permissions=True )}">Edit this dataset's permissions</a>
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset', id=data.id, library_id=library.id )}">Manage this dataset's versions</a>
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset', id=data.id, library_id=library.id, versions=True )}">Manage this dataset's versions</a>
%if data.has_data:
<a class="action-button" href="${h.url_for( controller='admin', action='download_dataset_from_folder', id=ldda.id, library_id=library.id )}">Download this dataset</a>
%endif
@@ -78,7 +78,8 @@
<%def name="render_existing_library_item_info( library_item )">
<%
library_item_type = None
library_item_type = 'unknown type'
library_item_desc = ''
library_item_info_associations = []
if isinstance( library_item, trans.app.model.Library ):
library_item_type = 'library'
+8 -25
View File
@@ -18,7 +18,13 @@
</select>
</%def>
<br/><br/>
%if ldda == ldda.library_dataset.library_dataset_dataset_association:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='admin', action='browse_library', id=library_id )}"><span>Browse this library</span></a>
@@ -29,35 +35,12 @@
${render_msg( msg, messagetype )}
%endif
<div class="toolFormTitle">Manage the following selected datasets</div>
<p/>
<table cellspacing="0" cellpadding="5" border="0" width="100%" class="libraryTitle">
<tr>
<td>
<div class="rowTitle">
<span class="historyItemTitle"><b>${ldda.name}</b></span>
<a id="ldda-${ldda.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
</div>
<div popupmenu="ldda-${ldda.id}-popup">
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset', id=ldda.library_dataset_id, library_id=library_id )}">Manage this dataset's versions</a>
</div>
</td>
<td>
%if ldda == ldda.library_dataset.library_dataset_dataset_association:
<i>This is the latest version of this library dataset</i>
%else:
<font color="red"><i>This is an expired version of this library dataset</i></font>
%endif
</td>
</tr>
</table>
<p/>
<div class="toolForm">
<div class="toolFormTitle">Edit attributes of ${ldda.name}</div>
<div class="toolFormBody">
<form name="edit_attributes" action="${h.url_for( controller='admin', action='library_dataset_dataset_association', library_id=library_id, information=True )}" method="post">
<input type="hidden" name="id" value="${ldda.id}"/>
<br/>
<div class="form-row">
<label>Name:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
+39 -31
View File
@@ -5,9 +5,9 @@
<%
roles = trans.app.model.Role.filter( trans.app.model.Role.table.c.deleted==False ).order_by( trans.app.model.Role.table.c.name ).all()
data_list = util.listify( ldda )
if len( data_list ) > 1:
name_str = '%d selected datasets' % len( data_list )
lddas = util.listify( ldda )
if len( lddas ) > 1:
name_str = '%d selected datasets' % len( lddas )
else:
name_str = ldda.name
%>
@@ -23,32 +23,40 @@
${render_msg( msg, messagetype )}
%endif
<div class="toolFormTitle">Manage the following selected datasets</div>
%if len( lddas ) > 1:
<div class="toolFormTitle">Manage the following selected datasets</div>
<p/>
<table cellspacing="0" cellpadding="5" border="0" width="100%" class="libraryTitle">
%for ldd_assoc in lddas:
<tr>
<td>
<div class="rowTitle">
<span class="historyItemTitle"><b>${ldd_assoc.name}</b></span>
<a id="ldda-${ldd_assoc.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
</div>
<div popupmenu="ldd_assoc-${ldd_assoc.id}-popup">
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset', id=ldd_assoc.library_dataset_id, library_id=library_id )}">Manage this dataset's versions</a>
</div>
</td>
<td>
%if ldd_assoc == ldd_assoc.library_dataset.library_dataset_dataset_association:
<i>This is the latest version of this library dataset</i>
%else:
<font color="red"><i>This is an expired version of this library dataset</i></font>
%endif
</td>
</tr>
%endfor
</table>
<p/>
%else:
%if ldda == ldda.library_dataset.library_dataset_dataset_association:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
%endif
<p/>
<table cellspacing="0" cellpadding="5" border="0" width="100%" class="libraryTitle">
%for ldd_assoc in data_list:
<tr>
<td>
<div class="rowTitle">
<span class="historyItemTitle"><b>${ldd_assoc.name}</b></span>
<a id="ldda-${ldd_assoc.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
</div>
<div popupmenu="ldd_assoc-${ldd_assoc.id}-popup">
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset', id=ldd_assoc.library_dataset_id, library_id=library_id )}">Manage this dataset's versions</a>
</div>
</td>
<td>
%if ldd_assoc == ldd_assoc.library_dataset.library_dataset_dataset_association:
<i>This is the latest version of this library dataset</i>
%else:
<font color="red"><i>This is an expired version of this library dataset</i></font>
%endif
</td>
</tr>
%endfor
</table>
<p/>
<% ldda_ids = ",".join( [ str( d.id ) for d in data_list ] ) %>
${render_permission_form( data_list[0], name_str, h.url_for( controller='admin', action='library_dataset_dataset_association', id=ldda_ids, library_id=library_id, permissions=True ), roles )}
<% ldda_ids = ",".join( [ str( d.id ) for d in lddas ] ) %>
${render_permission_form( lddas[0], name_str, h.url_for( controller='admin', action='library_dataset_dataset_association', id=ldda_ids, library_id=library_id, permissions=True ), roles )}
@@ -0,0 +1,51 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/admin/library/common.mako" import="render_available_templates" />
<%namespace file="/admin/library/common.mako" import="render_existing_library_item_info" />
%if library_dataset == library_dataset.library_dataset_dataset_association:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='admin', action='browse_library', id=library_id )}"><span>Browse this library</span></a>
</li>
</ul>
%if msg:
${render_msg( msg, messagetype )}
%endif
<div class="toolForm">
<div class="toolFormTitle">Edit attributes of ${library_dataset.name}</div>
<div class="toolFormBody">
<form name="edit_attributes" action="${h.url_for( controller='admin', action='library_dataset' )}" method="post">
<input type="hidden" name="id" value="${library_dataset.id}"/>
<div class="form-row">
<label>Name:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="text" name="name" value="${library_dataset.name}" size="40"/>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<label>Info:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="text" name="info" value="${library_dataset.info}" size="40"/>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<input type="submit" name="edit_attributes_button" value="Save"/>
</div>
</form>
</div>
</div>
${render_existing_library_item_info( library_dataset )}
${render_available_templates( library_dataset, library_id )}
@@ -0,0 +1,26 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/dataset/security_common.mako" import="render_permission_form" />
%if library_dataset == library_dataset.library_dataset_dataset_association:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='admin', action='browse_library', id=library_id )}"><span>Browse this library</span></a>
</li>
</ul>
%if msg:
${render_msg( msg, messagetype )}
%endif
<%
roles = trans.app.model.Role.filter( trans.app.model.Role.table.c.deleted==False ).order_by( trans.app.model.Role.table.c.name ).all()
%>
${render_permission_form( library_dataset, library_dataset.name, h.url_for( controller='admin', action='library_dataset', id=library_dataset.id, library_id=library_id, permissions=True ), roles )}
@@ -0,0 +1,55 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
%if library_dataset == library_dataset.library_dataset_dataset_association.library_dataset:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='admin', action='browse_library', id=library_id )}"><span>Browse this library</span></a>
</li>
</ul>
%if msg:
${render_msg( msg, messagetype )}
%endif
<div class="toolForm">
<div class="toolFormTitle">Set version of ${library_dataset.name}</div>
<div class="toolFormBody">
<form name="library_dataset_version" action="${h.url_for( controller='admin', action='library_dataset', id=library_dataset.id, library_id=library_id, versions=True )}" method="post">
<div class="form-row">
<div style="float: left; width: 250px; margin-right: 10px;">
<div class="form-row">
<input type="radio" name="set_lda_id" value="${library_dataset.library_dataset_dataset_association.id}" checked>${library_dataset.name} (current)
<a id="dataset-${library_dataset.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
<div popupmenu="dataset-${library_dataset.id}-popup">
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset_dataset_association', id=library_dataset.library_dataset_dataset_association.id, library_id=library_id, information=True )}">Edit this dataset's information</a>
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset_dataset_association', id=library_dataset.library_dataset_dataset_association.id, library_id=library_id, permissions=True )}">Edit this dataset's permissions</a>
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset_dataset_association', replace_id=library_dataset.id, library_id=library_id )}">Replace this dataset with a new version</a>
</div>
%for ldda in library_dataset.expired_datasets:
<br/>
<input type="radio" name="set_lda_id" value="${ldda.id}" >${ldda.name}
<a id="ldda-${ldda.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
<div popupmenu="ldda-${ldda.id}-popup">
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset_dataset_association', id=ldda.id, library_id=library_id, information=True )}">Edit this dataset's information</a>
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset_dataset_association', id=ldda.id, library_id=library_id, permissions=True )}">Edit this dataset's permissions</a>
</div>
%endfor
</div>
</div>
<div style="clear: both"></div>
</div>
%if library_dataset.expired_datasets:
<div class="form-row">
<input type="submit" name="change_version_button" value="Save"/>
</div>
%endif
</form>
</div>
</div>
@@ -1,73 +0,0 @@
<%inherit file="/base.mako"/>
<%namespace file="/dataset/security_common.mako" import="render_permission_form" />
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/admin/library/common.mako" import="render_available_templates" />
<%
roles = trans.app.model.Role.filter( trans.app.model.Role.table.c.deleted==False ).order_by( trans.app.model.Role.table.c.name ).all()
%>
%if msg:
${render_msg( msg, messagetype )}
%endif
<div class="toolForm">
<div class="toolFormTitle">Set version of ${library_dataset.name}</div>
<div class="toolFormBody">
<form name="library_dataset_version" action="${h.url_for( controller='admin', action='library_dataset', id=library_dataset.id, library_id=library_id )}" method="post">
<div class="form-row">
<div style="float: left; width: 250px; margin-right: 10px;">
<div class="form-row">
<input type="radio" name="set_lda_id" value="${library_dataset.library_dataset_dataset_association.id}" checked><a href="${h.url_for( controller='admin', action='library_dataset_dataset_association', id=library_dataset.library_dataset_dataset_association.id, library_id=library_id )}">${library_dataset.name}</a> (current)
<a id="dataset-${library_dataset.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
<div popupmenu="dataset-${library_dataset.id}-popup">
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset_dataset_association', replace_id=library_dataset.id, library_id=library_id )}">Replace this dataset with a new version</a>
</div>
%for expired_dataset in library_dataset.expired_datasets:
<br/>
<input type="radio" name="set_lda_id" value="${expired_dataset.id}" ><a href="${h.url_for( controller='admin', action='library_dataset_dataset_association', id=expired_dataset.id, library_id=library_id )}">${expired_dataset.name}</a>
%endfor
</div>
</div>
<div style="clear: both"></div>
</div>
%if library_dataset.expired_datasets:
<div class="form-row">
<input type="submit" name="change_version" value="Save"/>
</div>
%endif
</form>
</div>
</div>
<p/>
${render_permission_form( library_dataset, library_dataset.name, h.url_for( controller='admin', action='library_dataset', id=library_dataset.id, library_id=library_id, permissions=True ), roles )}
<div class="toolForm">
<div class="toolFormTitle">Edit attributes of ${library_dataset.name}</div>
<div class="toolFormBody">
<form name="edit_attributes" action="${h.url_for( controller='admin', action='library_dataset' )}" method="post">
<input type="hidden" name="id" value="${library_dataset.id}"/>
<div class="form-row">
<label>Name:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="text" name="name" value="${library_dataset.name}" size="40"/>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<label>Info:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="text" name="info" value="${library_dataset.info}" size="40"/>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<input type="submit" name="edit_attributes_button" value="Save"/>
</div>
</form>
</div>
</div>
<p/>
${render_available_templates( library_dataset, library_id )}
+13 -4
View File
@@ -1,9 +1,10 @@
<%def name="render_select( current_actions, action_key, action, all_roles )">
<%
in_roles = []
import sets
in_roles = sets.Set()
for a in current_actions:
if a.action == action.action:
in_roles.append( a.role )
in_roles.add( a.role )
out_roles = filter( lambda x: x not in in_roles, all_roles )
%>
<p><b>${action.action}:</b> ${action.description}</p>
@@ -36,34 +37,42 @@
current_actions = obj.default_permissions
permitted_actions = trans.app.model.Dataset.permitted_actions.items()
obj_str = 'user %s' % obj_name
obj_type = 'dataset'
elif isinstance( obj, trans.app.model.History ):
current_actions = obj.default_permissions
permitted_actions = trans.app.model.Dataset.permitted_actions.items()
obj_str = 'history %s' % obj_name
obj_type = 'dataset'
elif isinstance( obj, trans.app.model.Dataset ):
current_actions = obj.actions
permitted_actions = trans.app.model.Dataset.permitted_actions.items()
obj_str = obj_name
obj_type = 'dataset'
elif isinstance( obj, trans.app.model.LibraryDatasetDatasetAssociation ):
current_actions = obj.actions + obj.dataset.actions
permitted_actions = trans.app.model.Dataset.permitted_actions.items()
permitted_actions = trans.app.model.Dataset.permitted_actions.items() + trans.app.model.Library.permitted_actions.items()
obj_str = obj_name
obj_type = 'dataset'
elif isinstance( obj, trans.app.model.Library ):
current_actions = obj.actions
permitted_actions = trans.app.model.Library.permitted_actions.items()
obj_str = 'library %s' % obj_name
obj_type = 'library'
elif isinstance( obj, trans.app.model.LibraryDataset ):
current_actions = obj.actions
permitted_actions = trans.app.model.Library.permitted_actions.items()
obj_str = 'library dataset %s' % obj_name
obj_type = 'library'
elif isinstance( obj, trans.app.model.LibraryFolder ):
current_actions = obj.actions
permitted_actions = trans.app.model.Library.permitted_actions.items()
obj_str = 'library folder %s' % obj_name
obj_type = 'library'
else:
current_actions = []
permitted_actions = {}.items()
obj_str = 'unknown object %s' %obj_name
obj_type = ''
%>
<script type="text/javascript">
$( document ).ready( function () {
@@ -87,7 +96,7 @@
});
</script>
<div class="toolForm">
<div class="toolFormTitle">Manage permissions and role associations of ${obj_str}</div>
<div class="toolFormTitle">Manage ${obj_type} permissions and role associations of ${obj_str}</div>
<div class="toolFormBody">
<form name="edit_role_associations" id="edit_role_associations" action="${form_url}" method="post">
<div class="form-row"></div>
+1 -1
View File
@@ -20,7 +20,7 @@
</tr>
</thead>
<tbody>
%for i, library in enumerate( libraries ):
%for library in libraries:
<tr class="libraryRow libraryOrFolderRow" id="libraryRow">
<td><a href="${h.url_for( controller='library', action='browse_library', id=library.id )}">${library.name}</a></td>
<td><i>${library.description}</i></td>
+3
View File
@@ -28,6 +28,9 @@
%endif
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.DATASET_MANAGE_PERMISSIONS, dataset=ldda.dataset ):
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=ldda.id, library_id=library.id, permissions=True )}">Edit this dataset's permissions</a>
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=ldda.library_dataset ):
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset', id=data.id, library_id=library.id, versions=True )}">Manage this dataset's versions</a>
%endif
%endif
%if data.has_data:
<a class="action-button" href="${h.url_for( controller='library', action='download_dataset_from_folder', id=ldda.id, library_id=library.id )}">Download this dataset</a>
+9 -28
View File
@@ -18,7 +18,13 @@
</select>
</%def>
<br/><br/>
%if ldda == ldda.library_dataset.library_dataset_dataset_association:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='library', action='browse_library', id=library_id )}"><span>Browse this library</span></a>
@@ -29,30 +35,6 @@
${render_msg( msg, messagetype )}
%endif
<div class="toolFormTitle">Manage the following selected datasets</div>
<p/>
<table cellspacing="0" cellpadding="5" border="0" width="100%" class="libraryTitle">
<tr>
<td>
<div class="rowTitle">
<span class="historyItemTitle"><b>${ldda.name}</b></span>
<a id="ldda-${ldda.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
</div>
<div popupmenu="ldda-${ldda.id}-popup">
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset', id=ldda.library_dataset_id, library_id=library_id )}">Manage this dataset's versions</a>
</div>
</td>
<td>
%if ldda == ldda.library_dataset.library_dataset_dataset_association:
<i>This is the latest version of this library dataset</i>
%else:
<font color="red"><i>This is an expired version of this library dataset</i></font>
%endif
</td>
</tr>
</table>
<p/>
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=ldda.library_dataset ):
<div class="toolForm">
<div class="toolFormTitle">Edit attributes of ${ldda.name}</div>
@@ -145,11 +127,10 @@
</div>
</div>
</div>
<div class="toolForm">
${render_existing_library_item_info( ldda.library_dataset )}
</div>
%endif
${render_existing_library_item_info( ldda.library_dataset )}
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=ldda.library_dataset ):
${render_available_templates( ldda.library_dataset, library_id )}
%endif
+39 -31
View File
@@ -5,9 +5,9 @@
<%
roles = trans.app.model.Role.filter( trans.app.model.Role.table.c.deleted==False ).order_by( trans.app.model.Role.table.c.name ).all()
data_list = util.listify( ldda )
if len( data_list ) > 1:
name_str = '%d selected datasets' % len( data_list )
lddas = util.listify( ldda )
if len( lddas ) > 1:
name_str = '%d selected datasets' % len( lddas )
else:
name_str = ldda.name
%>
@@ -23,32 +23,40 @@
${render_msg( msg, messagetype )}
%endif
<div class="toolFormTitle">Manage the following selected datasets</div>
%if len( lddas ) > 1:
<div class="toolFormTitle">Manage the following selected datasets</div>
<p/>
<table cellspacing="0" cellpadding="5" border="0" width="100%" class="libraryTitle">
%for ldd_assoc in lddas:
<tr>
<td>
<div class="rowTitle">
<span class="historyItemTitle"><b>${ldd_assoc.name}</b></span>
<a id="ldda-${ldd_assoc.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
</div>
<div popupmenu="ldd_assoc-${ldd_assoc.id}-popup">
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset', id=ldd_assoc.library_dataset_id, library_id=library_id )}">Manage this dataset's versions</a>
</div>
</td>
<td>
%if ldd_assoc == ldd_assoc.library_dataset.library_dataset_dataset_association:
<i>This is the latest version of this library dataset</i>
%else:
<font color="red"><i>This is an expired version of this library dataset</i></font>
%endif
</td>
</tr>
%endfor
</table>
<p/>
%else:
%if ldda == ldda.library_dataset.library_dataset_dataset_association:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
%endif
<p/>
<table cellspacing="0" cellpadding="5" border="0" width="100%" class="libraryTitle">
%for ldd_assoc in data_list:
<tr>
<td>
<div class="rowTitle">
<span class="historyItemTitle"><b>${ldd_assoc.name}</b></span>
<a id="ldda-${ldd_assoc.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
</div>
<div popupmenu="ldd_assoc-${ldd_assoc.id}-popup">
<a class="action-button" href="${h.url_for( controller='admin', action='library_dataset', id=ldd_assoc.library_dataset_id, library_id=library_id )}">Manage this dataset's versions</a>
</div>
</td>
<td>
%if ldd_assoc == ldd_assoc.library_dataset.library_dataset_dataset_association:
<i>This is the latest version of this library dataset</i>
%else:
<font color="red"><i>This is an expired version of this library dataset</i></font>
%endif
</td>
</tr>
%endfor
</table>
<p/>
<% ldda_ids = ",".join( [ str( d.id ) for d in data_list ] ) %>
${render_permission_form( data_list[0], name_str, h.url_for( controller='library', action='library_dataset_dataset_association', id=ldda_ids, library_id=library_id, permissions=True ), roles )}
<% ldda_ids = ",".join( [ str( d.id ) for d in lddas ] ) %>
${render_permission_form( lddas[0], name_str, h.url_for( controller='library', action='library_dataset_dataset_association', id=ldda_ids, library_id=library_id, permissions=True ), roles )}
@@ -0,0 +1,69 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/library/common.mako" import="render_available_templates" />
<%namespace file="/library/common.mako" import="render_existing_library_item_info" />
%if library_dataset == library_dataset.library_dataset_dataset_association:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='library', action='browse_library', id=library_id )}"><span>Browse this library</span></a>
</li>
</ul>
%if msg:
${render_msg( msg, messagetype )}
%endif
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=library_dataset ):
<div class="toolForm">
<div class="toolFormTitle">Edit attributes of ${library_dataset.name}</div>
<div class="toolFormBody">
<form name="edit_attributes" action="${h.url_for( controller='library', action='library_dataset', id=library_dataset.id, library_id=library_id, information=True )}" method="post">
<div class="form-row">
<label>Name:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="text" name="name" value="${library_dataset.name}" size="40"/>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<label>Info:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="text" name="info" value="${library_dataset.info}" size="40"/>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<input type="submit" name="edit_attributes_button" value="Save"/>
</div>
</form>
</div>
</div>
%else:
<div class="toolForm">
<div class="toolFormTitle">View attributes of ${library_dataset.name}</div>
<div class="toolFormBody">
<div class="form-row">
<b>Name:</b> ${library_dataset.name}
<div style="clear: both"></div>
<b>Info:</b> ${library_dataset.info}
<div style="clear: both"></div>
<b>Dataset Versions:</b>
<div style="clear: both"></div>
</div>
<div style="clear: both"></div>
</div>
</div>
%endif
${render_existing_library_item_info( library_dataset )}
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=library_dataset ):
${render_available_templates( library_dataset, library_id )}
%endif
@@ -0,0 +1,27 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/dataset/security_common.mako" import="render_permission_form" />>
%if library_dataset == library_dataset.library_dataset_dataset_association.library_dataset:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='library', action='browse_library', id=library_id )}"><span>Browse this library</span></a>
</li>
</ul>
%if msg:
${render_msg( msg, messagetype )}
%endif
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_manage, library_item=library_dataset ):
<%
roles = trans.app.model.Role.filter( trans.app.model.Role.table.c.deleted==False ).order_by( trans.app.model.Role.table.c.name ).all()
%>
${render_permission_form( library_dataset, library_dataset.name, h.url_for( controller='library', action='library_dataset', id=library_dataset.id, library_id=library_id, permissions=True ), roles )}
%endif
@@ -0,0 +1,55 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
%if library_dataset == library_dataset.library_dataset_dataset_association.library_dataset:
<b><i>This is the latest version of this library dataset</i></b>
%else:
<font color="red"><b><i>This is an expired version of this library dataset</i></b></font>
%endif
<p/>
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='library', action='browse_library', id=library_id )}"><span>Browse this library</span></a>
</li>
</ul>
%if msg:
${render_msg( msg, messagetype )}
%endif
<div class="toolForm">
<div class="toolFormTitle">Set version of ${library_dataset.name}</div>
<div class="toolFormBody">
<form name="library_dataset_version" action="${h.url_for( controller='library', action='library_dataset', id=library_dataset.id, library_id=library_id, versions=True )}" method="post">
<div class="form-row">
<div style="float: left; width: 250px; margin-right: 10px;">
<div class="form-row">
<input type="radio" name="set_lda_id" value="${library_dataset.library_dataset_dataset_association.id}" checked>${library_dataset.name} (current)
<a id="dataset-${library_dataset.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
<div popupmenu="dataset-${library_dataset.id}-popup">
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=library_dataset.library_dataset_dataset_association.id, library_id=library_id, information=True )}">Edit this dataset's information</a>
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=library_dataset.library_dataset_dataset_association.id, library_id=library_id, permissions=True )}">Edit this dataset's permissions</a>
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', replace_id=library_dataset.id, library_id=library_id )}">Replace this dataset with a new version</a>
</div>
%for ldda in library_dataset.expired_datasets:
<br/>
<input type="radio" name="set_lda_id" value="${ldda.id}" >${ldda.name}
<a id="ldda-${ldda.id}-popup" class="popup-arrow" style="display: none;">&#9660;</a>
<div popupmenu="ldda-${ldda.id}-popup">
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=ldda.id, library_id=library_id, information=True )}">Edit this dataset's information</a>
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=ldda.id, library_id=library_id, permissions=True )}">Edit this dataset's permissions</a>
</div>
%endfor
</div>
</div>
<div style="clear: both"></div>
</div>
%if library_dataset.expired_datasets:
<div class="form-row">
<input type="submit" name="change_version_button" value="Save"/>
</div>
%endif
</form>
</div>
</div>
@@ -1,98 +0,0 @@
<%inherit file="/base.mako"/>
<%namespace file="/dataset/security_common.mako" import="render_permission_form" />
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/library/common.mako" import="render_available_templates" />
<%namespace file="/library/common.mako" import="render_existing_library_item_info" />
%if msg:
${render_msg( msg, messagetype )}
%endif
<%def name="title()">Edit Library Dataset Attributes</%def>
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MANAGE, library_item=library_dataset ):
${render_permission_form( library_dataset, library_dataset.name, h.url_for( controller='library', action='library_dataset', id=library_dataset.id, library_id=library_id, permissions=True ), trans.user.all_roles() )}
%endif
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=library_dataset ):
<div class="toolForm">
<div class="toolFormTitle">Edit attributes of ${library_dataset.name}</div>
<div class="toolFormBody">
<form name="edit_attributes" action="${h.url_for( controller='library', action='library_dataset', id=library_dataset.id, library_id=library_id )}" method="post">
<div class="form-row">
<label>Name:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="text" name="name" value="${library_dataset.name}" size="40"/>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<label>Info:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="text" name="info" value="${library_dataset.info}" size="40"/>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<label>Set Dataset Version:</label>
<div style="float: left; width: 250px; margin-right: 10px;">
<div class="form-row">
<input type="radio" name="set_lda_id" value="${library_dataset.library_dataset_dataset_association.id}" checked><a href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=library_dataset.library_dataset_dataset_association.id, library_id=library_id )}">${library_dataset.name}</a> (current)
%if refered_lda == library_dataset.library_dataset_dataset_association:
(your version)
%endif
%for expired_dataset in library_dataset.expired_datasets:
<br>
<input type="radio" name="set_lda_id" value="${expired_dataset.id}" ><a href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=expired_dataset.id, library_id=library_id )}">${expired_dataset.name}</a>
%if refered_lda == expired_dataset:
(your version)
%endif
%endfor
</div>
<div class="form-row">
Click <a href="${h.url_for( controller='library', action='library_dataset_dataset_association', replace_id=library_dataset.id, library_id=library_id )}">here</a> to replace this dataset with a new version.
</div>
<div style="clear: both"></div>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<input type="submit" name="save" value="Save"/>
</div>
</form>
</div>
</div>
%else:
<div class="toolForm">
<div class="toolFormTitle">View attributes of ${library_dataset.name}</div>
<div class="toolFormBody">
<div class="form-row">
<b>Name:</b> ${library_dataset.name}
<div style="clear: both"></div>
<b>Info:</b> ${library_dataset.info}
<div style="clear: both"></div>
<b>Dataset Versions:</b>
<div style="clear: both"></div>
<a href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=library_dataset.library_dataset_dataset_association.id, library_id=library_id )}">${library_dataset.name}</a> (current)
%if refered_lda == library_dataset.library_dataset_dataset_association:
(your version)
%endif
%for expired_dataset in library_dataset.expired_datasets:
<br/>
<a href="${h.url_for( controller='library', action='library_dataset_dataset_association', id=expired_dataset.id, library_id=library_id )}">${expired_dataset.name}</a>
%if refered_lda == expired_dataset:
(your version)
%endif
%endfor
</div>
<div style="clear: both"></div>
</div>
<div class="toolForm">
${render_existing_library_item_info( library_dataset )}
</div>
</div>
%endif
%if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=library_dataset ):
${render_available_templates( library_dataset, library_id )}
%endif
@@ -585,7 +585,6 @@ class TestSecurityAndLibraries( TwillTestCase ):
# Check the permissions on the dataset - should be 'access', which only allows viewing the information
self.home()
self.visit_url( '%s/library/library_dataset_dataset_association?information=True&library_id=%s&id=%s' % ( self.url, str( library_one.id ), str( ldda_two.id ) ) )
self.check_page_for_string( 'Manage the following selected datasets' )
self.check_page_for_string( '2.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' )
@@ -671,7 +670,6 @@ class TestSecurityAndLibraries( TwillTestCase ):
# Test selecting "View this dataset's information"
self.home()
self.visit_url( '%s/library/library_dataset_dataset_association?information=True&library_id=%s&id=%s' % ( self.url, str( library_one.id ), str( ldda_three.id ) ) )
self.check_page_for_string( 'Manage the following selected datasets' )
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' )
@@ -739,7 +737,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
self.visit_url( '%s/root/edit?id=%s' % ( self.url, str( last_hda_created.id ) ) )
self.check_page_for_string( 'Edit Attributes' )
self.check_page_for_string( last_hda_created.name )
check_str = 'Manage permissions and role associations of %s' % last_hda_created.name
check_str = 'Manage dataset permissions and role associations of %s' % last_hda_created.name
self.check_page_for_string( check_str )
self.check_page_for_string( 'Role members can manage the roles associated with this dataset' )
self.check_page_for_string( 'Role members can import this dataset into their history for analysis' )
@@ -790,7 +788,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
self.check_page_for_string( last_hda_created.name )
try:
# This should no longer be possible
check_str = 'Manage permissions and role associations of %s' % last_hda_created.name
check_str = 'Manage dataset permissions and role associations of %s' % last_hda_created.name
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: