#!/bin/env python import os, sys, logging, threading, time, string from sqlalchemy import * import subprocess import re from pprint import * ## needed to sort complex data structures from operator import itemgetter, attrgetter def _get_apps_ACL () : """ Gets the apps ACLs per user """ apps = {} userlist = [] f=open('../external_dbs/acl_applications.txt', 'r') for line in f : (appname, users) = line.split("##") appname = appname.rstrip() appname = appname.lstrip() users = users.rstrip() users = users.lstrip() userlist = users.split(',') apps[appname] = userlist f.close() return apps def get_apps_to_display ( all_apps_from_tool_conf, user_email) : """ Filters the apps ACLs for the logged user """ acl_apps = _get_apps_ACL() to_display = [] for app in all_apps_from_tool_conf : if app in acl_apps.keys() : ## ALL open app : check app's permissions if "ALL" in acl_apps[app] : ## app - open to ALL (no users listed after ALL) if len(acl_apps[app]) == 1 : to_display.append(app) ## check if there are still some listed users who don't have permission to use the app despite of allowed ALL elif len(acl_apps[app]) > 1 : if user_email in acl_apps[app] : continue else : to_display.append(app) ## restricted app ## check if the user is authorised for this restricted app elif user_email in acl_apps[app] : to_display.append(app) ## skip if not authorised else : continue else : print "The ACLs for the application <<< %s >>> have not been set. Please add it to the file /home/galaxy/externaldb/acl_applications.txt!! " % app return to_display