Ejemplo n.º 1
0
class ComponentGrid(grids.Grid):
    class NameColumn(grids.TextColumn):
        def get_value(self, trans, grid, component):
            return component.name

    class DescriptionColumn(grids.TextColumn):
        def get_value(self, trans, grid, component):
            return component.description

    title = "Repository review components"
    model_class = model.Component
    template = '/webapps/community/repository_review/grid.mako'
    default_sort_key = "name"
    columns = [
        NameColumn("Name",
                   key="Component.name",
                   link=(lambda item: dict(operation="edit", id=item.id)),
                   attach_popup=False),
        DescriptionColumn("Description",
                          key="Component.description",
                          attach_popup=False)
    ]
    default_filter = {}
    global_actions = [
        grids.GridAction(
            "Add new component",
            dict(controller='repository_review',
                 action='manage_components',
                 operation='create'))
    ]
    operations = []
    standard_filters = []
    num_rows_per_page = 50
    preserve_state = False
    use_paging = True
Ejemplo n.º 2
0
class PageListGrid( grids.Grid ):
    # Grid definition
    use_panels = True
    title = "Pages"
    model_class = model.Page
    default_filter = { "published" : "All"}
    default_sort_key = "-create_time"
    columns = [
        grids.TextColumn( "Title", key="title", model_class=model.Page, attach_popup=True, filterable="standard" ),
        PublicURLColumn( "Public URL" ),
        grids.GridColumn( "Published", key="published", format=format_bool, filterable="standard" ),
        grids.GridColumn( "Created", key="create_time", format=time_ago ),
        grids.GridColumn( "Last Updated", key="update_time", format=time_ago ),
    ]
    global_actions = [
        grids.GridAction( "Add new page", dict( action='create' ) )
    ]
    operations = [
        grids.GridOperation( "View", allow_multiple=False, url_args=dict( action='display') ),
        grids.GridOperation( "Edit name/id", allow_multiple=False, url_args=dict( action='edit') ),
        grids.GridOperation( "Edit content", allow_multiple=False, url_args=dict( action='edit_content') ),
        grids.GridOperation( "Delete" ),
        grids.GridOperation( "Publish", condition=( lambda item: not item.published ) ),
        grids.GridOperation( "Unpublish", condition=( lambda item: item.published ) ),
    ]
    def apply_default_filter( self, trans, query, **kwargs ):
        return query.filter_by( user=trans.user, deleted=False )
Ejemplo n.º 3
0
class FormsGrid( grids.Grid ):
    # Custom column types
    class NameColumn( grids.TextColumn ):
        def get_value(self, trans, grid, form):
            return form.latest_form.name
    class DescriptionColumn( grids.TextColumn ):
        def get_value(self, trans, grid, form):
            return form.latest_form.desc
    class TypeColumn( grids.TextColumn ):
        def get_value(self, trans, grid, form):
            return form.latest_form.type
    class DeletedColumn( grids.GridColumn ):
       def get_accepted_filters( self ):
           """ Returns a list of accepted filters for this column. """
           accepted_filter_labels_and_vals = { "active" : "False", "deleted" : "True", "all": "All" }
           accepted_filters = []
           for label, val in accepted_filter_labels_and_vals.items():
               args = { self.key: val }
               accepted_filters.append( grids.GridColumnFilter( label, args) )
           return accepted_filters
    # Grid definition
    title = "Forms"
    template = "admin/forms/grid.mako"
    model_class = model.FormDefinitionCurrent
    default_sort_key = "-create_time"
    num_rows_per_page = 50
    preserve_state = True
    use_paging = True
    default_filter = dict( deleted="False" )
    columns = [
        NameColumn( "Name", 
                    key="name", 
                    model_class=model.FormDefinition,
                    link=( lambda item: iff( item.deleted, None, dict( operation="view", id=item.id ) ) ),
                    attach_popup=True, 
                    filterable="advanced" ),
        DescriptionColumn( "Description",
                           key='desc',
                           model_class=model.FormDefinition,
                           filterable="advanced" ),
        TypeColumn( "Type" ),
        DeletedColumn( "Deleted", 
                       key="deleted", 
                       visible=False, 
                       filterable="advanced" )
    ]
    columns.append( grids.MulticolFilterColumn( "Search", 
                                                cols_to_filter=[ columns[0], columns[1] ], 
                                                key="free-text-search",
                                                visible=False,
                                                filterable="standard" ) )
    operations = [
        grids.GridOperation( "Edit", allow_multiple=False, condition=( lambda item: not item.deleted )  ),
        grids.GridOperation( "Delete", allow_multiple=True, condition=( lambda item: not item.deleted )  ),
        grids.GridOperation( "Undelete", condition=( lambda item: item.deleted ) ),    
    ]
    global_actions = [
        grids.GridAction( "Create new form", dict( controller='forms', 
                                                      action='new' ) )
    ]
Ejemplo n.º 4
0
class AdminRequestsGrid(RequestsGrid):
    class UserColumn(grids.TextColumn):
        def get_value(self, trans, grid, request):
            return escape(request.user.email)

    # Grid definition
    columns = [col for col in RequestsGrid.columns]
    columns.append(UserColumn("User", model_class=model.User, key='username'))
    operations = [operation for operation in RequestsGrid.operations]
    operations.append(
        grids.GridOperation("Edit",
                            allow_multiple=False,
                            condition=(lambda item: not item.deleted)))
    operations.append(
        grids.GridOperation(
            "Reject",
            allow_multiple=False,
            condition=(lambda item: not item.deleted and item.is_submitted)))
    operations.append(
        grids.GridOperation("Delete",
                            allow_multiple=True,
                            condition=(lambda item: not item.deleted)))
    operations.append(
        grids.GridOperation("Undelete", condition=(lambda item: item.deleted)))
    global_actions = [
        grids.GridAction(
            "Create new request",
            dict(controller='requests_common',
                 action='create_request',
                 cntrller='requests_admin'))
    ]
Ejemplo n.º 5
0
class FormsGrid(grids.Grid):
    # Custom column types
    class NameColumn(grids.TextColumn):
        def get_value(self, trans, grid, form):
            return escape(form.latest_form.name)

    class DescriptionColumn(grids.TextColumn):
        def get_value(self, trans, grid, form):
            return escape(form.latest_form.desc)

    class TypeColumn(grids.TextColumn):
        def get_value(self, trans, grid, form):
            return form.latest_form.type
    # Grid definition
    title = "Forms"
    template = "admin/forms/grid.mako"
    model_class = model.FormDefinitionCurrent
    default_sort_key = "-create_time"
    num_rows_per_page = 50
    preserve_state = True
    use_paging = True
    default_filter = dict(deleted="False")
    columns = [
        NameColumn("Name",
                   key="name",
                   model_class=model.FormDefinition,
                   link=(lambda item: iff(item.deleted, None, dict(operation="view_latest_form_definition",
                                                                   id=item.id))),
                   attach_popup=True,
                   filterable="advanced"),
        DescriptionColumn("Description",
                          key='desc',
                          model_class=model.FormDefinition,
                          filterable="advanced"),
        TypeColumn("Type"),
        grids.DeletedColumn("Deleted",
                            key="deleted",
                            visible=False,
                            filterable="advanced")
    ]
    columns.append(grids.MulticolFilterColumn("Search",
                                              cols_to_filter=[columns[0], columns[1]],
                                              key="free-text-search",
                                              visible=False,
                                              filterable="standard"))
    operations = [
        grids.GridOperation("Edit", allow_multiple=False, condition=(lambda item: not item.deleted)),
        grids.GridOperation("Delete", allow_multiple=True, condition=(lambda item: not item.deleted)),
        grids.GridOperation("Undelete", condition=(lambda item: item.deleted)),
    ]
    global_actions = [
        grids.GridAction("Create new form", dict(controller='forms', action='create_form_definition'))
    ]

    def build_initial_query(self, trans, **kwargs):
        return trans.sa_session.query(self.model_class).join(model.FormDefinition, self.model_class.latest_form_id == model.FormDefinition.id)
