def getInfo(identity): if is_number(identity): ident_str = "ID(p)={identity}" else: ident_str = "p.email={identity}" person = {} result = db.run("MATCH (p:Person) WHERE " + ident_str + " RETURN ID(p) AS id, p.surname AS surname, p.forename as forename, p.email AS email, " + "p.url AS url, p.location AS location, p.tagline AS tagline, p.is_admin AS is_admin, p.is_disabled AS is_disabled, p.nyunetid AS nyunetid", {"identity": identity}) for p in result: repo_count = 0 repos = db.run("MATCH (r:Repository)--(p:Person) WHERE " + ident_str + " RETURN COUNT(r) AS repo_count", {"identity": identity}) for r in repos: repo_count = r["repo_count"] person['id'] = p['id'] person['name'] = str(p['forename']) + " " + str(p['surname']) person['surname'] = p['surname'] person['forename'] = p['forename'] person['email'] = p['email'] person['url'] = p['url'] person['location'] = p['location'] person['tagline'] = p['tagline'] person['is_admin'] = p['is_admin'] person['is_disabled'] = p['is_disabled'] person['nyunetid'] = p['nyunetid'] person['repo_count'] = repo_count return person
def getRepos(identity): repos = [] if is_number(identity): ident_str = "ID(p)={identity}" else: ident_str = "p.email={identity}" result = db.run("MATCH (n:Repository)<-[x:OWNED_BY|COLLABORATES_WITH]-(p) WHERE " + ident_str + " RETURN ID(n) AS id, n.name AS name, n.readme AS readme, n.published AS published, n.license AS license, " + "n.url AS url, n.created_on AS created_on, n.published_on as published_on, n.featured as featured, x.access AS access", {"identity": identity}) for item in result: owner = lib.managers.RepoManager.RepoManager.getOwner(int(item['id'])) data = lib.managers.RepoManager.RepoManager.getData(int(item['id'])) users = lib.managers.RepoManager.RepoManager.getUsers(int(item['id'])) repos.append({ "id": item['id'], "name": item['name'], "readme": item['readme'], "created_on": item['created_on'], "published_on": item['published_on'], "featured": item['featured'], "url": item['url'], "data": data, "users": users, "owner": owner, "access": item['access'], "published": item['published'], "license": item['license'], "schema_type_count" : 0, "schema_field_count" : 0, "data_element_count": 0 }) for item in repos: result = db.run( "MATCH (n:Repository)--(t:SchemaType)--(d:Data) WHERE ID(n) = {repo_id} RETURN count(d) as data_element_count", {"repo_id": int(item['id'])}) for r in result: item['data_element_count'] = r['data_element_count'] result = db.run( "MATCH (n:Repository)--(t:SchemaType)WHERE ID(n) = {repo_id} RETURN count(DISTINCT(t)) as schema_type_count", {"repo_id": int(item['id'])}) for r in result: item['schema_type_count'] = r['schema_type_count'] result = db.run( "MATCH (n:Repository)--(t:SchemaType)--(f:SchemaField) WHERE ID(n) = {repo_id} RETURN count(DISTINCT(t)) as schema_type_count, count(DISTINCT(f)) as schema_field_count", {"repo_id": int(item['id'])}) for r in result: item['schema_field_count'] = r['schema_field_count'] return repos
def getRepoIDs(identity): repoIDs = [] if is_number(identity): ident_str = "ID(p)={identity}" else: ident_str = "p.email={identity}" result = db.run("MATCH (n:Repository)<-[x:OWNED_BY|COLLABORATES_WITH]-(p) WHERE " + ident_str + " RETURN ID(n) AS repo_id", {"identity": identity}) for item in result: repoIDs.append(item['repo_id']) return repoIDs
def getRepoIDs(identity): repoIDs = [] if is_number(identity): ident_str = "ID(p)={identity}" else: ident_str = "p.email={identity}" result = db.run( "MATCH (n:Repository)<-[x:OWNED_BY|COLLABORATES_WITH]-(p) WHERE " + ident_str + " RETURN ID(n) AS repo_id", {"identity": identity}) for item in result: repoIDs.append(item['repo_id']) return repoIDs
def setPassword(person_id, password): # TODO: verify user has access to update password... if password is not None: if is_number(person_id): find_str = "ID(p)={person_id}" else: find_str = "p.password_reset_key = {person_id}" db_password_hash = '' # check if password matches person_id result = db.run( "MATCH (p:Person) WHERE " + find_str + " RETURN p.password AS password", {"person_id": person_id}) for p in result: db_password_hash = p['password'] if db_password_hash != '': # hash new password and update DB new_pass_hash = sha256_crypt.hash(password) if db_password_hash == new_pass_hash: return True result = db.run( "MATCH (p:Person) WHERE " + find_str + " SET p.password = {new_pass_hash}, p.password_reset_key = '' RETURN p", { "person_id": person_id, "new_pass_hash": new_pass_hash }) # Check we updated something summary = result.consume() if summary.counters.properties_set >= 1: return True return False else: raise FindError("No user found") else: raise AuthError("Password is empty")
def getInfo(identity): if is_number(identity): ident_str = "ID(p)={identity}" else: ident_str = "p.email={identity}" person = {} result = db.run( "MATCH (p:Person) WHERE " + ident_str + " RETURN ID(p) AS id, p.surname AS surname, p.forename as forename, p.email AS email, " + "p.url AS url, p.location AS location, p.tagline AS tagline, p.is_admin AS is_admin, p.is_disabled AS is_disabled, p.nyunetid AS nyunetid", {"identity": identity}) for p in result: repo_count = 0 repos = db.run( "MATCH (r:Repository)--(p:Person) WHERE " + ident_str + " RETURN COUNT(r) AS repo_count", {"identity": identity}) for r in repos: repo_count = r["repo_count"] person['id'] = p['id'] person['name'] = str(p['forename']) + " " + str(p['surname']) person['surname'] = p['surname'] person['forename'] = p['forename'] person['email'] = p['email'] person['url'] = p['url'] person['location'] = p['location'] person['tagline'] = p['tagline'] person['is_admin'] = p['is_admin'] person['is_disabled'] = p['is_disabled'] person['nyunetid'] = p['nyunetid'] person['repo_count'] = repo_count return person
def setPassword(person_id, password): # TODO: verify user has access to update password... if password is not None: if is_number(person_id): find_str = "ID(p)={person_id}" else: find_str = "p.password_reset_key = {person_id}" db_password_hash = '' # check if password matches person_id result = db.run("MATCH (p:Person) WHERE " + find_str + " RETURN p.password AS password", {"person_id": person_id}) for p in result: db_password_hash = p['password'] if db_password_hash != '': # hash new password and update DB new_pass_hash = sha256_crypt.hash(password) if db_password_hash == new_pass_hash: return True result = db.run("MATCH (p:Person) WHERE " + find_str + " SET p.password = {new_pass_hash}, p.password_reset_key = '' RETURN p", {"person_id": person_id, "new_pass_hash": new_pass_hash}) # Check we updated something summary = result.consume() if summary.counters.properties_set >= 1: return True return False else: raise FindError("No user found") else: raise AuthError("Password is empty")
def editPerson(identity, forename, surname, location, email, url, tagline, is_disabled, nyunetid): if is_number(identity): ident_str = "ID(p)={identity}" identity = int(identity) else: ident_str = "p.email={identity}" update = [] if forename is not None: update.append("p.forename = {forename}") if surname is not None: update.append("p.surname = {surname}") if location is not None: update.append("p.location = {location}") if email is not None: update.append("p.email = {email}") if url is not None: update.append("p.url = {url}") if tagline is not None: update.append("p.tagline = {tagline}") if nyunetid is not None: update.append("p.nyunetid = {nyunetid}") if is_disabled is not None: print is_disabled try: is_disabled = int(is_disabled) if is_disabled <> 0: is_disabled = 1 update.append("p.is_disabled = {is_disabled}") except: pass update_str = "%s" % ", ".join(map(str, update)) if update_str != '' and update_str is not None: result = db.run("MATCH (p:Person) WHERE " + ident_str + " SET " + update_str + " RETURN p.forename AS forename, p.surname AS surname, p.location AS location, p.email AS email, p.url AS url, p.tagline AS tagline, p.is_disabled AS is_disabled, p.nyunetid AS nyunetid", {"identity": identity, "forename": forename, "surname": surname, "location": location, "email": email, "url": url, "tagline": tagline, "is_disabled": is_disabled, "nyunetid": nyunetid}) if result: updated_person = {} for p in result: updated_person['forename'] = p['forename'] updated_person['surname'] = p['surname'] updated_person['name'] = str(p['forename']) + " " + str(p['surname']) updated_person['location'] = p['location'] updated_person['email'] = p['email'] updated_person['url'] = p['url'] updated_person['tagline'] = p['tagline'] updated_person['is_disabled'] = p['is_disabled'] updated_person['nyunetid'] = p['nyunetid'] if updated_person is not None: return updated_person else: raise FindError(message="Person does not exist", context="People.editPerson") else: raise DbError(message="Could not update person", context="People.editPerson", dberror="") else: raise ValidationError(message="Nothing to update", context="People.editPerson")
def editPerson(identity, forename, surname, location, email, url, tagline, is_disabled, nyunetid): if is_number(identity): ident_str = "ID(p)={identity}" identity = int(identity) else: ident_str = "p.email={identity}" update = [] if forename is not None: update.append("p.forename = {forename}") if surname is not None: update.append("p.surname = {surname}") if location is not None: update.append("p.location = {location}") if email is not None: update.append("p.email = {email}") if url is not None: update.append("p.url = {url}") if tagline is not None: update.append("p.tagline = {tagline}") if nyunetid is not None: update.append("p.nyunetid = {nyunetid}") if is_disabled is not None: print is_disabled try: is_disabled = int(is_disabled) if is_disabled <> 0: is_disabled = 1 update.append("p.is_disabled = {is_disabled}") except: pass update_str = "%s" % ", ".join(map(str, update)) if update_str != '' and update_str is not None: result = db.run( "MATCH (p:Person) WHERE " + ident_str + " SET " + update_str + " RETURN p.forename AS forename, p.surname AS surname, p.location AS location, p.email AS email, p.url AS url, p.tagline AS tagline, p.is_disabled AS is_disabled, p.nyunetid AS nyunetid", { "identity": identity, "forename": forename, "surname": surname, "location": location, "email": email, "url": url, "tagline": tagline, "is_disabled": is_disabled, "nyunetid": nyunetid }) if result: updated_person = {} for p in result: updated_person['forename'] = p['forename'] updated_person['surname'] = p['surname'] updated_person['name'] = str(p['forename']) + " " + str( p['surname']) updated_person['location'] = p['location'] updated_person['email'] = p['email'] updated_person['url'] = p['url'] updated_person['tagline'] = p['tagline'] updated_person['is_disabled'] = p['is_disabled'] updated_person['nyunetid'] = p['nyunetid'] if updated_person is not None: return updated_person else: raise FindError(message="Person does not exist", context="People.editPerson") else: raise DbError(message="Could not update person", context="People.editPerson", dberror="") else: raise ValidationError(message="Nothing to update", context="People.editPerson")
def getRepos(identity): repos = [] if is_number(identity): ident_str = "ID(p)={identity}" else: ident_str = "p.email={identity}" result = db.run( "MATCH (n:Repository)<-[x:OWNED_BY|COLLABORATES_WITH]-(p) WHERE " + ident_str + " RETURN ID(n) AS id, n.name AS name, n.readme AS readme, n.published AS published, n.license AS license, " + "n.url AS url, n.created_on AS created_on, n.published_on as published_on, n.featured as featured, x.access AS access", {"identity": identity}) for item in result: owner = lib.managers.RepoManager.RepoManager.getOwner( int(item['id'])) data = lib.managers.RepoManager.RepoManager.getData(int( item['id'])) users = lib.managers.RepoManager.RepoManager.getUsers( int(item['id'])) repos.append({ "id": item['id'], "name": item['name'], "readme": item['readme'], "created_on": item['created_on'], "published_on": item['published_on'], "featured": item['featured'], "url": item['url'], "data": data, "users": users, "owner": owner, "access": item['access'], "published": item['published'], "license": item['license'], "schema_type_count": 0, "schema_field_count": 0, "data_element_count": 0 }) for item in repos: result = db.run( "MATCH (n:Repository)--(t:SchemaType)--(d:Data) WHERE ID(n) = {repo_id} RETURN count(d) as data_element_count", {"repo_id": int(item['id'])}) for r in result: item['data_element_count'] = r['data_element_count'] result = db.run( "MATCH (n:Repository)--(t:SchemaType)WHERE ID(n) = {repo_id} RETURN count(DISTINCT(t)) as schema_type_count", {"repo_id": int(item['id'])}) for r in result: item['schema_type_count'] = r['schema_type_count'] result = db.run( "MATCH (n:Repository)--(t:SchemaType)--(f:SchemaField) WHERE ID(n) = {repo_id} RETURN count(DISTINCT(t)) as schema_type_count, count(DISTINCT(f)) as schema_field_count", {"repo_id": int(item['id'])}) for r in result: item['schema_field_count'] = r['schema_field_count'] return repos