def undelete_group(self, trans, **kwd):
     id = kwd.get('id', None)
     if not id:
         message = "No group ids received for undeleting"
         trans.response.send_redirect(
             web.url_for(controller='admin',
                         action='groups',
                         message=message,
                         status='error'))
     ids = util.listify(id)
     count = 0
     undeleted_groups = ""
     for group_id in ids:
         group = get_group(trans, group_id)
         if not group.deleted:
             message = "Group '%s' has not been deleted, so it cannot be undeleted." % group.name
             trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='groups',
                             message=util.sanitize_text(message),
                             status='error'))
         group.deleted = False
         trans.sa_session.add(group)
         trans.sa_session.flush()
         count += 1
         undeleted_groups += " %s" % group.name
     message = "Undeleted %d groups: %s" % (count, undeleted_groups)
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='groups',
                     message=util.sanitize_text(message),
                     status='done'))
 def undelete_role(self, trans, **kwd):
     id = kwd.get('id', None)
     if not id:
         message = "No role ids received for undeleting"
         trans.response.send_redirect(
             web.url_for(controller='admin',
                         action='roles',
                         message=message,
                         status='error'))
     ids = util.listify(id)
     count = 0
     undeleted_roles = ""
     for role_id in ids:
         role = get_role(trans, role_id)
         if not role.deleted:
             message = "Role '%s' has not been deleted, so it cannot be undeleted." % role.name
             trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='roles',
                             message=util.sanitize_text(message),
                             status='error'))
         role.deleted = False
         trans.sa_session.add(role)
         trans.sa_session.flush()
         count += 1
         undeleted_roles += " %s" % role.name
     message = "Undeleted %d roles: %s" % (count, undeleted_roles)
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='roles',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #3
0
 def download_dataset_from_folder( self, trans, cntrller, obj_id, library_id=None, **kwd ):
     """Catches the dataset id and displays file contents as directed"""
     # id must refer to a LibraryDatasetDatasetAssociation object
     ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( obj_id )
     if not ldda.dataset:
         msg = 'Invalid LibraryDatasetDatasetAssociation id %s received for file downlaod' % str( obj_id )
         return trans.response.send_redirect( web.url_for( controller=cntrller,
                                                           action='browse_library',
                                                           obj_id=library_id,
                                                           msg=util.sanitize_text( msg ),
                                                           messagetype='error' ) )
     mime = trans.app.datatypes_registry.get_mimetype_by_extension( ldda.extension.lower() )
     trans.response.set_content_type( mime )
     fStat = os.stat( ldda.file_name )
     trans.response.headers[ 'Content-Length' ] = int( fStat.st_size )
     valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     fname = ldda.name
     fname = ''.join( c in valid_chars and c or '_' for c in fname )[ 0:150 ]
     trans.response.headers[ "Content-Disposition" ] = "attachment; filename=GalaxyLibraryDataset-%s-[%s]" % ( str( obj_id ), fname )
     try:
         return open( ldda.file_name )
     except: 
         msg = 'This dataset contains no content'
         return trans.response.send_redirect( web.url_for( controller=cntrller,
                                                           action='browse_library',
                                                           obj_id=library_id,
                                                           msg=util.sanitize_text( msg ),
                                                           messagetype='error' ) )
 def undelete_user(self, trans, **kwd):
     id = kwd.get('id', None)
     if not id:
         message = "No user ids received for undeleting"
         trans.response.send_redirect(
             web.url_for(controller='admin',
                         action='users',
                         message=message,
                         status='error'))
     ids = util.listify(id)
     count = 0
     undeleted_users = ""
     for user_id in ids:
         user = get_user(trans, user_id)
         if not user.deleted:
             message = "User '%s' has not been deleted, so it cannot be undeleted." % user.email
             trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='users',
                             message=util.sanitize_text(message),
                             status='error'))
         user.deleted = False
         trans.sa_session.add(user)
         trans.sa_session.flush()
         count += 1
         undeleted_users += " %s" % user.email
     message = "Undeleted %d users: %s" % (count, undeleted_users)
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='users',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #5
0
 def recalculate_user_disk_usage( self, trans, **kwd ):
     user_id = kwd.get( 'id', None )
     user = trans.sa_session.query( trans.model.User ).get( trans.security.decode_id( user_id ) )
     if not user:
         return trans.show_error_message( "User not found for id (%s)" % sanitize_text( str( user_id ) ) )
     engine = None
     if trans.app.config.database_connection:
         engine = trans.app.config.database_connection.split(':')[0]
     if engine not in ( 'postgres', 'postgresql' ):
         done = False
         while not done:
             current = user.get_disk_usage()
             new = user.calculate_disk_usage()
             trans.sa_session.refresh( user )
             # make sure usage didn't change while calculating, set done
             if user.get_disk_usage() == current:
                 done = True
             if new not in (current, None):
                 user.set_disk_usage( new )
                 trans.sa_session.add( user )
                 trans.sa_session.flush()
     else:
         # We can use the lightning fast pgcalc!
         current = user.get_disk_usage()
         new = pgcalc( self.sa_session, user.id )
     # yes, still a small race condition between here and the flush
     if new in ( current, None ):
         message = 'Usage is unchanged at %s.' % nice_size( current )
     else:
         message = 'Usage has changed by %s to %s.' % ( nice_size( new - current ), nice_size( new )  )
     return trans.response.send_redirect( web.url_for( controller='admin',
                                                       action='users',
                                                       message=sanitize_text( message ),
                                                       status='info' ) )
Пример #6
0
 def undelete_user(self, trans, **kwd):
     id = kwd.get('id', None)
     if not id:
         message = "No user ids received for undeleting"
         trans.response.send_redirect(web.url_for(controller='admin',
                                                  action='users',
                                                  message=message,
                                                  status='error'))
     ids = util.listify(id)
     count = 0
     undeleted_users = ""
     for user_id in ids:
         user = get_user(trans, user_id)
         if not user.deleted:
             message = "User '%s' has not been deleted, so it cannot be undeleted." % user.email
             trans.response.send_redirect(web.url_for(controller='admin',
                                                      action='users',
                                                      message=util.sanitize_text(message),
                                                      status='error'))
         user.deleted = False
         trans.sa_session.add(user)
         trans.sa_session.flush()
         count += 1
         undeleted_users += " %s" % user.email
     message = "Undeleted %d users: %s" % (count, undeleted_users)
     trans.response.send_redirect(web.url_for(controller='admin',
                                              action='users',
                                              message=util.sanitize_text(message),
                                              status='done'))
Пример #7
0
 def undelete_group(self, trans, **kwd):
     id = kwd.get('id', None)
     if not id:
         message = "No group ids received for undeleting"
         trans.response.send_redirect(web.url_for(controller='admin',
                                                  action='groups',
                                                  message=message,
                                                  status='error'))
     ids = util.listify(id)
     count = 0
     undeleted_groups = ""
     for group_id in ids:
         group = get_group(trans, group_id)
         if not group.deleted:
             message = "Group '%s' has not been deleted, so it cannot be undeleted." % group.name
             trans.response.send_redirect(web.url_for(controller='admin',
                                                      action='groups',
                                                      message=util.sanitize_text(message),
                                                      status='error'))
         group.deleted = False
         trans.sa_session.add(group)
         trans.sa_session.flush()
         count += 1
         undeleted_groups += " %s" % group.name
     message = "Undeleted %d groups: %s" % (count, undeleted_groups)
     trans.response.send_redirect(web.url_for(controller='admin',
                                              action='groups',
                                              message=util.sanitize_text(message),
                                              status='done'))
Пример #8
0
 def purge_group(self, trans, **kwd):
     # This method should only be called for a Group that has previously been deleted.
     # Purging a deleted Group simply deletes all UserGroupAssociations and GroupRoleAssociations.
     id = kwd.get('id', None)
     if not id:
         message = "No group ids received for purging"
         trans.response.send_redirect(web.url_for(controller='admin',
                                                  action='groups',
                                                  message=util.sanitize_text(message),
                                                  status='error'))
     ids = util.listify(id)
     message = "Purged %d groups: " % len(ids)
     for group_id in ids:
         group = get_group(trans, group_id)
         if not group.deleted:
             # We should never reach here, but just in case there is a bug somewhere...
             message = "Group '%s' has not been deleted, so it cannot be purged." % group.name
             trans.response.send_redirect(web.url_for(controller='admin',
                                                      action='groups',
                                                      message=util.sanitize_text(message),
                                                      status='error'))
         # Delete UserGroupAssociations
         for uga in group.users:
             trans.sa_session.delete(uga)
         # Delete GroupRoleAssociations
         for gra in group.roles:
             trans.sa_session.delete(gra)
         trans.sa_session.flush()
         message += " %s " % group.name
     trans.response.send_redirect(web.url_for(controller='admin',
                                              action='groups',
                                              message=util.sanitize_text(message),
                                              status='done'))
