def delete_searches(dataset: str, x: int, y: int, z: int, user: User = Depends(get_user)): if not user.has_role("clio_general", dataset): raise HTTPException( status_code=401, detail= f"user does not have permission to delete searches in dataset {dataset_id}" ) try: # delete only supported from interface # (delete by dataset + user name + xyz) collection = firestore.get_collection( [CLIO_SAVEDSEARCHES, "USER", "searches"]) match_list = collection.where("email", "==", user.email).where( "locationkey", "==", f"{x}_{y}_{z}").where("dataset", "==", dataset).get() for match in match_list: match.reference.delete() except Exception as e: print(e) raise HTTPException( status_code=400, detail=f"error in deleting saved searches for dataset {dataset}")
def searches(dataset: str, x: int, y: int, z: int, payload: dict, user: User = Depends(get_user)): if not user.has_role("clio_general", dataset): raise HTTPException( status_code=401, detail= f"user does not have permission to write searches to dataset {dataset_id}" ) try: # we only allow one annotation per email and location key so if it exists, replace. payload["timestamp"] = time.time() payload["dataset"] = dataset payload["location"] = [x, y, z] payload["locationkey"] = f"{x}_{y}_{z}" payload["email"] = user.email collection = firestore.get_collection( [CLIO_SAVEDSEARCHES, "USER", "searches"]) collection.document().set(payload) except Exception as e: print(e) raise HTTPException( status_code=400, detail= f"error in put annotation ({x},{y},{z}) for dataset {dataset}")
def get_signature(user: User, dataset: str, point: tuple): if not user.has_role("clio_general", dataset): raise HTTPException(status_code=403, detail="user doesn't have authorization") try: pt, sig = fetch_signature(dataset, *point) res = {"point": pt, "signature": str(sig)} except Exception as e: res = {"messsage": str(e)} return res
def get_matches(user: User, dataset: str, point: tuple): if not user.has_role("clio_general", dataset): raise HTTPException(status_code=403, detail="user doesn't have authorization") try: data = find_similar_signatures(dataset, *point) res = {"matches": data} if len(data) == 0: res["message"] = "no matches" except Exception as e: res = {"messsage": str(e)} return res
async def post_neuprint_custom(dataset: str, payload: NeuprintRequest, user: User = Depends(get_user)): if not user.has_role("clio_general", dataset): raise HTTPException(status_code=403, detail="user doesn't have authorization for this dataset") cur_dataset = get_dataset(dataset) if cur_dataset.neuprintHTTP: neuprint_server = cur_dataset.neuprintHTTP.server else: raise HTTPException(status_code=400, detail=f"dataset {dataset} has no assigned neuprint server") try: async with client_session.post(f'https://{neuprint_server}/api/custom/custom', data=payload.json(), headers=neuprint_headers) as resp: response = await resp.json() except Exception as e: print(e) raise HTTPException(status_code=400, detail=f"error in neuprint request for dataset {dataset}") return response
def get_searches(dataset: str, user: User = Depends(get_user)): if not user.has_role("clio_general", dataset): raise HTTPException( status_code=401, detail=f"user does not have permission to read dataset {dataset_id}" ) try: collection = firestore.get_collection( [CLIO_SAVEDSEARCHES, "USER", "searches"]) searches = collection.where("email", "==", user.email).where("dataset", "==", dataset).get() output = {} for search in searches: res = search.to_dict() res["id"] = search.id output[res["locationkey"]] = res return output except Exception as e: print(e) raise HTTPException( status_code=400, detail=f"error in getting saved searches for dataset {dataset}")
def post_atlas(dataset: str, x: int, y: int, z: int, payload: dict, user: User = Depends(get_user)) -> dict: if "title" not in payload or "user" not in payload: raise HTTPException( status_code=400, detail=f"POSTed object must include 'title' and 'user' properties") if not user.can_write_own(dataset): raise HTTPException( status_code=401, detail=f"no permission to write annotations in dataset {dataset}") if payload["user"] != user.email and not user.can_write_others(dataset): raise HTTPException( status_code=401, detail= f"no permission to write others' annotations in dataset {dataset}") if "verified" in payload and payload["verified"] and not user.has_role( "clio_write", dataset): raise HTTPException( status_code=401, detail=f"no permission to set verified status in dataset {dataset}" ) try: location_key = f"{x}_{y}_{z}" collection = firestore.get_collection( [CLIO_ANNOTATIONS, "ATLAS", "annotations"]) annotations = collection.where("user", "==", payload["user"]) \ .where("dataset", "==", dataset) \ .where("locationkey", "==", f"{x}_{y}_{z}").get() payload["timestamp"] = time.time() payload["dataset"] = dataset payload["location"] = [x, y, z] payload["locationkey"] = location_key if len(annotations) == 0: new_ref = collection.document() payload["id"] = new_ref.id if "verified" in payload: if payload["verified"] and not user.has_role( "clio_write", dataset): raise HTTPException( status_code=401, detail=f"no permission to set verified atlas pt") else: payload["verified"] = False new_ref.set(payload) else: first = True for annotation in annotations: if first: current = annotation.to_dict() if "verified" in current and current[ "verified"] and not user.has_role( "clio_write", dataset): raise HTTPException( status_code=401, detail=f"no permission to modify verified atlas pt" ) payload["id"] = annotation.id annotation.reference.set(payload) first = False else: # shouldn't happen unless legacy bad points. print( f"deleted duplicate atlas annotation point: {annotation}" ) annotation.reference.delete() return payload except HTTPException as e: raise e except Exception as e: print(e) raise HTTPException( status_code=400, detail= f"error in put annotation ({x},{y},{z}) for dataset {dataset}: {e}" )