Ejemplo n.º 6
0
class LibraryListGrid( grids.Grid ):
    class NameColumn( grids.TextColumn ):
        def get_value( self, trans, grid, library ):
            return library.name
    class DescriptionColumn( grids.TextColumn ):
        def get_value( self, trans, grid, library ):
            if library.description:
                return library.description
            return ''
    class StatusColumn( grids.GridColumn ):
        def get_value( self, trans, grid, library ):
            if library.purged:
                return "purged"
            elif library.deleted:
                return "deleted"
            return ""
    # Grid definition
    title = "Data Libraries"
    model_class = model.Library
    template='/admin/library/grid.mako'
    default_sort_key = "name"
    columns = [
        NameColumn( "Data library name",
                    key="name",
                    link=( lambda library: dict( operation="browse", id=library.id ) ),
                    attach_popup=False,
                    filterable="advanced" ),
        DescriptionColumn( "Data library description",
                           key="description",
                           attach_popup=False,
                           filterable="advanced" ),
        grids.GridColumn( "Created", key="create_time", format=time_ago ),
        grids.GridColumn( "Last Updated", key="update_time", format=time_ago ),
        StatusColumn( "Status", attach_popup=False ),
        # Columns that are valid for filtering but are not visible.
        grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" )
    ]
    columns.append( grids.MulticolFilterColumn( "search dataset name, info, message, dbkey",
                                                cols_to_filter=[ columns[0], columns[1] ], 
                                                key="free-text-search",
                                                visible=False,
                                                filterable="standard" ) )
    global_actions = [
        grids.GridAction( "Create new data library", dict( controller='library_admin', action='create_library' ) )
    ]
    standard_filters = [
        grids.GridColumnFilter( "Active", args=dict( deleted=False ) ),
        grids.GridColumnFilter( "Deleted", args=dict( deleted=True, purged=False ) ),
        grids.GridColumnFilter( "Purged", args=dict( purged=True ) ),
        grids.GridColumnFilter( "All", args=dict( deleted='All' ) )
    ]
    default_filter = dict( name="All", description="All", deleted="False", purged="False" )
    num_rows_per_page = 50
    preserve_state = False
    use_paging = True
Ejemplo n.º 7
0
class ManageCategoryGrid( CategoryGrid ):
    columns = [ col for col in CategoryGrid.columns ]
    # Override the NameColumn to include an Edit link
    columns[ 0 ] = CategoryGrid.NameColumn( "Name",
                                            key="Category.name",
                                            link=( lambda item: dict( operation="Edit", id=item.id ) ),
                                            model_class=model.Category,
                                            attach_popup=False )
    global_actions = [
        grids.GridAction( "Add new category",
                          dict( controller='admin', action='manage_categories', operation='create' ) )
    ]
Ejemplo n.º 8
0
class VisualizationListGrid( grids.Grid ):
    def get_url_args( item ):
        """
        Returns dictionary used to create item link.
        """
        url_kwargs = dict( controller='visualization', id=item.id )
        #TODO: hack to build link to saved visualization - need trans in this function instead in order to do
        #link_data = trans.app.visualizations_registry.get_visualizations( trans, item )
        if item.type in registry.VisualizationsRegistry.BUILT_IN_VISUALIZATIONS:
            url_kwargs[ 'action' ] = item.type
        else:
            url_kwargs[ 'action' ] = 'saved'
        return url_kwargs

    def get_display_name( self, trans, item ):
        if trans.app.visualizations_registry and item.type in trans.app.visualizations_registry.plugins:
            plugin = trans.app.visualizations_registry.plugins[ item.type ]
            return plugin.config.get( 'name', item.type )
        return item.type

    # Grid definition
    title = "Saved Visualizations"
    model_class = model.Visualization
    default_sort_key = "-update_time"
    default_filter = dict( title="All", deleted="False", tags="All", sharing="All" )
    columns = [
        grids.TextColumn( "Title", key="title", attach_popup=True, link=get_url_args ),
        grids.TextColumn( "Type", method='get_display_name' ),
        grids.TextColumn( "Dbkey", key="dbkey" ),
        grids.IndividualTagsColumn( "Tags", key="tags", model_tag_association_class=model.VisualizationTagAssociation, filterable="advanced", grid_name="VisualizationListGrid" ),
        grids.SharingStatusColumn( "Sharing", key="sharing", filterable="advanced", sortable=False ),
        grids.GridColumn( "Created", key="create_time", format=time_ago ),
        grids.GridColumn( "Last Updated", key="update_time", format=time_ago ),
    ]
    columns.append(
        grids.MulticolFilterColumn(
        "Search",
        cols_to_filter=[ columns[0], columns[2] ],
        key="free-text-search", visible=False, filterable="standard" )
                )
    global_actions = [
        grids.GridAction( "Create new visualization", dict( action='create' ), inbound=True )
    ]
    operations = [
        grids.GridOperation( "Open", allow_multiple=False, url_args=get_url_args ),
        grids.GridOperation( "Open in Circster", allow_multiple=False, condition=( lambda item: item.type == 'trackster' ), url_args=dict( action='circster' ) ),
        grids.GridOperation( "Edit Attributes", allow_multiple=False, url_args=dict( action='edit'), inbound=True),
        grids.GridOperation( "Copy", allow_multiple=False, condition=( lambda item: not item.deleted )),
        grids.GridOperation( "Share or Publish", allow_multiple=False, condition=( lambda item: not item.deleted ), async_compatible=False ),
        grids.GridOperation( "Delete", condition=( lambda item: not item.deleted ), confirm="Are you sure you want to delete this visualization?" ),
    ]
    def apply_query_filter( self, trans, query, **kwargs ):
        return query.filter_by( user=trans.user, deleted=False )
Ejemplo n.º 9
0
class VisualizationListGrid( grids.Grid ):
    def get_url_args( item ):
        """
        Returns dictionary used to create item link.
        """
        controller = "visualization"
        action = item.type
        if item.type == "phyloviz":
            controller = "phyloviz"
            action = "visualization"
        return dict( controller=controller, action=action, id=item.id )

    # Grid definition
    title = "Saved Visualizations"
    model_class = model.Visualization
    default_sort_key = "-update_time"
    default_filter = dict( title="All", deleted="False", tags="All", sharing="All" )
    columns = [
        grids.TextColumn( "Title", key="title", attach_popup=True, link=get_url_args ),
        grids.TextColumn( "Type", key="type" ),
        grids.TextColumn( "Dbkey", key="dbkey" ),
        grids.IndividualTagsColumn( "Tags", key="tags", model_tag_association_class=model.VisualizationTagAssociation, filterable="advanced", grid_name="VisualizationListGrid" ),
        grids.SharingStatusColumn( "Sharing", key="sharing", filterable="advanced", sortable=False ),
        grids.GridColumn( "Created", key="create_time", format=time_ago ),
        grids.GridColumn( "Last Updated", key="update_time", format=time_ago ),
    ]    
    columns.append( 
        grids.MulticolFilterColumn(  
        "Search", 
        cols_to_filter=[ columns[0], columns[2] ], 
        key="free-text-search", visible=False, filterable="standard" )
                )
    global_actions = [
        grids.GridAction( "Create new visualization", dict( action='create' ) )
    ]
    operations = [
        grids.GridOperation( "Open", allow_multiple=False, url_args=get_url_args ),
        grids.GridOperation( "Open in Circster", allow_multiple=False, condition=( lambda item: item.type == 'trackster' ), url_args=dict( action='circster' ) ),
        grids.GridOperation( "Edit Attributes", allow_multiple=False, url_args=dict( action='edit') ),
        grids.GridOperation( "Copy", allow_multiple=False, condition=( lambda item: not item.deleted ), async_compatible=False, url_args=dict( action='copy') ),
        grids.GridOperation( "Share or Publish", allow_multiple=False, condition=( lambda item: not item.deleted ), async_compatible=False ),
        grids.GridOperation( "Delete", condition=( lambda item: not item.deleted ), async_compatible=True, confirm="Are you sure you want to delete this visualization?" ),
    ]
    def apply_query_filter( self, trans, query, **kwargs ):
        return query.filter_by( user=trans.user, deleted=False )