Пример #9
0
 def undelete_role(self, trans, **kwd):
     id = kwd.get('id', None)
     if not id:
         message = "No role ids received for undeleting"
         trans.response.send_redirect(web.url_for(controller='admin',
                                                  action='roles',
                                                  message=message,
                                                  status='error'))
     ids = util.listify(id)
     count = 0
     undeleted_roles = ""
     for role_id in ids:
         role = get_role(trans, role_id)
         if not role.deleted:
             message = "Role '%s' has not been deleted, so it cannot be undeleted." % role.name
             trans.response.send_redirect(web.url_for(controller='admin',
                                                      action='roles',
                                                      message=util.sanitize_text(message),
                                                      status='error'))
         role.deleted = False
         trans.sa_session.add(role)
         trans.sa_session.flush()
         count += 1
         undeleted_roles += " %s" % role.name
     message = "Undeleted %d roles: %s" % (count, undeleted_roles)
     trans.response.send_redirect(web.url_for(controller='admin',
                                              action='roles',
                                              message=util.sanitize_text(message),
                                              status='done'))
Пример #10
0
 def recalculate_user_disk_usage( self, trans, **kwd ):
     user_id = kwd.get( 'id', None )
     user = trans.sa_session.query( trans.model.User ).get( trans.security.decode_id( user_id ) )
     if not user:
         return trans.show_error_message( "User not found for id (%s)" % sanitize_text( str( user_id ) ) )
     engine = None
     if trans.app.config.database_connection:
         engine = trans.app.config.database_connection.split(':')[0]
     if engine not in ( 'postgres', 'postgresql' ):
         done = False
         while not done:
             current = user.get_disk_usage()
             new = user.calculate_disk_usage()
             trans.sa_session.refresh( user )
             # make sure usage didn't change while calculating, set done
             if user.get_disk_usage() == current:
                 done = True
             if new not in (current, None):
                 user.set_disk_usage( new )
                 trans.sa_session.add( user )
                 trans.sa_session.flush()
     else:
         # We can use the lightning fast pgcalc!
         current = user.get_disk_usage()
         new = pgcalc( self.sa_session, user.id )
     # yes, still a small race condition between here and the flush
     if new in ( current, None ):
         message = 'Usage is unchanged at %s.' % nice_size( current )
     else:
         message = 'Usage has changed by %s to %s.' % ( nice_size( new - current ), nice_size( new )  )
     return trans.response.send_redirect( web.url_for( controller='admin',
                                                       action='users',
                                                       message=sanitize_text( message ),
                                                       status='info' ) )
 def purge_role(self, trans, **kwd):
     # This method should only be called for a Role that has previously been deleted.
     # Purging a deleted Role deletes all of the following from the database:
     # - UserRoleAssociations where role_id == Role.id
     # - DefaultUserPermissions where role_id == Role.id
     # - DefaultHistoryPermissions where role_id == Role.id
     # - GroupRoleAssociations where role_id == Role.id
     # - DatasetPermissionss where role_id == Role.id
     id = kwd.get('id', None)
     if not id:
         message = "No role ids received for purging"
         trans.response.send_redirect(
             web.url_for(controller='admin',
                         action='roles',
                         message=util.sanitize_text(message),
                         status='error'))
     ids = util.listify(id)
     message = "Purged %d roles: " % len(ids)
     for role_id in ids:
         role = get_role(trans, role_id)
         if not role.deleted:
             message = "Role '%s' has not been deleted, so it cannot be purged." % role.name
             trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='roles',
                             message=util.sanitize_text(message),
                             status='error'))
         # Delete UserRoleAssociations
         for ura in role.users:
             user = trans.sa_session.query(trans.app.model.User).get(
                 ura.user_id)
             # Delete DefaultUserPermissions for associated users
             for dup in user.default_permissions:
                 if role == dup.role:
                     trans.sa_session.delete(dup)
             # Delete DefaultHistoryPermissions for associated users
             for history in user.histories:
                 for dhp in history.default_permissions:
                     if role == dhp.role:
                         trans.sa_session.delete(dhp)
             trans.sa_session.delete(ura)
         # Delete GroupRoleAssociations
         for gra in role.groups:
             trans.sa_session.delete(gra)
         # Delete DatasetPermissionss
         for dp in role.dataset_actions:
             trans.sa_session.delete(dp)
         trans.sa_session.flush()
         message += " %s " % role.name
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='roles',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #12
0
 def purge_role(self, trans, **kwd):
     # This method should only be called for a Role that has previously been deleted.
     # Purging a deleted Role deletes all of the following from the database:
     # - UserRoleAssociations where role_id == Role.id
     # - DefaultUserPermissions where role_id == Role.id
     # - DefaultHistoryPermissions where role_id == Role.id
     # - GroupRoleAssociations where role_id == Role.id
     # - DatasetPermissionss where role_id == Role.id
     id = kwd.get('id', None)
     if not id:
         message = "No role ids received for purging"
         trans.response.send_redirect(web.url_for(controller='admin',
                                                  action='roles',
                                                  message=util.sanitize_text(message),
                                                  status='error'))
     ids = util.listify(id)
     message = "Purged %d roles: " % len(ids)
     for role_id in ids:
         role = get_role(trans, role_id)
         if not role.deleted:
             message = "Role '%s' has not been deleted, so it cannot be purged." % role.name
             trans.response.send_redirect(web.url_for(controller='admin',
                                                      action='roles',
                                                      message=util.sanitize_text(message),
                                                      status='error'))
         # Delete UserRoleAssociations
         for ura in role.users:
             user = trans.sa_session.query(trans.app.model.User).get(ura.user_id)
             # Delete DefaultUserPermissions for associated users
             for dup in user.default_permissions:
                 if role == dup.role:
                     trans.sa_session.delete(dup)
             # Delete DefaultHistoryPermissions for associated users
             for history in user.histories:
                 for dhp in history.default_permissions:
                     if role == dhp.role:
                         trans.sa_session.delete(dhp)
             trans.sa_session.delete(ura)
         # Delete GroupRoleAssociations
         for gra in role.groups:
             trans.sa_session.delete(gra)
         # Delete DatasetPermissionss
         for dp in role.dataset_actions:
             trans.sa_session.delete(dp)
         trans.sa_session.flush()
         message += " %s " % role.name
     trans.response.send_redirect(web.url_for(controller='admin',
                                              action='roles',
                                              message=util.sanitize_text(message),
                                              status='done'))
Пример #13
0
 def undelete_category(self, trans, **kwd):
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         undeleted_categories = ""
         for category_id in ids:
             category = suc.get_category(trans, category_id)
             if category.deleted:
                 category.deleted = False
                 trans.sa_session.add(category)
                 trans.sa_session.flush()
                 count += 1
                 undeleted_categories += " %s" % category.name
         message = "Undeleted %d categories: %s" % (count,
                                                    undeleted_categories)
     else:
         message = "No category ids received for undeleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #14
0
 def delete_repository_metadata(self, trans, **kwd):
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         for repository_metadata_id in ids:
             repository_metadata = suc.get_repository_metadata_by_id(
                 trans, repository_metadata_id)
             trans.sa_session.delete(repository_metadata)
             trans.sa_session.flush()
             count += 1
         if count:
             message = "Deleted %d repository metadata %s" % (
                 count, inflector.cond_plural(len(ids), "record"))
     else:
         message = "No repository metadata ids received for deleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='browse_repository_metadata',
                     message=util.sanitize_text(message),
                     status=status))
