Eagerload active_datasets for a history rather than activatable_datasets since it throws exceptions in the migration script.

This commit is contained in:
Greg Von Kuster
2008-12-23 10:25:54 -05:00
parent 61951c59e1
commit 6a3f5a925e
@@ -170,6 +170,7 @@ def main():
default_user_action = security_agent.permitted_actions.DATASET_MANAGE_PERMISSIONS.action
for user in app.model.User.query().all():
print
print "################"
print "Setting up user %s." % user.email
private_role = security_agent.get_private_user_role( user )
@@ -187,12 +188,14 @@ def main():
dup = app.model.DefaultUserPermissions( user, default_user_action, private_role )
dup.flush()
# Set DefaultHistoryPermissions on all of the user's active histories and associated datasets
# TODO: fix mapping for history.activatable_datasets so it doesn't throw an exception on the
# following query when eagerloading activatable_datasets. Fix all of the queries below that
# call history.active_datasets to be history.activatable_datasets when this works.
histories = app.model.History.filter( and_( app.model.History.table.c.user_id==user.id,
app.model.History.table.purged==False ) ) \
.options( eagerload( 'activatable_datasets' ) ).all()
app.model.History.table.c.purged==False ) ) \
.options( eagerload( 'active_datasets' ) ).all()
print "Setting DefaultHistoryPermissions for %d un-purged histories associated with %s" % ( len( histories ), user.email )
for history in histories:
print "Working on history %d" % history.id
# Delete all of the current default permissions for the history
for dhp in history.default_permissions:
dhp.delete()
@@ -200,11 +203,10 @@ def main():
# Add the new default permissions for the history
dhp = app.model.DefaultHistoryPermissions( history, default_user_action, private_role )
dhp.flush()
print "Setting ActionDatasetRoleAssociations for %d un-purged datasets in history %d" % ( len( history.activatable_datasets ), history.id )
print "Setting ActionDatasetRoleAssociations for %d un-purged datasets in history %d" % ( len( history.active_datasets ), history.id )
# Set the permissions on the current history's datasets that are not purged
for hda in history.activatable_datasets:
for hda in history.active_datasets:
dataset = hda.dataset
print "Working on dataset %d" % dataset.id
if dataset.library_associations:
# Don't change permissions on a dataset associated with a library
continue