Ejemplo n.º 10
0
class PageListGrid( grids.Grid ):
    # Custom column.
    class URLColumn( grids.PublicURLColumn ):
        def get_value( self, trans, grid, item ):
            return url_for(controller='page', action='display_by_username_and_slug', username=item.user.username, slug=item.slug )

    # Grid definition
    use_panels = True
    title = "Pages"
    model_class = model.Page
    default_filter = { "published" : "All", "tags" : "All", "title" : "All", "sharing" : "All" }
    default_sort_key = "-update_time"
    columns = [
        grids.TextColumn( "Title", key="title", attach_popup=True, filterable="advanced" ),
        URLColumn( "Public URL" ),
        grids.OwnerAnnotationColumn( "Annotation", key="annotation", model_annotation_association_class=model.PageAnnotationAssociation, filterable="advanced" ),
        grids.IndividualTagsColumn( "Tags", key="tags", model_tag_association_class=model.PageTagAssociation, filterable="advanced", grid_name="PageListGrid" ),
        grids.SharingStatusColumn( "Sharing", key="sharing", filterable="advanced", sortable=False ),
        grids.GridColumn( "Created", key="create_time", format=time_ago ),
        grids.GridColumn( "Last Updated", key="update_time", format=time_ago ),
    ]
    columns.append(
        grids.MulticolFilterColumn(
        "Search",
        cols_to_filter=[ columns[0], columns[2] ],
        key="free-text-search", visible=False, filterable="standard" )
                )
    global_actions = [
        grids.GridAction( "Add new page", dict( action='create' ) )
    ]
    operations = [
        grids.DisplayByUsernameAndSlugGridOperation( "View", allow_multiple=False ),
        grids.GridOperation( "Edit content", allow_multiple=False, url_args=dict( action='edit_content') ),
        grids.GridOperation( "Edit attributes", allow_multiple=False, url_args=dict( action='edit') ),
        grids.GridOperation( "Share or Publish", allow_multiple=False, condition=( lambda item: not item.deleted ), async_compatible=False ),
        grids.GridOperation( "Delete", confirm="Are you sure you want to delete this page?" ),
    ]
    def apply_query_filter( self, trans, query, **kwargs ):
        return query.filter_by( user=trans.user, deleted=False )
Ejemplo n.º 11
0
    def browse_requests( self, trans, **kwd ):
        if 'operation' in kwd:
            operation = kwd['operation'].lower()
            if operation == "edit":
                return trans.response.send_redirect( web.url_for( controller='requests_common',
                                                                  action='edit_basic_request_info',
                                                                  cntrller='requests',
                                                                  **kwd ) )
            if operation == "add_samples":
                return trans.response.send_redirect( web.url_for( controller='requests_common',
                                                                  action='add_samples',
                                                                  cntrller='requests',
                                                                  **kwd ) )
            if operation == "edit_samples":
                return trans.response.send_redirect( web.url_for( controller='requests_common',
                                                                  action='edit_samples',
                                                                  cntrller='requests',
                                                                  **kwd ) )
            if operation == "view_request":
                return trans.response.send_redirect( web.url_for( controller='requests_common',
                                                                  action='view_request',
                                                                  cntrller='requests',
                                                                  **kwd ) )
            if operation == "delete":
                return trans.response.send_redirect( web.url_for( controller='requests_common',
                                                                  action='delete_request',
                                                                  cntrller='requests',
                                                                  **kwd ) )
            if operation == "undelete":
                return trans.response.send_redirect( web.url_for( controller='requests_common',
                                                                  action='undelete_request',
                                                                  cntrller='requests',
                                                                  **kwd ) )
            if operation == "view_request_history":
                return trans.response.send_redirect( web.url_for( controller='requests_common',
                                                                  action='view_request_history',
                                                                  cntrller='requests',
                                                                  **kwd ) )

        # If there are requests that have been rejected, show a message as a reminder to the user
        rejected = 0
        for request in trans.sa_session.query( trans.app.model.Request ) \
                            .filter( trans.app.model.Request.table.c.deleted==False ) \
                            .filter( trans.app.model.Request.table.c.user_id==trans.user.id ):
            if request.is_rejected:
                rejected = rejected + 1
        if rejected:
            status = 'warning'
            message = "%d requests (highlighted in red) were rejected.  Click on the request name for details." % rejected
            kwd[ 'status' ] = status
            kwd[ 'message' ] = message
        # Allow the user to create a new request only if they have permission to access a request type.
        accessible_request_types = trans.app.security_agent.get_accessible_request_types( trans, trans.user )
        if accessible_request_types:
            self.request_grid.global_actions = [ grids.GridAction( "Create new request", dict( controller='requests_common',
                                                                                               action='create_request',
                                                                                               cntrller='requests' ) ) ]
        else:
            self.request_grid.global_actions = []
        # Render the list view
        return self.request_grid( trans, **kwd )
Ejemplo n.º 12
0
    def manage_datasets(self, trans, **kwd):
        def handle_error(**kwd):
            kwd['status'] = 'error'
            return trans.response.send_redirect(
                web.url_for(controller='requests_admin',
                            action='manage_datasets',
                            **kwd))

        params = util.Params(kwd)
        message = util.restore_text(params.get('message', ''))
        status = params.get('status', 'done')
        # When this method is called due to a grid operation, the sample ID
        # will be in the param 'id'.  But when this method is called via a
        # redirect from another method, the ID will be in 'sample_id'.  So,
        # check for 'id' if 'sample_id' is not provided.
        sample_id = params.get('sample_id', None)
        if sample_id is None:
            sample_id = params.get('id', None)
        try:
            sample = trans.sa_session.query(trans.model.Sample).get(
                trans.security.decode_id(sample_id))
        except:
            return invalid_id_redirect(trans, 'requests_admin', sample_id,
                                       'sample')
        if 'operation' in kwd:
            operation = kwd['operation'].lower()
            sample_dataset_id = params.get('id', None)
            if not sample_dataset_id:
                message = 'Select at least 1 dataset to %s.' % operation
                kwd['message'] = message
                del kwd['operation']
                handle_error(**kwd)
            id_list = util.listify(sample_dataset_id)
            selected_sample_datasets = []
            for sample_dataset_id in id_list:
                try:
                    sample_dataset = trans.sa_session.query(
                        trans.model.SampleDataset).get(
                            trans.security.decode_id(sample_dataset_id))
                except:
                    return invalid_id_redirect(trans, 'requests_admin',
                                               sample_dataset_id,
                                               'sample dataset')
                selected_sample_datasets.append(sample_dataset)
            if operation == "view":
                return trans.fill_template(
                    '/admin/requests/view_sample_dataset.mako',
                    cntrller='requests_admin',
                    sample_dataset=selected_sample_datasets[0])
            elif operation == "delete":
                not_deleted = []
                for sample_dataset in selected_sample_datasets:
                    # Make sure the dataset has been transferred before deleting it.
                    if sample_dataset in sample_dataset.sample.untransferred_dataset_files:
                        # Save the sample dataset
                        sample = sample_dataset.sample
                        trans.sa_session.delete(sample_dataset)
                        trans.sa_session.flush()
                    else:
                        not_deleted.append(sample_dataset.name)
                message = '%i datasets have been deleted.' % (len(id_list) -
                                                              len(not_deleted))
                if not_deleted:
                    status = 'warning'
                    message = message + '  %s could not be deleted because their transfer status is not "Not Started". ' % str(
                        not_deleted)
                return trans.response.send_redirect(
                    web.url_for(controller='requests_admin',
                                action='manage_datasets',
                                sample_id=trans.security.encode_id(sample.id),
                                status=status,
                                message=message))
            elif operation == "rename":
                # If one of the selected sample datasets is in the NOT_STARTED state,
                # then display an error message.  A NOT_STARTED state implies the dataset
                # has not yet been transferred.
                no_datasets_transferred = True
                for selected_sample_dataset in selected_sample_datasets:
                    if selected_sample_dataset in selected_sample_dataset.sample.untransferred_dataset_files:
                        no_datasets_transferred = False
                        break
                if no_datasets_transferred:
                    status = 'error'
                    message = 'A dataset can be renamed only if it has been transferred.'
                    return trans.response.send_redirect(
                        web.url_for(controller='requests_admin',
                                    action='manage_datasets',
                                    sample_id=trans.security.encode_id(
                                        selected_sample_datasets[0].sample.id),
                                    status=status,
                                    message=message))
                return trans.fill_template(
                    '/admin/requests/rename_datasets.mako',
                    sample=selected_sample_datasets[0].sample,
                    id_list=id_list)
            elif operation == "transfer":
                self.initiate_data_transfer(
                    trans,
                    trans.security.encode_id(
                        selected_sample_datasets[0].sample.id),
                    sample_datasets=selected_sample_datasets)
            elif operation == "view_external_service":
                return trans.response.send_redirect(
                    web.url_for(controller='external_service',
                                action='view_external_service',
                                **kwd))

        # Render the grid view
        request_id = trans.security.encode_id(sample.request.id)
        library_id = trans.security.encode_id(sample.library.id)
        self.datatx_grid.title = 'Manage "%s" datasets' % sample.name
        self.datatx_grid.global_actions = [
            grids.GridAction(
                "Browse target data library",
                dict(controller='library_common',
                     action='browse_library',
                     cntrller='library_admin',
                     id=library_id)),
            grids.GridAction(
                "Browse this request",
                dict(controller='requests_common',
                     action='view_request',
                     cntrller='requests_admin',
                     id=request_id))
        ]
        return self.datatx_grid(trans, **kwd)