Пример #15
0
 def undelete_category(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         undeleted_categories = ""
         for category_id in ids:
             category = suc.get_category(trans.app, category_id)
             if category.deleted:
                 category.deleted = False
                 trans.sa_session.add(category)
                 trans.sa_session.flush()
                 # Update the Tool Shed's repository registry.
                 trans.app.repository_registry.add_category_entry(category)
                 count += 1
                 undeleted_categories += " %s" % category.name
         message = "Undeleted %d categories: %s" % (
             count, escape(undeleted_categories))
     else:
         message = "No category ids received for undeleting."
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #16
0
    def user_per_month(self, trans, **kwd):
        params = util.Params(kwd)
        message = ''

        email = util.restore_text(params.get('email', ''))
        specs = sorter('date', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        q = sa.select(
            (self.select_month(model.Job.table.c.create_time).label('date'),
             sa.func.count(model.Job.table.c.id).label('total_jobs')),
            whereclause=sa.and_(
                model.Job.table.c.session_id == model.GalaxySession.table.c.id,
                model.GalaxySession.table.c.user_id == model.User.table.c.id,
                model.User.table.c.email == email),
            from_obj=[sa.join(model.Job.table, model.User.table)],
            group_by=self.group_by_month(model.Job.table.c.create_time),
            order_by=[_order])
        jobs = []
        for row in q.execute():
            jobs.append((row.date.strftime("%Y-%m"), row.total_jobs,
                         row.date.strftime("%B"), row.date.strftime("%Y")))
        return trans.fill_template('/webapps/reports/jobs_user_per_month.mako',
                                   order=order,
                                   arrow=arrow,
                                   sort_id=sort_id,
                                   id=kwd.get('id'),
                                   email=util.sanitize_text(email),
                                   jobs=jobs,
                                   message=message)
 def mark_category_deleted( self, trans, **kwd ):
     # TODO: We should probably eliminate the Category.deleted column since it really makes no
     # sense to mark a category as deleted (category names and descriptions can be changed instead).
     # If we do this, and the following 2 methods can be eliminated.
     message = kwd.get( 'message', ''  )
     status = kwd.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         ids = util.listify( id )
         message = "Deleted %d categories: " % len( ids )
         for category_id in ids:
             category = suc.get_category( trans.app, category_id )
             category.deleted = True
             trans.sa_session.add( category )
             trans.sa_session.flush()
             # Update the Tool Shed's repository registry.
             trans.app.repository_registry.remove_category_entry( category )
             message += " %s " % category.name
     else:
         message = "No category ids received for deleting."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='manage_categories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
Пример #18
0
 def undelete_category(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     id = kwd.get("id", None)
     if id:
         ids = util.listify(id)
         count = 0
         undeleted_categories = ""
         for category_id in ids:
             category = suc.get_category(trans.app, category_id)
             if category.deleted:
                 category.deleted = False
                 trans.sa_session.add(category)
                 trans.sa_session.flush()
                 # Update the Tool Shed's repository registry.
                 trans.app.repository_registry.add_category_entry(category)
                 count += 1
                 undeleted_categories += " %s" % category.name
         message = "Undeleted %d categories: %s" % (count, escape(undeleted_categories))
     else:
         message = "No category ids received for undeleting."
     trans.response.send_redirect(
         web.url_for(
             controller="admin", action="manage_categories", message=util.sanitize_text(message), status="done"
         )
     )
Пример #19
0
 def delete_repository_metadata(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     status = kwd.get("status", "done")
     id = kwd.get("id", None)
     if id:
         ids = util.listify(id)
         count = 0
         for repository_metadata_id in ids:
             repository_metadata = metadata_util.get_repository_metadata_by_id(trans.app, repository_metadata_id)
             trans.sa_session.delete(repository_metadata)
             trans.sa_session.flush()
             count += 1
         if count:
             message = "Deleted %d repository metadata %s" % (count, inflector.cond_plural(len(ids), "record"))
     else:
         message = "No repository metadata ids received for deleting."
         status = "error"
     trans.response.send_redirect(
         web.url_for(
             controller="admin",
             action="browse_repository_metadata",
             message=util.sanitize_text(message),
             status=status,
         )
     )
 def purge_category( self, trans, **kwd ):
     # This method should only be called for a Category that has previously been deleted.
     # Purging a deleted Category deletes all of the following from the database:
     # - RepoitoryCategoryAssociations where category_id == Category.id
     message = kwd.get( 'message', ''  )
     status = kwd.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         ids = util.listify( id )
         count = 0
         purged_categories = ""
         message = "Purged %d categories: " % len( ids )
         for category_id in ids:
             category = suc.get_category( trans.app, category_id )
             if category.deleted:
                 # Delete RepositoryCategoryAssociations
                 for rca in category.repositories:
                     trans.sa_session.delete( rca )
                 trans.sa_session.flush()
                 purged_categories += " %s " % category.name
         message = "Purged %d categories: %s" % ( count, purged_categories )
     else:
         message = "No category ids received for purging."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='manage_categories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
 def undelete_category( self, trans, **kwd ):
     message = kwd.get( 'message', ''  )
     status = kwd.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         ids = util.listify( id )
         count = 0
         undeleted_categories = ""
         for category_id in ids:
             category = suc.get_category( trans.app, category_id )
             if category.deleted:
                 category.deleted = False
                 trans.sa_session.add( category )
                 trans.sa_session.flush()
                 # Update the Tool Shed's repository registry.
                 trans.app.repository_registry.add_category_entry( category )
                 count += 1
                 undeleted_categories += " %s" % category.name
         message = "Undeleted %d categories: %s" % ( count, undeleted_categories )
     else:
         message = "No category ids received for undeleting."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='manage_categories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
Пример #22
0
 def user_per_month(self, trans, **kwd):
     params = util.Params(kwd)
     message = ''
     specs = sorter('date', kwd)
     sort_id = specs.sort_id
     order = specs.order
     arrow = specs.arrow
     _order = specs.exc_order
     email = util.restore_text(params.get('email', ''))
     user_id = trans.security.decode_id(params.get('id', ''))
     q = sa.select(
         (self.select_month(
             model.StoredWorkflow.table.c.create_time).label('date'),
          sa.func.count(
              model.StoredWorkflow.table.c.id).label('total_workflows')),
         whereclause=model.StoredWorkflow.table.c.user_id == user_id,
         from_obj=[model.StoredWorkflow.table],
         group_by=self.group_by_month(
             model.StoredWorkflow.table.c.create_time),
         order_by=[_order])
     workflows = []
     for row in q.execute():
         workflows.append(
             (row.date.strftime("%Y-%m"), row.total_workflows,
              row.date.strftime("%B"), row.date.strftime("%Y")))
     return trans.fill_template(
         '/webapps/reports/workflows_user_per_month.mako',
         email=util.sanitize_text(email),
         order=order,
         arrow=arrow,
         sort_id=sort_id,
         workflows=workflows,
         message=message)
Пример #23
0
 def undelete_repository( self, trans, **kwd ):
     params = util.Params( kwd )
     message = util.restore_text( params.get( 'message', ''  ) )
     status = params.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id.
         ids = util.listify( id )
         count = 0
         undeleted_repositories = ""
         for repository_id in ids:
             repository = suc.get_repository_in_tool_shed( trans, repository_id )
             if repository.deleted:
                 repository.deleted = False
                 trans.sa_session.add( repository )
                 trans.sa_session.flush()
                 count += 1
                 undeleted_repositories += " %s" % repository.name
         if count:
             message = "Undeleted %d %s: %s" % ( count, inflector.cond_plural( count, "repository" ), undeleted_repositories )
         else:
             message = "No selected repositories were marked deleted, so they could not be undeleted."
     else:
         message = "No repository ids received for undeleting."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='browse_repositories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
Пример #24
0
    def user_per_month(self, trans, **kwd):
        params = util.Params(kwd)
        message = ''
        specs = sorter('date', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        email = util.restore_text(params.get('email', ''))
        user_id = trans.security.decode_id(params.get('id', ''))

        q = sa.select(
            (self.select_month(
                model.StoredWorkflow.table.c.create_time).label('date'),
             sa.func.count(
                 model.StoredWorkflow.table.c.id).label('total_workflows')),
            whereclause=model.StoredWorkflow.table.c.user_id == user_id,
            from_obj=[model.StoredWorkflow.table],
            group_by=self.group_by_month(
                model.StoredWorkflow.table.c.create_time),
            order_by=[_order])

        all_workflows_user_month = sa.select(
            (self.select_day(
                model.StoredWorkflow.table.c.create_time).label('date'),
             model.StoredWorkflow.table.c.id),
            whereclause=model.StoredWorkflow.table.c.user_id == user_id,
            from_obj=[model.StoredWorkflow.table])

        trends = dict()
        for workflow in all_workflows_user_month.execute():
            workflow_day = int(workflow.date.strftime("%-d")) - 1
            workflow_month = int(workflow.date.strftime("%-m"))
            workflow_month_name = workflow.date.strftime("%B")
            workflow_year = workflow.date.strftime("%Y")
            key = str(workflow_month_name + workflow_year)

            try:
                trends[key][workflow_day] += 1
            except KeyError:
                workflow_year = int(workflow_year)
                wday, day_range = calendar.monthrange(workflow_year,
                                                      workflow_month)
                trends[key] = [0] * day_range
                trends[key][workflow_day] += 1

        workflows = []
        for row in q.execute():
            workflows.append(
                (row.date.strftime("%Y-%m"), row.total_workflows,
                 row.date.strftime("%B"), row.date.strftime("%Y")))
        return trans.fill_template(
            '/webapps/reports/workflows_user_per_month.mako',
            email=util.sanitize_text(email),
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            trends=trends,
            workflows=workflows,
            message=message)
Пример #25
0
 def delete_repository( self, trans, **kwd ):
     message = kwd.get( 'message', ''  )
     status = kwd.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         # Deleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. 
         ids = util.listify( id )
         count = 0
         deleted_repositories = ""
         for repository_id in ids:
             repository = suc.get_repository_in_tool_shed( trans, repository_id )
             if repository:
                 if not repository.deleted:
                     # Mark all installable repository_metadata records as not installable.
                     for repository_metadata in repository.downloadable_revisions:
                         repository_metadata.downloadable = False
                         trans.sa_session.add( repository_metadata )
                     repository.deleted = True
                     trans.sa_session.add( repository )
                     trans.sa_session.flush()
                     count += 1
                     deleted_repositories += " %s " % repository.name
         if count:
             message = "Deleted %d %s: %s" % ( count, inflector.cond_plural( len( ids ), "repository" ), deleted_repositories )
         else:
             message = "All selected repositories were already marked deleted."
     else:
         message = "No repository ids received for deleting."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='browse_repositories',
                                                message=util.sanitize_text( message ),
                                                status=status ) )
Пример #26
0
 def user_per_month(self, trans, **kwd):
     params = util.Params(kwd)
     message = ''
     email = util.restore_text(params.get('email', ''))
     user_id = trans.security.decode_id(params.get('id', ''))
     q = sa.select((sa.func.date_trunc(
         'month', sa.func.date(
             model.Request.table.c.create_time)).label('date'),
                    sa.func.count(model.Request.table.c.id).label('total')),
                   whereclause=model.Request.table.c.user_id == user_id,
                   from_obj=[model.Request.table],
                   group_by=[
                       sa.func.date_trunc(
                           'month',
                           sa.func.date(model.Request.table.c.create_time))
                   ],
                   order_by=[sa.desc('date')])
     requests = []
     for row in q.execute():
         requests.append((row.date.strftime("%Y-%m"), row.total,
                          row.date.strftime("%B"), row.date.strftime("%Y")))
     return trans.fill_template(
         '/webapps/reports/requests_user_per_month.mako',
         email=util.sanitize_text(email),
         requests=requests,
         message=message)
Пример #27
0
    def user_per_month( self, trans, **kwd ):
        params = util.Params( kwd )
        message = ''

        email = util.restore_text( params.get( 'email', '' ) )
        specs = sorter( 'date', kwd )
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        q = sa.select( ( self.select_month( model.Job.table.c.create_time ).label( 'date' ),
                         sa.func.count( model.Job.table.c.id ).label( 'total_jobs' ) ),
                       whereclause=sa.and_( model.Job.table.c.session_id == model.GalaxySession.table.c.id,
                                            model.GalaxySession.table.c.user_id == model.User.table.c.id,
                                            model.User.table.c.email == email ),
                       from_obj=[ sa.join( model.Job.table, model.User.table ) ],
                       group_by=self.group_by_month( model.Job.table.c.create_time ),
                       order_by=[ _order ] )
        jobs = []
        for row in q.execute():
            jobs.append( ( row.date.strftime( "%Y-%m" ),
                           row.total_jobs,
                           row.date.strftime( "%B" ),
                           row.date.strftime( "%Y" ) ) )
        return trans.fill_template( '/webapps/reports/jobs_user_per_month.mako',
                                    order=order,
                                    arrow=arrow,
                                    sort_id=sort_id,
                                    id=kwd.get('id'),
                                    email=util.sanitize_text( email ),
                                    jobs=jobs, message=message )
Пример #28
0
 def user_per_month( self, trans, **kwd ):
     params = util.Params( kwd )
     message = ''
     specs = sorter( 'date', kwd )
     sort_id = specs.sort_id
     order = specs.order
     arrow = specs.arrow
     _order = specs.exc_order
     email = util.restore_text( params.get( 'email', '' ) )
     user_id = trans.security.decode_id( params.get( 'id', '' ) )
     q = sa.select( ( self.select_month( model.StoredWorkflow.table.c.create_time ).label( 'date' ),
                      sa.func.count( model.StoredWorkflow.table.c.id ).label( 'total_workflows' ) ),
                    whereclause=model.StoredWorkflow.table.c.user_id == user_id,
                    from_obj=[ model.StoredWorkflow.table ],
                    group_by=self.group_by_month( model.StoredWorkflow.table.c.create_time ),
                    order_by=[ _order ] )
     workflows = []
     for row in q.execute():
         workflows.append( ( row.date.strftime( "%Y-%m" ),
                             row.total_workflows,
                             row.date.strftime( "%B" ),
                             row.date.strftime( "%Y" ) ) )
     return trans.fill_template( '/webapps/reports/workflows_user_per_month.mako',
                                 email=util.sanitize_text( email ),
                                 order=order,
                                 arrow=arrow,
                                 sort_id=sort_id,
                                 workflows=workflows,
                                 message=message )
 def mark_category_deleted(self, trans, **kwd):
     # TODO: We should probably eliminate the Category.deleted column since it really makes no
     # sense to mark a category as deleted (category names and descriptions can be changed instead).
     # If we do this, and the following 2 methods can be eliminated.
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         message = "Deleted %d categories: " % len(ids)
         for category_id in ids:
             category = suc.get_category(trans.app, category_id)
             category.deleted = True
             trans.sa_session.add(category)
             trans.sa_session.flush()
             # Update the Tool Shed's repository registry.
             trans.app.repository_registry.remove_category_entry(category)
             message += " %s " % category.name
     else:
         message = "No category ids received for deleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #30
0
 def undelete_repository(self, trans, **kwd):
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id.
         ids = util.listify(id)
         count = 0
         undeleted_repositories = ""
         for repository_id in ids:
             repository = suc.get_repository_in_tool_shed(
                 trans, repository_id)
             if repository.deleted:
                 repository.deleted = False
                 trans.sa_session.add(repository)
                 trans.sa_session.flush()
                 count += 1
                 undeleted_repositories += " %s" % repository.name
         if count:
             message = "Undeleted %d %s: %s" % (
                 count, inflector.cond_plural(
                     count, "repository"), undeleted_repositories)
         else:
             message = "No selected repositories were marked deleted, so they could not be undeleted."
     else:
         message = "No repository ids received for undeleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='browse_repositories',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #31
0
 def recalculate_user_disk_usage( self, trans, **kwd ):
     user_id = kwd.get( 'id', None )
     user = trans.sa_session.query( trans.model.User ).get( trans.security.decode_id( user_id ) )
     if not user:
         return trans.show_error_message( "User not found for id (%s)" % sanitize_text( str( user_id ) ) )
     current = user.get_disk_usage()
     user.calculate_and_set_disk_usage()
     new = user.get_disk_usage()
     if new in ( current, None ):
         message = 'Usage is unchanged at %s.' % nice_size( current )
     else:
         message = 'Usage has changed by %s to %s.' % ( nice_size( new - current ), nice_size( new )  )
     return trans.response.send_redirect( web.url_for( controller='admin',
                                                       action='users',
                                                       message=sanitize_text( message ),
                                                       status='info' ) )
Пример #32
0
 def purge_category(self, trans, **kwd):
     # This method should only be called for a Category that has previously been deleted.
     # Purging a deleted Category deletes all of the following from the database:
     # - RepoitoryCategoryAssociations where category_id == Category.id
     message = escape(kwd.get('message', ''))
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         purged_categories = ""
         message = "Purged %d categories: " % len(ids)
         for category_id in ids:
             category = suc.get_category(trans.app, category_id)
             if category.deleted:
                 # Delete RepositoryCategoryAssociations
                 for rca in category.repositories:
                     trans.sa_session.delete(rca)
                 trans.sa_session.flush()
                 purged_categories += " %s " % category.name
         message = "Purged %d categories: %s" % (count,
                                                 escape(purged_categories))
     else:
         message = "No category ids received for purging."
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #33
0
 def user_per_month(self, trans, **kwd):
     params = util.Params(kwd)
     message = ''
     email = util.restore_text(params.get('email', ''))
     q = sa.select(
         (sa.func.date_trunc(
             'month', sa.func.date(
                 model.Job.table.c.create_time)).label('date'),
          sa.func.count(model.Job.table.c.id).label('total_jobs')),
         whereclause=sa.and_(
             model.Job.table.c.session_id == model.GalaxySession.table.c.id,
             model.GalaxySession.table.c.user_id == model.User.table.c.id,
             model.User.table.c.email == email),
         from_obj=[sa.join(model.Job.table, model.User.table)],
         group_by=[
             sa.func.date_trunc('month',
                                sa.func.date(model.Job.table.c.create_time))
         ],
         order_by=[sa.desc('date')])
     jobs = []
     for row in q.execute():
         jobs.append((row.date.strftime("%Y-%m"), row.total_jobs,
                      row.date.strftime("%B"), row.date.strftime("%Y")))
     return trans.fill_template('/webapps/reports/jobs_user_per_month.mako',
                                email=util.sanitize_text(email),
                                jobs=jobs,
                                message=message)
Пример #34
0
 def upload_empty( self, trans, controller, library_id, folder_id, err_code, err_msg ):
     msg = err_code + err_msg
     return trans.response.send_redirect( web.url_for( controller=controller,
                                                       action='library_dataset_dataset_association',
                                                       library_id=library_id,
                                                       folder_id=folder_id,
                                                       msg=util.sanitize_text( msg ),
                                                       messagetype='error' ) )
Пример #35
0
 def purge_library( self, trans, **kwd ):
     # TODO: change this function to purge_library_item, behaving similar to delete_library_item
     # assuming we want the ability to purge libraries.
     # This function is currently only used by the functional tests.
     params = util.Params( kwd )
     library = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( params.id ) )
     def purge_folder( library_folder ):
         for lf in library_folder.folders:
             purge_folder( lf )
         trans.sa_session.refresh( library_folder )
         for library_dataset in library_folder.datasets:
             trans.sa_session.refresh( library_dataset )
             ldda = library_dataset.library_dataset_dataset_association
             if ldda:
                 trans.sa_session.refresh( ldda )
                 dataset = ldda.dataset
                 trans.sa_session.refresh( dataset )
                 # If the dataset is not associated with any additional undeleted folders, then we can delete it.
                 # We don't set dataset.purged to True here because the cleanup_datasets script will do that for
                 # us, as well as removing the file from disk.
                 #if not dataset.deleted and len( dataset.active_library_associations ) <= 1: # This is our current ldda
                 dataset.deleted = True
                 ldda.deleted = True
                 trans.sa_session.add_all( ( dataset, ldda ) )
             library_dataset.deleted = True
             trans.sa_session.add( library_dataset )
         library_folder.deleted = True
         library_folder.purged = True
         trans.sa_session.add( library_folder )
         trans.sa_session.flush()
     if not library.deleted:
         message = "Library '%s' has not been marked deleted, so it cannot be purged" % ( library.name )
         return trans.response.send_redirect( web.url_for( controller='library_admin',
                                                           action='browse_libraries',
                                                           message=util.sanitize_text( message ),
                                                           status='error' ) )
     else:
         purge_folder( library.root_folder )
         library.purged = True
         trans.sa_session.add( library )
         trans.sa_session.flush()
         message = "Library '%s' and all of its contents have been purged, datasets will be removed from disk via the cleanup_datasets script" % library.name
         return trans.response.send_redirect( web.url_for( controller='library_admin',
                                                           action='browse_libraries',
                                                           message=util.sanitize_text( message ),
                                                           status='done' ) )   
Пример #36
0
 def purge_quota( self, trans, **kwd ):
     quota, params = self._quota_op( trans, True, self._purge_quota, kwd, listify=True )
     if not quota:
         return
     return trans.response.send_redirect( web.url_for( controller='admin',
                                                       action='quotas',
                                                       webapp=params.webapp,
                                                       message=sanitize_text( params.message ),
                                                       status='error' ) )
Пример #37
0
    def user_per_month(self, trans, **kwd):
        params = util.Params(kwd)
        message = ''

        email = util.restore_text(params.get('email', ''))
        specs = sorter('date', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order

        q = sa.select(
            (self.select_month(model.Job.table.c.create_time).label('date'),
             sa.func.count(model.Job.table.c.id).label('total_jobs')),
            whereclause=model.User.table.c.email == email,
            from_obj=[sa.join(model.Job.table, model.User.table)],
            group_by=self.group_by_month(model.Job.table.c.create_time),
            order_by=[_order])

        all_jobs_per_user = sa.select(
            (model.Job.table.c.create_time.label('date'),
             model.Job.table.c.id.label('job_id')),
            whereclause=sa.and_(model.User.table.c.email == email),
            from_obj=[sa.join(model.Job.table, model.User.table)])

        trends = dict()
        for job in all_jobs_per_user.execute():
            job_day = int(job.date.strftime("%-d")) - 1
            job_month = int(job.date.strftime("%-m"))
            job_month_name = job.date.strftime("%B")
            job_year = job.date.strftime("%Y")
            key = str(job_month_name + job_year)

            try:
                trends[key][job_day] += 1
            except KeyError:
                job_year = int(job_year)
                wday, day_range = calendar.monthrange(job_year, job_month)
                trends[key] = [0] * day_range
                trends[key][job_day] += 1

        jobs = []
        for row in q.execute():
            jobs.append((row.date.strftime("%Y-%m"), row.total_jobs,
                         row.date.strftime("%B"), row.date.strftime("%Y")))
        return trans.fill_template('/webapps/reports/jobs_user_per_month.mako',
                                   order=order,
                                   arrow=arrow,
                                   sort_id=sort_id,
                                   id=kwd.get('id'),
                                   trends=trends,
                                   email=util.sanitize_text(email),
                                   jobs=jobs,
                                   message=message)
Пример #38
0
    def user_per_month(self, trans, **kwd):
        params = util.Params(kwd)
        message = ''

        email = util.restore_text(params.get('email', ''))
        specs = sorter('date', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order

        q = sa.select((self.select_month(model.Job.table.c.create_time).label('date'),
                       sa.func.count(model.Job.table.c.id).label('total_jobs')),
                      whereclause=model.User.table.c.email == email,
                      from_obj=[sa.join(model.Job.table, model.User.table)],
                      group_by=self.group_by_month(model.Job.table.c.create_time),
                      order_by=[_order])

        all_jobs_per_user = sa.select((model.Job.table.c.create_time.label('date'),
                                       model.Job.table.c.id.label('job_id')),
                                      whereclause=sa.and_(model.User.table.c.email == email),
                                      from_obj=[sa.join(model.Job.table, model.User.table)])

        trends = dict()
        for job in all_jobs_per_user.execute():
            job_day = int(job.date.strftime("%-d")) - 1
            job_month = int(job.date.strftime("%-m"))
            job_month_name = job.date.strftime("%B")
            job_year = job.date.strftime("%Y")
            key = str(job_month_name + job_year)

            try:
                trends[key][job_day] += 1
            except KeyError:
                job_year = int(job_year)
                wday, day_range = calendar.monthrange(job_year, job_month)
                trends[key] = [0] * day_range
                trends[key][job_day] += 1

        jobs = []
        for row in q.execute():
            jobs.append((row.date.strftime("%Y-%m"),
                         row.total_jobs,
                         row.date.strftime("%B"),
                         row.date.strftime("%Y")))
        return trans.fill_template('/webapps/reports/jobs_user_per_month.mako',
                                   order=order,
                                   arrow=arrow,
                                   sort_id=sort_id,
                                   id=kwd.get('id'),
                                   trends=trends,
                                   email=util.sanitize_text(email),
                                   jobs=jobs, message=message)
Пример #39
0
 def create_role(self, trans, **kwd):
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     name = util.restore_text(params.get('name', ''))
     description = util.restore_text(params.get('description', ''))
     in_users = util.listify(params.get('in_users', []))
     out_users = util.listify(params.get('out_users', []))
     in_groups = util.listify(params.get('in_groups', []))
     out_groups = util.listify(params.get('out_groups', []))
     create_group_for_role = params.get('create_group_for_role', '')
     create_group_for_role_checked = CheckboxField.is_checked(create_group_for_role)
     ok = True
     if params.get('create_role_button', False):
         if not name or not description:
             message = "Enter a valid name and a description."
             status = 'error'
             ok = False
         elif trans.sa_session.query(trans.app.model.Role).filter(trans.app.model.Role.table.c.name == name).first():
             message = "Role names must be unique and a role with that name already exists, so choose another name."
             status = 'error'
             ok = False
         else:
             # Create the role
             role, num_in_groups = trans.app.security_agent.create_role(
                 name, description, in_users, in_groups, create_group_for_role=create_group_for_role_checked)
             message = "Role '%s' has been created with %d associated users and %d associated groups.  " \
                 % (role.name, len(in_users), num_in_groups)
             if create_group_for_role_checked:
                 message += 'One of the groups associated with this role is the newly created group with the same name.'
             trans.response.send_redirect(web.url_for(controller='admin',
                                                      action='roles',
                                                      message=util.sanitize_text(message),
                                                      status='done'))
     if ok:
         for user in trans.sa_session.query(trans.app.model.User) \
                                     .filter(trans.app.model.User.table.c.deleted == false()) \
                                     .order_by(trans.app.model.User.table.c.email):
             out_users.append((user.id, user.email))
         for group in trans.sa_session.query(trans.app.model.Group) \
                                      .filter(trans.app.model.Group.table.c.deleted == false()) \
                                      .order_by(trans.app.model.Group.table.c.name):
             out_groups.append((group.id, group.name))
     return trans.fill_template('/webapps/tool_shed/admin/dataset_security/role/role_create.mako',
                                name=name,
                                description=description,
                                in_users=in_users,
                                out_users=out_users,
                                in_groups=in_groups,
                                out_groups=out_groups,
                                create_group_for_role_checked=create_group_for_role_checked,
                                message=message,
                                status=status)
 def manage_users_and_roles_for_group(self, trans, **kwd):
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     group = get_group(trans, params.id)
     if params.get('group_roles_users_edit_button', False):
         in_roles = [
             trans.sa_session.query(trans.app.model.Role).get(x)
             for x in util.listify(params.in_roles)
         ]
         in_users = [
             trans.sa_session.query(trans.app.model.User).get(x)
             for x in util.listify(params.in_users)
         ]
         trans.app.security_agent.set_entity_group_associations(
             groups=[group], roles=in_roles, users=in_users)
         trans.sa_session.refresh(group)
         message += "Group '%s' has been updated with %d associated roles and %d associated users" % (
             group.name, len(in_roles), len(in_users))
         trans.response.send_redirect(
             web.url_for(controller='admin',
                         action='groups',
                         message=util.sanitize_text(message),
                         status=status))
     in_roles = []
     out_roles = []
     in_users = []
     out_users = []
     for role in trans.sa_session.query(trans.app.model.Role) \
                                 .filter(trans.app.model.Role.table.c.deleted == false()) \
                                 .order_by(trans.app.model.Role.table.c.name):
         if role in [x.role for x in group.roles]:
             in_roles.append((role.id, role.name))
         else:
             out_roles.append((role.id, role.name))
     for user in trans.sa_session.query(trans.app.model.User) \
                                 .filter(trans.app.model.User.table.c.deleted == false()) \
                                 .order_by(trans.app.model.User.table.c.email):
         if user in [x.user for x in group.users]:
             in_users.append((user.id, user.email))
         else:
             out_users.append((user.id, user.email))
     message += 'Group %s is currently associated with %d roles and %d users' % (
         group.name, len(in_roles), len(in_users))
     return trans.fill_template(
         '/webapps/tool_shed/admin/dataset_security/group/group.mako',
         group=group,
         in_roles=in_roles,
         out_roles=out_roles,
         in_users=in_users,
         out_users=out_users,
         message=message,
         status=status)
Пример #41
0
    def user_per_month( self, trans, **kwd ):
        params = util.Params( kwd )
        message = ''
        specs = sorter( 'date', kwd )
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        email = util.restore_text( params.get( 'email', '' ) )
        user_id = trans.security.decode_id( params.get( 'id', '' ) )

        q = sa.select( ( self.select_month( model.StoredWorkflow.table.c.create_time ).label( 'date' ),
                         sa.func.count( model.StoredWorkflow.table.c.id ).label( 'total_workflows' ) ),
                       whereclause=model.StoredWorkflow.table.c.user_id == user_id,
                       from_obj=[ model.StoredWorkflow.table ],
                       group_by=self.group_by_month( model.StoredWorkflow.table.c.create_time ),
                       order_by=[ _order ] )

        all_workflows_user_month = sa.select( ( self.select_day( model.StoredWorkflow.table.c.create_time ).label( 'date' ),
                                               model.StoredWorkflow.table.c.id ),
                                             whereclause=model.StoredWorkflow.table.c.user_id == user_id,
                                             from_obj=[ model.StoredWorkflow.table ] )

        trends = dict()
        for workflow in all_workflows_user_month.execute():
            workflow_day = int(workflow.date.strftime("%-d")) - 1
            workflow_month = int(workflow.date.strftime("%-m"))
            workflow_month_name = workflow.date.strftime("%B")
            workflow_year = workflow.date.strftime("%Y")
            key = str( workflow_month_name + workflow_year)

            try:
                trends[key][workflow_day] += 1
            except KeyError:
                workflow_year = int(workflow_year)
                wday, day_range = calendar.monthrange(workflow_year, workflow_month)
                trends[key] = [0] * day_range
                trends[key][workflow_day] += 1

        workflows = []
        for row in q.execute():
            workflows.append( ( row.date.strftime( "%Y-%m" ),
                                row.total_workflows,
                                row.date.strftime( "%B" ),
                                row.date.strftime( "%Y" ) ) )
        return trans.fill_template( '/webapps/reports/workflows_user_per_month.mako',
                                    email=util.sanitize_text( email ),
                                    order=order,
                                    arrow=arrow,
                                    sort_id=sort_id,
                                    trends=trends,
                                    workflows=workflows,
                                    message=message )
Пример #42
0
 def download_dataset_from_folder(self,
                                  trans,
                                  cntrller,
                                  obj_id,
                                  library_id=None,
                                  **kwd):
     """Catches the dataset id and displays file contents as directed"""
     # id must refer to a LibraryDatasetDatasetAssociation object
     ldda = trans.sa_session.query(
         trans.app.model.LibraryDatasetDatasetAssociation).get(obj_id)
     if not ldda.dataset:
         msg = 'Invalid LibraryDatasetDatasetAssociation id %s received for file downlaod' % str(
             obj_id)
         return trans.response.send_redirect(
             web.url_for(controller=cntrller,
                         action='browse_library',
                         obj_id=library_id,
                         msg=util.sanitize_text(msg),
                         messagetype='error'))
     mime = trans.app.datatypes_registry.get_mimetype_by_extension(
         ldda.extension.lower())
     trans.response.set_content_type(mime)
     fStat = os.stat(ldda.file_name)
     trans.response.headers['Content-Length'] = int(fStat.st_size)
     valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     fname = ldda.name
     fname = ''.join(c in valid_chars and c or '_' for c in fname)[0:150]
     trans.response.headers[
         "Content-Disposition"] = "attachment; filename=GalaxyLibraryDataset-%s-[%s]" % (
             str(obj_id), fname)
     try:
         return open(ldda.file_name)
     except:
         msg = 'This dataset contains no content'
         return trans.response.send_redirect(
             web.url_for(controller=cntrller,
                         action='browse_library',
                         obj_id=library_id,
                         msg=util.sanitize_text(msg),
                         messagetype='error'))
Пример #43
0
 def _quota_op(self, trans, do_op, op_method, kwd, listify=False):
     params = self.get_quota_params(kwd)
     if listify:
         quota = []
         messages = []
         for id in galaxy.util.listify(params.id):
             try:
                 quota.append(self.get_quota(trans, id))
             except MessageException as e:
                 messages.append(str(e))
         if messages:
             return None, trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='quotas',
                             webapp=params.webapp,
                             message=sanitize_text(', '.join(messages)),
                             status='error'))
     else:
         try:
             quota = self.get_quota(trans, params.id, deleted=False)
         except MessageException as e:
             return None, trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='quotas',
                             webapp=params.webapp,
                             message=sanitize_text(str(e)),
                             status='error'))
     if do_op is True or (do_op is not False and params.get(do_op, False)):
         try:
             message = op_method(quota, params)
             return None, trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='quotas',
                             webapp=params.webapp,
                             message=sanitize_text(message),
                             status='done'))
         except MessageException as e:
             params.message = e.err_msg
             params.status = e.type
     return quota, params
