view primsfilters.py @ 27:ecd3f6c9e606

small fix to support spaces in parameters
author pieter.lukasse@wur.nl
date Thu, 01 May 2014 11:19:52 +0200
parents cd4f13119afa
children
line wrap: on
line source

import logging
log = logging.getLogger( __name__ )


def restrict_prims_metabolomics( context, tool ):
    """
    This tool filter will hide prims_metabolomics tools for non-metabolomics users. 
    This can be enabled by adding the following to the
     ``app:main`` section of ``universe_wsgi.ini``::

        tool_filters = primsfilters:restrict_prims_metabolomics
        
    and by adding this file to the folder:
    
        <galaxy-dist>/lib/galaxy/tools/filters
        
    This is optional and can be used in case some control is desired on whom 
    gets to see the prims_metabolomics tools. When not using this file and the 
    settings mentioned above, all prims_metabolomics tools will be visible to 
    all users.  
    """
    # for debugging: import pydevd;pydevd.settrace("L0136815.wurnet.nl")
    user = context.trans.user
    metabolomics_tools = [ "msclust2", "combine_output", "create_poly_model", "lookup_library", 
                          "NDIStext2tabular", "rankfilterGCMS_tabular", "filter_on_rank",
                          "export_to_metexp_tabular", "query_metexp" ]
    found_match = False
    # iterate over the tool (partial)ids and look for a match (this is compatible with tool shed given ids):
    for partial_id in metabolomics_tools:
        if tool.id.find("/"+ partial_id + "/") >= 0:
            found_match = True
            break
    # the second part of this if is compatible with the ids when NOT using tool shed:    
    if found_match or tool.id in metabolomics_tools: 
        # logging.warn( 'FILTER MATCHED: %s' %(tool.name))        
    
        for user_role in user.roles:
            if user_role.role.name == "PRIMS_METABOLOMICS":
                return True
        # not found to have the role, return false:
        return False
    else:
        # return true for any other tool
        return True