class InstalledRepositoryGrid(grids.Grid):
    class ToolShedStatusColumn(grids.TextColumn):
        def get_value(self, trans, grid, tool_shed_repository):
            if tool_shed_repository.tool_shed_status:
                tool_shed_status_str = ''
                if tool_shed_repository.is_deprecated_in_tool_shed:
                    tool_shed_status_str += generate_deprecated_repository_img_str(
                        include_mouse_over=True)
                if tool_shed_repository.is_latest_installable_revision:
                    tool_shed_status_str += generate_latest_revision_img_str(
                        include_mouse_over=True)
                if tool_shed_repository.revision_update_available:
                    tool_shed_status_str += generate_revision_updates_img_str(
                        include_mouse_over=True)
                if tool_shed_repository.upgrade_available:
                    tool_shed_status_str += generate_revision_upgrades_img_str(
                        include_mouse_over=True)
                if tool_shed_repository.includes_workflows:
                    tool_shed_status_str += generate_includes_workflows_img_str(
                        include_mouse_over=True)
            else:
                tool_shed_status_str = generate_unknown_img_str(
                    include_mouse_over=True)
            return tool_shed_status_str

    class NameColumn(grids.TextColumn):
        def get_value(self, trans, grid, tool_shed_repository):
            return str(tool_shed_repository.name)

    class DescriptionColumn(grids.TextColumn):
        def get_value(self, trans, grid, tool_shed_repository):
            return util.unicodify(tool_shed_repository.description)

    class OwnerColumn(grids.TextColumn):
        def get_value(self, trans, grid, tool_shed_repository):
            return str(tool_shed_repository.owner)

    class RevisionColumn(grids.TextColumn):
        def get_value(self, trans, grid, tool_shed_repository):
            return str(tool_shed_repository.changeset_revision)

    class StatusColumn(grids.TextColumn):
        def get_value(self, trans, grid, tool_shed_repository):
            return suc.get_tool_shed_repository_status_label(
                trans.app, tool_shed_repository)

    class ToolShedColumn(grids.TextColumn):
        def get_value(self, trans, grid, tool_shed_repository):
            return tool_shed_repository.tool_shed

    class DeletedColumn(grids.DeletedColumn):
        def get_accepted_filters(self):
            """ Returns a list of accepted filters for this column. """
            accepted_filter_labels_and_vals = {
                "Active": "False",
                "Deactivated or uninstalled": "True",
                "All": "All"
            }
            accepted_filters = []
            for label, val in accepted_filter_labels_and_vals.items():
                args = {self.key: val}
                accepted_filters.append(grids.GridColumnFilter(label, args))
            return accepted_filters

    # Grid definition
    title = "Installed tool shed repositories"
    model_class = tool_shed_install.ToolShedRepository
    template = '/admin/tool_shed_repository/grid.mako'
    default_sort_key = "name"
    columns = [
        ToolShedStatusColumn(label=""),
        NameColumn(
            label="Name",
            key="name",
            link=(lambda item: iff(
                item.status in [
                    tool_shed_install.ToolShedRepository.installation_status.
                    CLONING
                ], None, dict(operation="manage_repository", id=item.id))),
            attach_popup=True),
        DescriptionColumn(label="Description"),
        OwnerColumn(label="Owner"),
        RevisionColumn(label="Revision"),
        StatusColumn(label="Installation Status", filterable="advanced"),
        ToolShedColumn(label="Tool shed"),
        # Columns that are valid for filtering but are not visible.
        DeletedColumn(label="Status",
                      key="deleted",
                      visible=False,
                      filterable="advanced")
    ]
    columns.append(
        grids.MulticolFilterColumn("Search repository name",
                                   cols_to_filter=[columns[1]],
                                   key="free-text-search",
                                   visible=False,
                                   filterable="standard"))
    global_actions = [
        grids.GridAction(
            label="Update tool shed status",
            url_args=dict(
                controller='admin_toolshed',
                action='update_tool_shed_status_for_installed_repository',
                all_installed_repositories=True),
            inbound=False)
    ]
    operations = [ grids.GridOperation( label="Update tool shed status",
                                        condition=( lambda item: not item.deleted ),
                                        allow_multiple=False,
                                        url_args=dict( controller='admin_toolshed',
                                                       action='browse_repositories',
                                                       operation='update tool shed status' ) ),
                   grids.GridOperation( label="Get updates",
                                        condition=( lambda item: \
                                                        not item.deleted and \
                                                        item.revision_update_available and \
                                                        item.status not in \
                                                            [ tool_shed_install.ToolShedRepository.installation_status.ERROR,
                                                              tool_shed_install.ToolShedRepository.installation_status.NEW ] ),
                                        allow_multiple=False,
                                        url_args=dict( controller='admin_toolshed',
                                                       action='browse_repositories',
                                                       operation='get updates' ) ),
                   grids.GridOperation( label="Install latest revision",
                                        condition=( lambda item: item.upgrade_available ),
                                        allow_multiple=False,
                                        url_args=dict( controller='admin_toolshed',
                                                       action='browse_repositories',
                                                       operation='install latest revision' ) ),
                   grids.GridOperation( label="Install",
                                        condition=( lambda item: \
                                                    not item.deleted and \
                                                    item.status == tool_shed_install.ToolShedRepository.installation_status.NEW ),
                                        allow_multiple=False,
                                        url_args=dict( controller='admin_toolshed',
                                                       action='manage_repository',
                                                       operation='install' ) ),
                   grids.GridOperation( label="Deactivate or uninstall",
                                        condition=( lambda item: \
                                                    not item.deleted and \
                                                    item.status != tool_shed_install.ToolShedRepository.installation_status.NEW ),
                                        allow_multiple=False,
                                        url_args=dict( controller='admin_toolshed',
                                                       action='browse_repositories',
                                                       operation='deactivate or uninstall' ) ),
                   grids.GridOperation( label="Reset to install",
                                        condition=( lambda item: \
                                                        ( item.status == tool_shed_install.ToolShedRepository.installation_status.ERROR ) ),
                                        allow_multiple=False,
                                        url_args=dict( controller='admin_toolshed',
                                                       action='browse_repositories',
                                                       operation='reset to install' ) ),
                   grids.GridOperation( label="Activate or reinstall",
                                        condition=( lambda item: item.deleted ),
                                        allow_multiple=False,
                                        target=None,
                                        url_args=dict( controller='admin_toolshed',
                                                       action='browse_repositories',
                                                       operation='activate or reinstall' ) ),
                   grids.GridOperation( label="Purge",
                                        condition=( lambda item: item.is_new ),
                                        allow_multiple=False,
                                        target=None,
                                        url_args=dict( controller='admin_toolshed',
                                                       action='browse_repositories',
                                                       operation='purge' ) ) ]
    standard_filters = []
    default_filter = dict(deleted="False")
    num_rows_per_page = 50
    preserve_state = False
    use_paging = False

    def build_initial_query(self, trans, **kwd):
        return trans.install_model.context.query( self.model_class ) \
                               .order_by( self.model_class.table.c.tool_shed,
                                          self.model_class.table.c.name,
                                          self.model_class.table.c.owner,
                                          self.model_class.table.c.ctx_rev )

    @property
    def legend(self):
        legend_str = '%s&nbsp;&nbsp;Updates are available in the Tool Shed for this revision<br/>' % generate_revision_updates_img_str(
        )
        legend_str += '%s&nbsp;&nbsp;A newer installable revision is available for this repository<br/>' % generate_revision_upgrades_img_str(
        )
        legend_str += '%s&nbsp;&nbsp;This is the latest installable revision of this repository<br/>' % generate_latest_revision_img_str(
        )
        legend_str += '%s&nbsp;&nbsp;This repository is deprecated in the Tool Shed<br/>' % generate_deprecated_repository_img_str(
        )
        legend_str += '%s&nbsp;&nbsp;This repository contains exported workflows<br/>' % generate_includes_workflows_img_str(
        )
        legend_str += '%s&nbsp;&nbsp;Unable to get information from the Tool Shed<br/>' % generate_unknown_img_str(
        )
        return legend_str