Пример #44
0
 def create_quota( self, trans, **kwd ):
     params = self.get_quota_params( kwd )
     if params.get( 'create_quota_button', False ):
         try:
             quota, message = self._create_quota( params )
             return trans.response.send_redirect( web.url_for( controller='admin',
                                                               action='quotas',
                                                               webapp=params.webapp,
                                                               message=sanitize_text( message ),
                                                               status='done' ) )
         except MessageException, e:
             params.message = str( e )
             params.status = 'error'
Пример #45
0
 def undelete_quota(self, trans, **kwd):
     quota, params = self._quota_op(trans, True, self._undelete_quota, kwd, listify=True)
     if not quota:
         return
     return trans.response.send_redirect(
         web.url_for(
             controller="admin",
             action="quotas",
             webapp=params.webapp,
             message=sanitize_text(params.message),
             status="error",
         )
     )
Пример #46
0
 def create_quota( self, trans, **kwd ):
     params = self.get_quota_params( kwd )
     if params.get( 'create_quota_button', False ):
         try:
             quota, message = self._create_quota( params )
             return trans.response.send_redirect( web.url_for( controller='admin',
                                                               action='quotas',
                                                               webapp=params.webapp,
                                                               message=sanitize_text( message ),
                                                               status='done' ) )
         except MessageException, e:
             params.message = str( e )
             params.status = 'error'
