def removeUser(request): userid = request.unauthenticated_userid userToRemove = request.params['couserName'] hubName = request.params['hubName'] Hubs.removeUserFromHub(hubName, userid, userToRemove) url = request.route_url('myHubs') return HTTPFound(location=url)
def addUser(request): newUser = request.params['userEmail'] hubName = request.params['hubName'] owner = request.params['owner'] Hubs.addUserToHub(hubName, owner, newUser) url = request.route_url('myHubs') return HTTPFound(location=url)
def getProblems(data, txn=None): if 'genome' not in data: data['genome'] = getGenome(data, txn=txn) problems = db.Problems(data['genome']) problemsInBounds = problems.getInBounds(data['ref'], data['start'], data['end']) if problemsInBounds is None: problemsPath = os.path.join(cfg.jbrowsePath, cfg.dataPath, 'genomes', data['genome'], 'problems.bed') if not os.path.exists(problemsPath): location = Hubs.generateProblems(data['genome'], problemsPath) if not location == problemsPath: raise Exception problemsDf = pd.read_csv(problemsPath, sep='\t', header=None) problemsDf.columns = problemColumns problems.put(problemsDf, txn=txn) problemsIsInBounds = problemsDf.apply(db.checkInBounds, axis=1, args=(data['ref'], data['start'], data['end'])) return problemsDf[problemsIsInBounds].to_dict('records') else: return problemsInBounds.to_dict('records')
def isPublic(request): query = request.matchdict hubName = query['hub'] user = query['user'] chkpublic = "chkpublic" in request.params.keys() hub = db.HubInfo(user, hubName).get() hub['isPublic'] = chkpublic db.HubInfo(user, hubName).put(hub) if chkpublic: Hubs.addUserToHub(hubName, user, 'Public') elif 'Public' in hub['users']: Hubs.removeUserFromHub(hubName, user, 'Public') url = request.route_url('myHubs') return HTTPFound(location=url)
def uploadHubUrl(request): user = request.authenticated_userid if 'POST' == request.method: # TODO: Implement user authentication (and maybe an anonymous user if not request.json_body['args']['hubUrl']: return url = request.json_body['args']['hubUrl'] hubName = "" if request.json_body['args']['hubName']: hubName = request.json_body['args']['hubName'] return Hubs.parseHub({'user': user, 'url': url, 'hubName': hubName}) return
def myHubs(request): userid = request.authenticated_userid everyKey = db.HubInfo.keysWhichMatch(db.HubInfo) hubInfos = Hubs.getHubInfos(everyKey, userid) labels = {} usersdict = {} permissions = {} for hubName in hubInfos: currHubInfo = hubInfos[hubName] owner = currHubInfo['owner'] usersdict[hubName] = currHubInfo[ 'users'] if 'users' in currHubInfo.keys() else [] everyLabelKey = db.Labels.keysWhichMatch(owner, hubName) num_labels = 0 for key in everyLabelKey: if key[0] == userid or userid in hubInfos[key[1]]['users']: num_labels += db.Labels(*key).get().shape[0] labels[hubName] = num_labels # get each co users permissions for couser in usersdict[hubName]: permissions[(hubName, couser)] = db.Permissions(owner, hubName, couser).get() return { "user": userid, "hubInfos": hubInfos, "usersdict": usersdict, "permissions": permissions, "labels": labels }
def hubInfo(request): query = request.matchdict return Hubs.getHubInfo(query['user'], query['hub'])