Ejemplo n.º 14
0
class QuotaListGrid( grids.Grid ):

    class NameColumn( grids.TextColumn ):
        def get_value( self, trans, grid, quota ):
            return escape(quota.name)

    class DescriptionColumn( grids.TextColumn ):
        def get_value( self, trans, grid, quota ):
            if quota.description:
                return escape(quota.description)
            return ''

    class AmountColumn( grids.TextColumn ):
        def get_value( self, trans, grid, quota ):
            return quota.operation + quota.display_amount

    class StatusColumn( grids.GridColumn ):
        def get_value( self, trans, grid, quota ):
            if quota.deleted:
                return "deleted"
            elif quota.default:
                return "<strong>default for %s users</strong>" % quota.default[0].type
            return ""

    class UsersColumn( grids.GridColumn ):
        def get_value( self, trans, grid, quota ):
            if quota.users:
                return len( quota.users )
            return 0

    class GroupsColumn( grids.GridColumn ):
        def get_value( self, trans, grid, quota ):
            if quota.groups:
                return len( quota.groups )
            return 0

    # Grid definition
    title = "Quotas"
    model_class = model.Quota
    template = '/admin/quota/grid.mako'
    default_sort_key = "name"
    columns = [
        NameColumn( "Name",
                    key="name",
                    link=( lambda item: dict( operation="Change amount", id=item.id, webapp="galaxy" ) ),
                    model_class=model.Quota,
                    attach_popup=True,
                    filterable="advanced" ),
        DescriptionColumn( "Description",
                           key='description',
                           model_class=model.Quota,
                           attach_popup=False,
                           filterable="advanced" ),
        AmountColumn( "Amount",
                      key='amount',
                      model_class=model.Quota,
                      attach_popup=False,
                      filterable="advanced" ),
        UsersColumn( "Users", attach_popup=False ),
        GroupsColumn( "Groups", attach_popup=False ),
        StatusColumn( "Status", attach_popup=False ),
        # Columns that are valid for filtering but are not visible.
        grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" )
    ]
    columns.append( grids.MulticolFilterColumn( "Search",
                                                cols_to_filter=[ columns[0], columns[1], columns[2] ],
                                                key="free-text-search",
                                                visible=False,
                                                filterable="standard" ) )
    global_actions = [
        grids.GridAction( "Add new quota", dict( controller='admin', action='quotas', operation='create' ) )
    ]
    operations = [ grids.GridOperation( "Rename",
                                        condition=( lambda item: not item.deleted ),
                                        allow_multiple=False,
                                        url_args=dict( webapp="galaxy", action="rename_quota" ) ),
                   grids.GridOperation( "Change amount",
                                        condition=( lambda item: not item.deleted ),
                                        allow_multiple=False,
                                        url_args=dict( webapp="galaxy", action="edit_quota" ) ),
                   grids.GridOperation( "Manage users and groups",
                                        condition=( lambda item: not item.default and not item.deleted ),
                                        allow_multiple=False,
                                        url_args=dict( webapp="galaxy", action="manage_users_and_groups_for_quota" ) ),
                   grids.GridOperation( "Set as different type of default",
                                        condition=( lambda item: item.default ),
                                        allow_multiple=False,
                                        url_args=dict( webapp="galaxy", action="set_quota_default" ) ),
                   grids.GridOperation( "Set as default",
                                        condition=( lambda item: not item.default and not item.deleted ),
                                        allow_multiple=False,
                                        url_args=dict( webapp="galaxy", action="set_quota_default" ) ),
                   grids.GridOperation( "Unset as default",
                                        condition=( lambda item: item.default and not item.deleted ),
                                        allow_multiple=False,
                                        url_args=dict( webapp="galaxy", action="unset_quota_default" ) ),
                   grids.GridOperation( "Delete",
                                        condition=( lambda item: not item.deleted and not item.default ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="mark_quota_deleted" ) ),
                   grids.GridOperation( "Undelete",
                                        condition=( lambda item: item.deleted ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="undelete_quota" ) ),
                   grids.GridOperation( "Purge",
                                        condition=( lambda item: item.deleted ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="purge_quota" ) ) ]
    standard_filters = [
        grids.GridColumnFilter( "Active", args=dict( deleted=False ) ),
        grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ),
        grids.GridColumnFilter( "All", args=dict( deleted='All' ) )
    ]
    num_rows_per_page = 50
    preserve_state = False
    use_paging = True
Ejemplo n.º 15
0
class UserListGrid( grids.Grid ):

    class EmailColumn( grids.TextColumn ):
        def get_value( self, trans, grid, user ):
            return escape(user.email)

    class UserNameColumn( grids.TextColumn ):
        def get_value( self, trans, grid, user ):
            if user.username:
                return escape(user.username)
            return 'not set'

    class StatusColumn( grids.GridColumn ):
        def get_value( self, trans, grid, user ):
            if user.purged:
                return "purged"
            elif user.deleted:
                return "deleted"
            return ""

    class GroupsColumn( grids.GridColumn ):
        def get_value( self, trans, grid, user ):
            if user.groups:
                return len( user.groups )
            return 0

    class RolesColumn( grids.GridColumn ):
        def get_value( self, trans, grid, user ):
            if user.roles:
                return len( user.roles )
            return 0

    class ExternalColumn( grids.GridColumn ):
        def get_value( self, trans, grid, user ):
            if user.external:
                return 'yes'
            return 'no'

    class LastLoginColumn( grids.GridColumn ):
        def get_value( self, trans, grid, user ):
            if user.galaxy_sessions:
                return self.format( user.galaxy_sessions[ 0 ].update_time )
            return 'never'

    class TimeCreatedColumn( grids.GridColumn ):
        def get_value( self, trans, grid, user ):
            return user.create_time.strftime('%x')

    class ActivatedColumn( grids.GridColumn ):
        def get_value( self, trans, grid, user ):
            if user.active:
                return 'Y'
            else:
                return 'N'

    # Grid definition
    title = "Users"
    model_class = model.User
    template = '/admin/user/grid.mako'
    default_sort_key = "email"
    columns = [
        EmailColumn( "Email",
                     key="email",
                     model_class=model.User,
                     link=( lambda item: dict( operation="information", id=item.id, webapp="galaxy" ) ),
                     attach_popup=True,
                     filterable="advanced",
                     target="top" ),
        UserNameColumn( "User Name",
                        key="username",
                        model_class=model.User,
                        attach_popup=False,
                        filterable="advanced" ),
        GroupsColumn( "Groups", attach_popup=False ),
        RolesColumn( "Roles", attach_popup=False ),
        ExternalColumn( "External", attach_popup=False ),
        LastLoginColumn( "Last Login", format=time_ago ),
        StatusColumn( "Status", attach_popup=False ),
        TimeCreatedColumn( "Created", attach_popup=False ),
        ActivatedColumn( "Activated", attach_popup=False ),
        # Columns that are valid for filtering but are not visible.
        grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" )
    ]
    columns.append( grids.MulticolFilterColumn( "Search",
                                                cols_to_filter=[ columns[0], columns[1] ],
                                                key="free-text-search",
                                                visible=False,
                                                filterable="standard" ) )
    global_actions = [
        grids.GridAction( "Create new user", dict( controller='admin', action='users', operation='create', webapp="galaxy" ) )
    ]
    operations = [
        grids.GridOperation( "Manage Roles and Groups",
                             condition=( lambda item: not item.deleted ),
                             allow_multiple=False,
                             url_args=dict( webapp="galaxy", action="manage_roles_and_groups_for_user" ) ),
        grids.GridOperation( "Reset Password",
                             condition=( lambda item: not item.deleted ),
                             allow_multiple=True,
                             allow_popup=False,
                             url_args=dict( webapp="galaxy", action="reset_user_password" ) ),
        grids.GridOperation( "Recalculate Disk Usage",
                             condition=( lambda item: not item.deleted ),
                             allow_multiple=False,
                             url_args=dict( webapp="galaxy", action="recalculate_user_disk_usage" ) )
    ]
    standard_filters = [
        grids.GridColumnFilter( "Active", args=dict( deleted=False ) ),
        grids.GridColumnFilter( "Deleted", args=dict( deleted=True, purged=False ) ),
        grids.GridColumnFilter( "Purged", args=dict( purged=True ) ),
        grids.GridColumnFilter( "All", args=dict( deleted='All' ) )
    ]
    num_rows_per_page = 50
    preserve_state = False
    use_paging = True

    def get_current_item( self, trans, **kwargs ):
        return trans.user