Пример #47
0
 def _quota_op( self, trans, do_op, op_method, kwd, listify=False ):
     params = self.get_quota_params( kwd )
     if listify:
         quota = []
         messages = []
         for id in galaxy.util.listify( params.id ):
             try:
                 quota.append( self.get_quota( trans, id ) )
             except MessageException as e:
                 messages.append( str( e ) )
         if messages:
             return None, trans.response.send_redirect( web.url_for( controller='admin',
                                                                     action='quotas',
                                                                     webapp=params.webapp,
                                                                     message=sanitize_text( ', '.join( messages ) ),
                                                                     status='error' ) )
     else:
         try:
             quota = self.get_quota( trans, params.id, deleted=False )
         except MessageException as e:
             return None, trans.response.send_redirect( web.url_for( controller='admin',
                                                                     action='quotas',
                                                                     webapp=params.webapp,
                                                                     message=sanitize_text( str( e ) ),
                                                                     status='error' ) )
     if do_op is True or ( do_op is not False and params.get( do_op, False ) ):
         try:
             message = op_method( quota, params )
             return None, trans.response.send_redirect( web.url_for( controller='admin',
                                                                     action='quotas',
                                                                     webapp=params.webapp,
                                                                     message=sanitize_text( message ),
                                                                     status='done' ) )
         except MessageException as e:
             params.message = e.err_msg
             params.status = e.type
     return quota, params