Ejemplo n.º 16
0
class GroupListGrid( grids.Grid ):

    class NameColumn( grids.TextColumn ):
        def get_value( self, trans, grid, group ):
            return escape(group.name)

    class StatusColumn( grids.GridColumn ):
        def get_value( self, trans, grid, group ):
            if group.deleted:
                return "deleted"
            return ""

    class RolesColumn( grids.GridColumn ):
        def get_value( self, trans, grid, group ):
            if group.roles:
                return len( group.roles )
            return 0

    class UsersColumn( grids.GridColumn ):
        def get_value( self, trans, grid, group ):
            if group.members:
                return len( group.members )
            return 0

    # Grid definition
    title = "Groups"
    model_class = model.Group
    template = '/admin/dataset_security/group/grid.mako'
    default_sort_key = "name"
    columns = [
        NameColumn( "Name",
                    key="name",
                    link=( lambda item: dict( operation="Manage users and roles", id=item.id, webapp="galaxy" ) ),
                    model_class=model.Group,
                    attach_popup=True,
                    filterable="advanced" ),
        UsersColumn( "Users", attach_popup=False ),
        RolesColumn( "Roles", attach_popup=False ),
        StatusColumn( "Status", attach_popup=False ),
        # Columns that are valid for filtering but are not visible.
        grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" )
    ]
    columns.append( grids.MulticolFilterColumn( "Search",
                                                cols_to_filter=[ columns[0], columns[1], columns[2] ],
                                                key="free-text-search",
                                                visible=False,
                                                filterable="standard" ) )
    global_actions = [
        grids.GridAction( "Add new group", dict( controller='admin', action='groups', operation='create', webapp="galaxy" ) )
    ]
    operations = [ grids.GridOperation( "Rename",
                                        condition=( lambda item: not item.deleted ),
                                        allow_multiple=False,
                                        url_args=dict( webapp="galaxy", action="rename_group" ) ),
                   grids.GridOperation( "Delete",
                                        condition=( lambda item: not item.deleted ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="mark_group_deleted" ) ),
                   grids.GridOperation( "Undelete",
                                        condition=( lambda item: item.deleted ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="undelete_group" ) ),
                   grids.GridOperation( "Purge",
                                        condition=( lambda item: item.deleted ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="purge_group" ) ) ]
    standard_filters = [
        grids.GridColumnFilter( "Active", args=dict( deleted=False ) ),
        grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ),
        grids.GridColumnFilter( "All", args=dict( deleted='All' ) )
    ]
    num_rows_per_page = 50
    preserve_state = False
    use_paging = True
Ejemplo n.º 17
0
class RoleListGrid( grids.Grid ):

    class NameColumn( grids.TextColumn ):
        def get_value( self, trans, grid, role ):
            return escape(role.name)

    class DescriptionColumn( grids.TextColumn ):
        def get_value( self, trans, grid, role ):
            if role.description:
                return escape(role.description)
            return ''

    class TypeColumn( grids.TextColumn ):
        def get_value( self, trans, grid, role ):
            return role.type

    class StatusColumn( grids.GridColumn ):
        def get_value( self, trans, grid, role ):
            if role.deleted:
                return "deleted"
            return ""

    class GroupsColumn( grids.GridColumn ):
        def get_value( self, trans, grid, role ):
            if role.groups:
                return len( role.groups )
            return 0

    class UsersColumn( grids.GridColumn ):
        def get_value( self, trans, grid, role ):
            if role.users:
                return len( role.users )
            return 0

    # Grid definition
    title = "Roles"
    model_class = model.Role
    template = '/admin/dataset_security/role/grid.mako'
    default_sort_key = "name"
    columns = [
        NameColumn( "Name",
                    key="name",
                    link=( lambda item: dict( operation="Manage users and groups", id=item.id, webapp="galaxy" ) ),
                    model_class=model.Role,
                    attach_popup=True,
                    filterable="advanced" ),
        DescriptionColumn( "Description",
                           key='description',
                           model_class=model.Role,
                           attach_popup=False,
                           filterable="advanced" ),
        TypeColumn( "Type",
                    key='type',
                    model_class=model.Role,
                    attach_popup=False,
                    filterable="advanced" ),
        GroupsColumn( "Groups", attach_popup=False ),
        UsersColumn( "Users", attach_popup=False ),
        StatusColumn( "Status", attach_popup=False ),
        # Columns that are valid for filtering but are not visible.
        grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" )
    ]
    columns.append( grids.MulticolFilterColumn( "Search",
                                                cols_to_filter=[ columns[0], columns[1], columns[2] ],
                                                key="free-text-search",
                                                visible=False,
                                                filterable="standard" ) )
    global_actions = [
        grids.GridAction( "Add new role", dict( controller='admin', action='roles', operation='create' ) )
    ]
    operations = [ grids.GridOperation( "Edit",
                                        condition=( lambda item: not item.deleted ),
                                        allow_multiple=False,
                                        url_args=dict( webapp="galaxy", action="rename_role" ) ),
                   grids.GridOperation( "Delete",
                                        condition=( lambda item: not item.deleted ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="mark_role_deleted" ) ),
                   grids.GridOperation( "Undelete",
                                        condition=( lambda item: item.deleted ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="undelete_role" ) ),
                   grids.GridOperation( "Purge",
                                        condition=( lambda item: item.deleted ),
                                        allow_multiple=True,
                                        url_args=dict( webapp="galaxy", action="purge_role" ) ) ]
    standard_filters = [
        grids.GridColumnFilter( "Active", args=dict( deleted=False ) ),
        grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ),
        grids.GridColumnFilter( "All", args=dict( deleted='All' ) )
    ]
    num_rows_per_page = 50
    preserve_state = False
    use_paging = True

    def apply_query_filter( self, trans, query, **kwargs ):
        return query.filter( model.Role.type != model.Role.types.PRIVATE )
Ejemplo n.º 18
0
class UserGrid(grids.Grid):
    class UserLoginColumn(grids.TextColumn):
        def get_value(self, trans, grid, user):
            return escape(user.email)

    class UserNameColumn(grids.TextColumn):
        def get_value(self, trans, grid, user):
            if user.username:
                return escape(user.username)
            return 'not set'

    class GroupsColumn(grids.GridColumn):
        def get_value(self, trans, grid, user):
            if user.groups:
                return len(user.groups)
            return 0

    class RolesColumn(grids.GridColumn):
        def get_value(self, trans, grid, user):
            if user.roles:
                return len(user.roles)
            return 0

    class ExternalColumn(grids.GridColumn):
        def get_value(self, trans, grid, user):
            if user.external:
                return 'yes'
            return 'no'

    class LastLoginColumn(grids.GridColumn):
        def get_value(self, trans, grid, user):
            if user.galaxy_sessions:
                return self.format(user.galaxy_sessions[0].update_time)
            return 'never'

    class StatusColumn(grids.GridColumn):
        def get_value(self, trans, grid, user):
            if user.purged:
                return "purged"
            elif user.deleted:
                return "deleted"
            return ""

    class EmailColumn(grids.GridColumn):
        def filter(self, trans, user, query, column_filter):
            if column_filter == 'All':
                return query
            return query.filter(
                and_(model.Tool.table.c.user_id == model.User.table.c.id,
                     model.User.table.c.email == column_filter))

    title = "Users"
    model_class = model.User
    default_sort_key = "email"
    columns = [
        UserLoginColumn(
            "Email",
            key="email",
            link=(lambda item: dict(operation="information", id=item.id)),
            attach_popup=True,
            filterable="advanced"),
        UserNameColumn("User Name",
                       key="username",
                       attach_popup=False,
                       filterable="advanced"),
        GroupsColumn("Groups", attach_popup=False),
        RolesColumn("Roles", attach_popup=False),
        ExternalColumn("External", attach_popup=False),
        LastLoginColumn("Last Login", format=time_ago),
        StatusColumn("Status", attach_popup=False),
        # Columns that are valid for filtering but are not visible.
        EmailColumn("Email", key="email", visible=False)
    ]
    columns.append(
        grids.MulticolFilterColumn("Search",
                                   cols_to_filter=[columns[0], columns[1]],
                                   key="free-text-search",
                                   visible=False,
                                   filterable="standard"))
    global_actions = [
        grids.GridAction(
            "Create new user",
            dict(controller='admin', action='users', operation='create'))
    ]
    operations = [
        grids.GridOperation(
            "Manage Roles and Groups",
            condition=(lambda item: not item.deleted),
            allow_multiple=False,
            url_args=dict(action="manage_roles_and_groups_for_user")),
        grids.GridOperation("Reset Password",
                            condition=(lambda item: not item.deleted),
                            allow_multiple=True,
                            allow_popup=False,
                            url_args=dict(action="reset_user_password"))
    ]
    standard_filters = [
        grids.GridColumnFilter("Active", args=dict(deleted=False)),
        grids.GridColumnFilter("Deleted",
                               args=dict(deleted=True, purged=False)),
        grids.GridColumnFilter("Purged", args=dict(purged=True)),
        grids.GridColumnFilter("All", args=dict(deleted='All'))
    ]

    use_paging = False

    def get_current_item(self, trans, **kwargs):
        return trans.user
Ejemplo n.º 19
0
class RoleGrid(grids.Grid):
    class NameColumn(grids.TextColumn):
        def get_value(self, trans, grid, role):
            return escape(str(role.name))

    class DescriptionColumn(grids.TextColumn):
        def get_value(self, trans, grid, role):
            if role.description:
                return str(role.description)
            return ''

    class TypeColumn(grids.TextColumn):
        def get_value(self, trans, grid, role):
            return str(role.type)

    class StatusColumn(grids.GridColumn):
        def get_value(self, trans, grid, role):
            if role.deleted:
                return "deleted"
            return ""

    class GroupsColumn(grids.GridColumn):
        def get_value(self, trans, grid, role):
            if role.groups:
                return len(role.groups)
            return 0

    class RepositoriesColumn(grids.GridColumn):
        def get_value(self, trans, grid, role):
            if role.repositories:
                return len(role.repositories)
            return 0

    class UsersColumn(grids.GridColumn):
        def get_value(self, trans, grid, role):
            if role.users:
                return len(role.users)
            return 0

    title = "Roles"
    model_class = model.Role
    default_sort_key = "name"
    columns = [
        NameColumn("Name",
                   key="name",
                   link=(lambda item: dict(
                       operation="Manage role associations", id=item.id)),
                   attach_popup=True,
                   filterable="advanced"),
        DescriptionColumn("Description",
                          key='description',
                          attach_popup=False,
                          filterable="advanced"),
        GroupsColumn("Groups", attach_popup=False),
        RepositoriesColumn("Repositories", attach_popup=False),
        UsersColumn("Users", attach_popup=False),
        # Columns that are valid for filtering but are not visible.
        grids.DeletedColumn("Deleted",
                            key="deleted",
                            visible=False,
                            filterable="advanced")
    ]
    columns.append(
        grids.MulticolFilterColumn("Search",
                                   cols_to_filter=[columns[0]],
                                   key="free-text-search",
                                   visible=False,
                                   filterable="standard"))
    global_actions = [
        grids.GridAction(
            "Add new role",
            dict(controller='admin', action='roles', operation='create'))
    ]
    # Repository admin roles currently do not have any operations since they are managed automatically based
    # on other events.  For example, if a repository is renamed, its associated admin role is automatically
    # renamed accordingly and if a repository is deleted its associated admin role is automatically deleted.
    operations = [
        grids.GridOperation("Rename",
                            condition=(lambda item: not item.deleted and
                                       not item.is_repository_admin_role),
                            allow_multiple=False,
                            url_args=dict(action="rename_role")),
        grids.GridOperation("Delete",
                            condition=(lambda item: not item.deleted and
                                       not item.is_repository_admin_role),
                            allow_multiple=True,
                            url_args=dict(action="mark_role_deleted")),
        grids.GridOperation("Undelete",
                            condition=(lambda item: item.deleted and not item.
                                       is_repository_admin_role),
                            allow_multiple=True,
                            url_args=dict(action="undelete_role")),
        grids.GridOperation("Purge",
                            condition=(lambda item: item.deleted and not item.
                                       is_repository_admin_role),
                            allow_multiple=True,
                            url_args=dict(action="purge_role"))
    ]
    standard_filters = [
        grids.GridColumnFilter("Active", args=dict(deleted=False)),
        grids.GridColumnFilter("Deleted", args=dict(deleted=True)),
        grids.GridColumnFilter("All", args=dict(deleted='All'))
    ]

    use_paging = False

    def apply_query_filter(self, trans, query, **kwd):
        return query.filter(model.Role.type != model.Role.types.PRIVATE)
Ejemplo n.º 20
0
class RequestTypeGrid(grids.Grid):
    # Custom column types
    class NameColumn(grids.TextColumn):
        def get_value(self, trans, grid, request_type):
            return escape(request_type.name)

    class DescriptionColumn(grids.TextColumn):
        def get_value(self, trans, grid, request_type):
            return escape(request_type.desc)

    class RequestFormColumn(grids.TextColumn):
        def get_value(self, trans, grid, request_type):
            return escape(request_type.request_form.name)

    class SampleFormColumn(grids.TextColumn):
        def get_value(self, trans, grid, request_type):
            return escape(request_type.sample_form.name)

    class ExternalServiceColumn(grids.IntegerColumn):
        def get_value(self, trans, grid, request_type):
            if request_type.external_services:
                return len(request_type.external_services)
            return 'No external service assigned'

    # Grid definition
    title = "Request Types"
    template = "admin/request_type/grid.mako"
    model_class = model.RequestType
    default_sort_key = "-create_time"
    num_rows_per_page = 50
    preserve_state = True
    use_paging = True
    default_filter = dict(deleted="False")
    columns = [
        NameColumn("Name",
                   key="name",
                   link=(lambda item: iff(
                       item.deleted, None,
                       dict(operation="view_request_type", id=item.id))),
                   attach_popup=True,
                   filterable="advanced"),
        DescriptionColumn("Description", key='desc', filterable="advanced"),
        RequestFormColumn("Request Form",
                          link=(lambda item: iff(
                              item.deleted, None,
                              dict(operation="view_form_definition",
                                   id=item.request_form.id)))),
        SampleFormColumn(
            "Sample Form",
            link=(lambda item: iff(
                item.deleted, None,
                dict(operation="view_form_definition", id=item.sample_form.id))
                  )),
        ExternalServiceColumn("External Services"),
        grids.DeletedColumn("Deleted",
                            key="deleted",
                            visible=False,
                            filterable="advanced")
    ]
    columns.append(
        grids.MulticolFilterColumn("Search",
                                   cols_to_filter=[columns[0], columns[1]],
                                   key="free-text-search",
                                   visible=False,
                                   filterable="standard"))
    operations = [
        grids.GridOperation("Edit request type",
                            allow_multiple=False,
                            condition=(lambda item: not item.deleted)),
        grids.GridOperation("Edit permissions",
                            allow_multiple=False,
                            condition=(lambda item: not item.deleted)),
        grids.GridOperation(
            "Use run details template",
            allow_multiple=False,
            condition=(
                lambda item: not item.deleted and not item.run_details)),
        grids.GridOperation("Delete",
                            allow_multiple=True,
                            condition=(lambda item: not item.deleted)),
        grids.GridOperation("Undelete", condition=(lambda item: item.deleted)),
    ]
    global_actions = [
        grids.GridAction(
            "Create new request type",
            dict(controller='request_type', action='create_request_type'))
    ]