Пример #48
0
    def list(self, trans, **kwargs):
        """List all available histories"""
        current_history = trans.get_history()
        message = kwargs.get('message')
        status = kwargs.get('status')
        if 'operation' in kwargs:
            operation = kwargs['operation'].lower()
            history_ids = listify(kwargs.get('id', []))
            # Display no message by default
            status, message = None, None
            # Load the histories and ensure they all belong to the current user
            histories = []
            for history_id in history_ids:
                history = self.history_manager.get_owned(self.decode_id(history_id), trans.user, current_history=trans.history)
                if history:
                    # Ensure history is owned by current user
                    if history.user_id is not None and trans.user:
                        assert trans.user.id == history.user_id, "History does not belong to current user"
                    histories.append(history)
                else:
                    log.warning("Invalid history id '%r' passed to list", history_id)
            if histories:
                if operation == "switch":
                    status, message = self._list_switch(trans, histories)
                    # Take action to update UI to reflect history switch. If
                    # grid is using panels, it is standalone and hence a redirect
                    # to root is needed; if grid is not using panels, it is nested
                    # in the main Galaxy UI and refreshing the history frame
                    # is sufficient.
                    use_panels = kwargs.get('use_panels', False) == 'True'
                    if use_panels:
                        return trans.response.send_redirect(url_for("/"))
                    else:
                        kwargs['refresh_frames'] = ['history']
                elif operation in ("delete", "delete permanently"):
                    status, message = self._list_delete(trans, histories, purge=(operation == "delete permanently"))
                    if current_history in histories:
                        # Deleted the current history, so a new, empty history was
                        # created automatically, and we need to refresh the history frame
                        kwargs['refresh_frames'] = ['history']
                elif operation == "undelete":
                    status, message = self._list_undelete(trans, histories)

                trans.sa_session.flush()
        # Render the list view
        if message and status:
            kwargs['message'] = sanitize_text(message)
            kwargs['status'] = status
        return self.stored_list_grid(trans, **kwargs)
 def undelete_repository(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id.
         ids = util.listify(id)
         count = 0
         undeleted_repositories = ""
         for repository_id in ids:
             repository = suc.get_repository_in_tool_shed(
                 trans.app, repository_id)
             if repository:
                 if repository.deleted:
                     # Inspect all repository_metadata records to determine those that are installable, and mark
                     # them accordingly.
                     for repository_metadata in repository.metadata_revisions:
                         metadata = repository_metadata.metadata
                         if metadata:
                             if metadata_util.is_downloadable(metadata):
                                 repository_metadata.downloadable = True
                                 trans.sa_session.add(repository_metadata)
                     # Mark the repository admin role as not deleted.
                     repository_admin_role = repository.admin_role
                     if repository_admin_role is not None:
                         repository_admin_role.deleted = False
                         trans.sa_session.add(repository_admin_role)
                     repository.deleted = False
                     trans.sa_session.add(repository)
                     trans.sa_session.flush()
                     if not repository.deprecated:
                         # Update the repository registry.
                         trans.app.repository_registry.add_entry(repository)
                     count += 1
                     undeleted_repositories += " %s" % repository.name
         if count:
             message = "Undeleted %d %s: %s" % (
                 count, inflector.cond_plural(
                     count, "repository"), undeleted_repositories)
         else:
             message = "No selected repositories were marked deleted, so they could not be undeleted."
     else:
         message = "No repository ids received for undeleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='browse_repositories',
                     message=util.sanitize_text(message),
                     status='done'))
 def purge_group(self, trans, **kwd):
     # This method should only be called for a Group that has previously been deleted.
     # Purging a deleted Group simply deletes all UserGroupAssociations and GroupRoleAssociations.
     id = kwd.get('id', None)
     if not id:
         message = "No group ids received for purging"
         trans.response.send_redirect(
             web.url_for(controller='admin',
                         action='groups',
                         message=util.sanitize_text(message),
                         status='error'))
     ids = util.listify(id)
     message = "Purged %d groups: " % len(ids)
     for group_id in ids:
         group = get_group(trans, group_id)
         if not group.deleted:
             # We should never reach here, but just in case there is a bug somewhere...
             message = "Group '%s' has not been deleted, so it cannot be purged." % group.name
             trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='groups',
                             message=util.sanitize_text(message),
                             status='error'))
         # Delete UserGroupAssociations
         for uga in group.users:
             trans.sa_session.delete(uga)
         # Delete GroupRoleAssociations
         for gra in group.roles:
             trans.sa_session.delete(gra)
         trans.sa_session.flush()
         message += " %s " % group.name
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='groups',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #51
0
 def create_form(self, trans, payload=None, **kwd):
     if trans.request.method == 'GET':
         fd_types = sorted(trans.app.model.FormDefinition.types.items())
         return {
             'title'         : 'Create new form',
             'submit_title'  : 'Create',
             'inputs'        : [{
                 'name'    : 'name',
                 'label'   : 'Name'
             }, {
                 'name'    : 'desc',
                 'label'   : 'Description'
             }, {
                 'name'    : 'type',
                 'type'    : 'select',
                 'options' : [('None', 'none')] + [(ft[1], ft[1]) for ft in fd_types],
                 'label'   : 'Type'
             }, {
                 'name'    : 'csv_file',
                 'label'   : 'Import from CSV',
                 'type'    : 'upload',
                 'help'    : 'Import fields from CSV-file with the following format: Label, Help, Type, Value, Options, Required=True/False.'
             }]
         }
     else:
         # csv-file format: label, helptext, type, default, selectlist, required '''
         csv_file = payload.get('csv_file')
         index = 0
         if csv_file:
             lines = csv_file.splitlines()
             for line in lines:
                 row = line.split(',')
                 if len(row) >= 6:
                     prefix = 'fields_%i|' % index
                     payload['%s%s' % (prefix, 'name')] = '%i_imported_field' % (index + 1)
                     payload['%s%s' % (prefix, 'label')] = row[0]
                     payload['%s%s' % (prefix, 'helptext')] = row[1]
                     payload['%s%s' % (prefix, 'type')] = row[2]
                     payload['%s%s' % (prefix, 'default')] = row[3]
                     payload['%s%s' % (prefix, 'selectlist')] = row[4].split(',')
                     payload['%s%s' % (prefix, 'required')] = row[5].lower() == 'true'
                 index = index + 1
         new_form, message = self.save_form_definition(trans, None, payload)
         if new_form is None:
             return self.message_exception(trans, message)
         imported = (' with %i imported fields' % index) if index > 0 else ''
         message = 'The form \'%s\' has been created%s.' % (payload.get('name'), imported)
         return {'message': util.sanitize_text(message)}