Ejemplo n.º 21
0
class HistoryListGrid(grids.Grid):

    # Custom column types
    class ItemCountColumn(grids.GridColumn):
        def get_value(self, trans, grid, history):
            return str(history.hid_counter - 1)

    class HistoryListNameColumn(NameColumn):
        def get_link(self, trans, grid, history):
            link = None
            if not history.deleted:
                link = dict(operation="Switch", id=history.id, use_panels=grid.use_panels, async_compatible=True)
            return link

    class DeletedColumn(grids.DeletedColumn):
        def get_value(self, trans, grid, history):
            if history == trans.history:
                return "<strong>current history</strong>"
            if history.purged:
                return "deleted permanently"
            elif history.deleted:
                return "deleted"
            return ""

        def sort(self, trans, query, ascending, column_name=None):
            if ascending:
                query = query.order_by(self.model_class.table.c.purged.asc(), self.model_class.update_time.desc())
            else:
                query = query.order_by(self.model_class.table.c.purged.desc(), self.model_class.update_time.desc())
            return query

    def build_initial_query(self, trans, **kwargs):
        # Override to preload sharing information used when fetching data for grid.
        query = super().build_initial_query(trans, **kwargs)
        query = query.options(undefer("users_shared_with_count"))
        return query

    # Grid definition
    title = "Saved Histories"
    model_class = model.History
    default_sort_key = "-update_time"
    columns = [
        HistoryListNameColumn("Name", key="name", attach_popup=True, filterable="advanced"),
        ItemCountColumn("Items", key="item_count", sortable=False),
        grids.GridColumn("Datasets", key="datasets_by_state", sortable=False, nowrap=True, delayed=True),
        grids.IndividualTagsColumn("Tags", key="tags", model_tag_association_class=model.HistoryTagAssociation,
                                   filterable="advanced", grid_name="HistoryListGrid"),
        grids.SharingStatusColumn("Sharing", key="sharing", filterable="advanced", sortable=False, use_shared_with_count=True),
        grids.GridColumn("Size on Disk", key="disk_size", sortable=False, delayed=True),
        grids.GridColumn("Created", key="create_time", format=time_ago),
        grids.GridColumn("Last Updated", key="update_time", format=time_ago),
        DeletedColumn("Status", key="deleted", filterable="advanced")
    ]
    columns.append(
        grids.MulticolFilterColumn(
            "search history names and tags",
            cols_to_filter=[columns[0], columns[3]],
            key="free-text-search", visible=False, filterable="standard")
    )
    global_actions = [
        grids.GridAction("Import history", dict(controller="", action="histories/import"))
    ]
    operations = [
        grids.GridOperation("Switch", allow_multiple=False, condition=(lambda item: not item.deleted), async_compatible=True),
        grids.GridOperation("View", allow_multiple=False, url_args=dict(controller="", action="histories/view")),
        grids.GridOperation("Share or Publish", allow_multiple=False, condition=(lambda item: not item.deleted), url_args=dict(controller="", action="histories/sharing")),
        grids.GridOperation("Change Permissions", allow_multiple=False, condition=(lambda item: not item.deleted), url_args=dict(controller="", action="histories/permissions")),
        grids.GridOperation("Copy", allow_multiple=False, condition=(lambda item: not item.deleted), async_compatible=False),
        grids.GridOperation("Rename", condition=(lambda item: not item.deleted), url_args=dict(controller="", action="histories/rename"), target="top"),
        grids.GridOperation("Delete", condition=(lambda item: not item.deleted), async_compatible=True),
        grids.GridOperation("Delete Permanently", condition=(lambda item: not item.purged), confirm="History contents will be removed from disk, this cannot be undone.  Continue?", async_compatible=True),
        grids.GridOperation("Undelete", condition=(lambda item: item.deleted and not item.purged), async_compatible=True),
    ]
    standard_filters = [
        grids.GridColumnFilter("Active", args=dict(deleted=False)),
        grids.GridColumnFilter("Deleted", args=dict(deleted=True)),
        grids.GridColumnFilter("All", args=dict(deleted='All')),
    ]
    default_filter = dict(name="All", deleted="False", tags="All", sharing="All")
    num_rows_per_page = 15
    use_paging = True
    info_text = "Histories that have been deleted for more than a time period specified by the Galaxy administrator(s) may be permanently deleted."

    def get_current_item(self, trans, **kwargs):
        return trans.get_history()

    def apply_query_filter(self, trans, query, **kwargs):
        return query.filter_by(user=trans.user, importing=False)
Ejemplo n.º 22
0
class ExternalServiceGrid(grids.Grid):
    # Custom column types
    class NameColumn(grids.TextColumn):
        def get_value(self, trans, grid, external_service):
            return external_service.name

    class ExternalServiceTypeColumn(grids.TextColumn):
        def get_value(self, trans, grid, external_service):
            try:
                return trans.app.external_service_types.all_external_service_types[
                    external_service.external_service_type_id].name
            except KeyError:
                return 'Error in loading external_service type: %s' % external_service.external_service_type_id

    # Grid definition
    title = "External Services"
    template = "admin/external_service/grid.mako"
    model_class = model.ExternalService
    default_sort_key = "-create_time"
    num_rows_per_page = 50
    preserve_state = True
    use_paging = True
    default_filter = dict(deleted="False")
    columns = [
        NameColumn("Name",
                   key="name",
                   link=(lambda item: iff(item.deleted, None,
                                          dict(operation="view", id=item.id))),
                   attach_popup=True,
                   filterable="advanced"),
        grids.TextColumn("Description",
                         key='description',
                         filterable="advanced"),
        ExternalServiceTypeColumn("External Service Type"),
        grids.GridColumn("Last Updated", key="update_time", format=time_ago),
        grids.DeletedColumn("Deleted",
                            key="deleted",
                            visible=False,
                            filterable="advanced")
    ]
    columns.append(
        grids.MulticolFilterColumn("Search",
                                   cols_to_filter=[columns[0], columns[1]],
                                   key="free-text-search",
                                   visible=False,
                                   filterable="standard"))
    operations = [
        grids.GridOperation("Edit",
                            allow_multiple=False,
                            condition=(lambda item: not item.deleted)),
        grids.GridOperation("Delete",
                            allow_multiple=True,
                            condition=(lambda item: not item.deleted)),
        grids.GridOperation("Undelete", condition=(lambda item: item.deleted)),
    ]
    global_actions = [
        grids.GridAction(
            "Reload external service types",
            dict(controller='external_service',
                 action='reload_external_service_types')),
        grids.GridAction(
            "Create new external service",
            dict(controller='external_service',
                 action='create_external_service'))
    ]
Ejemplo n.º 23
0
                             key="deleted", 
                             visible=False, 
                             filterable="advanced" )
    ]
    columns.append( grids.MulticolFilterColumn( "Search", 
                                                cols_to_filter=[ columns[0], columns[1] ], 
                                                key="free-text-search",
                                                visible=False,
                                                filterable="standard" ) )
    operations = [
        grids.GridOperation( "Edit", allow_multiple=False, condition=( lambda item: not item.deleted  )  ),
        grids.GridOperation( "Delete", allow_multiple=True, condition=( lambda item: not item.deleted  )  ),
        grids.GridOperation( "Undelete", condition=( lambda item: item.deleted ) ),    
    ]
    global_actions = [
        grids.GridAction( "Reload external service types", dict( controller='external_service', action='reload_external_service_types' ) ),
        grids.GridAction( "Create new external service", dict( controller='external_service', action='create_external_service' ) )
    ]

class ExternalService( BaseUIController, UsesFormDefinitionsMixin ):
    external_service_grid = ExternalServiceGrid()

    @web.expose
    @web.require_admin
    def browse_external_services( self, trans, **kwd ):
        if 'operation' in kwd:
            operation = kwd['operation'].lower()
            obj_id = kwd.get( 'id', None )
            if operation == "view":
                return self.view_external_service( trans, **kwd )
            elif operation == "edit":