Пример #52
0
 def undelete_repository(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     id = kwd.get("id", None)
     if id:
         # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id.
         ids = util.listify(id)
         count = 0
         undeleted_repositories = ""
         for repository_id in ids:
             repository = suc.get_repository_in_tool_shed(trans.app, repository_id)
             if repository:
                 if repository.deleted:
                     # Inspect all repository_metadata records to determine those that are installable, and mark
                     # them accordingly.
                     for repository_metadata in repository.metadata_revisions:
                         metadata = repository_metadata.metadata
                         if metadata:
                             if metadata_util.is_downloadable(metadata):
                                 repository_metadata.downloadable = True
                                 trans.sa_session.add(repository_metadata)
                     # Mark the repository admin role as not deleted.
                     repository_admin_role = repository.admin_role
                     if repository_admin_role is not None:
                         repository_admin_role.deleted = False
                         trans.sa_session.add(repository_admin_role)
                     repository.deleted = False
                     trans.sa_session.add(repository)
                     trans.sa_session.flush()
                     if not repository.deprecated:
                         # Update the repository registry.
                         trans.app.repository_registry.add_entry(repository)
                     count += 1
                     undeleted_repositories += " %s" % repository.name
         if count:
             message = "Undeleted %d %s: %s" % (
                 count,
                 inflector.cond_plural(count, "repository"),
                 undeleted_repositories,
             )
         else:
             message = "No selected repositories were marked deleted, so they could not be undeleted."
     else:
         message = "No repository ids received for undeleting."
     trans.response.send_redirect(
         web.url_for(
             controller="admin", action="browse_repositories", message=util.sanitize_text(message), status="done"
         )
     )
Пример #53
0
 def create_form(self, trans, payload=None, **kwd):
     if trans.request.method == 'GET':
         fd_types = sorted(trans.app.model.FormDefinition.types.items())
         return {
             'title'         : 'Create new form',
             'submit_title'  : 'Create',
             'inputs'        : [{
                 'name'    : 'name',
                 'label'   : 'Name'
             }, {
                 'name'    : 'desc',
                 'label'   : 'Description'
             }, {
                 'name'    : 'type',
                 'type'    : 'select',
                 'options' : [('None', 'none')] + [(ft[1], ft[1]) for ft in fd_types],
                 'label'   : 'Type'
             }, {
                 'name'    : 'csv_file',
                 'label'   : 'Import from CSV',
                 'type'    : 'upload',
                 'help'    : 'Import fields from CSV-file with the following format: Label, Help, Type, Value, Options, Required=True/False.'
             }]
         }
     else:
         # csv-file format: label, helptext, type, default, selectlist, required '''
         csv_file = payload.get('csv_file')
         index = 0
         if csv_file:
             lines = csv_file.splitlines()
             for line in lines:
                 row = line.split(',')
                 if len(row) >= 6:
                     prefix = 'fields_%i|' % index
                     payload['%s%s' % (prefix, 'name')] = '%i_imported_field' % (index + 1)
                     payload['%s%s' % (prefix, 'label')] = row[0]
                     payload['%s%s' % (prefix, 'helptext')] = row[1]
                     payload['%s%s' % (prefix, 'type')] = row[2]
                     payload['%s%s' % (prefix, 'default')] = row[3]
                     payload['%s%s' % (prefix, 'selectlist')] = row[4].split(',')
                     payload['%s%s' % (prefix, 'required')] = row[5].lower() == 'true'
                 index = index + 1
         new_form, message = self.save_form_definition(trans, None, payload)
         if new_form is None:
             return self.message_exception(trans, message)
         imported = (' with %i imported fields' % index) if index > 0 else ''
         message = 'The form \'%s\' has been created%s.' % (payload.get('name'), imported)
         return {'message': util.sanitize_text(message)}
Пример #54
0
 def _quota_op( self, trans, do_op, op_method, kwd, listify=False ):
     params = self.get_quota_params( kwd )
     if listify:
         quota = []
         messages = []
         for id in galaxy.util.listify( params.id ):
             try:
                 quota.append( self.get_quota( trans, id ) )
             except MessageException, e:
                 messages.append( str( e ) )
         if messages:
             return None, trans.response.send_redirect( web.url_for( controller='admin',
                                                                     action='quotas',
                                                                     webapp=params.webapp,
                                                                     message=sanitize_text( ', '.join( messages ) ),
                                                                     status='error' ) )
Пример #55
0
 def _quota_op( self, trans, do_op, op_method, kwd, listify=False ):
     params = self.get_quota_params( kwd )
     if listify:
         quota = []
         messages = []
         for id in galaxy.util.listify( params.id ):
             try:
                 quota.append( self.get_quota( trans, id ) )
             except MessageException, e:
                 messages.append( str( e ) )
         if messages:
             return None, trans.response.send_redirect( web.url_for( controller='admin',
                                                                     action='quotas',
                                                                     webapp=params.webapp,
                                                                     message=sanitize_text( ', '.join( messages ) ),
                                                                     status='error' ) )
Пример #56
0
 def forms_list(self, trans, payload=None, **kwd):
     message = kwd.get('message', '')
     status = kwd.get('status', '')
     if 'operation' in kwd:
         id = kwd.get('id')
         if not id:
             return self.message_exception(trans, 'Invalid form id (%s) received.' % str(id))
         ids = util.listify(id)
         operation = kwd['operation'].lower()
         if operation == 'delete':
             message, status = self._delete_form(trans, ids)
         elif operation == 'undelete':
             message, status = self._undelete_form(trans, ids)
     if message and status:
         kwd['message'] = util.sanitize_text(message)
         kwd['status'] = status
     return self.forms_grid(trans, **kwd)