async def find_history(req): """ Find history changes for a specific index. """ db = req.app["db"] index_id = req.match_info["index_id"] if not await db.indexes.count({"_id": index_id}): return not_found() term = req.query.get("term", None) db_query = {"index.id": index_id} if term: db_query.update(compose_regex_query(term, ["otu.name", "user.id"])) data = await paginate(db.history, db_query, req.query, sort=[("otu.name", 1), ("otu.version", -1)], projection=virtool.history.db.LIST_PROJECTION, reverse=True) return json_response(data)
async def find(req): db = req.app["db"] term = req.query.get("find", None) db_query = dict() if term: db_query = compose_regex_query(term, ["name", "data_type"]) base_query = virtool.references.db.compose_base_find_query( req["client"].user_id, req["client"].administrator, req["client"].groups) data = await paginate(db.references, db_query, req.query, sort="name", base_query=base_query, processor=virtool.utils.base_processor, projection=virtool.references.db.PROJECTION) for d in data["documents"]: latest_build, otu_count, unbuilt_count = await asyncio.gather( virtool.references.db.get_latest_build(db, d["id"]), virtool.references.db.get_otu_count(db, d["id"]), virtool.references.db.get_unbuilt_count(db, d["id"])) d.update({ "latest_build": latest_build, "otu_count": otu_count, "unbuilt_change_count": unbuilt_count }) return json_response(data)
async def find(req): db = req.app["db"] ids = req.query.get("ids", False) if ids: return json_response(await db.subtraction.distinct("_id")) host_count = await db.subtraction.count({"is_host": True}) ready_host_count = await db.subtraction.count({ "is_host": True, "ready": True }) term = req.query.get("find", None) db_query = dict() if term: db_query.update(compose_regex_query(term, ["_id"])) data = await paginate(db.subtraction, db_query, req.query, sort="_id", projection=virtool.subtractions.db.PROJECTION) data.update({ "host_count": host_count, "ready_host_count": ready_host_count }) return json_response(data)
async def find(db, names, term, req_query, verified, ref_id=None): db_query = dict() if term: db_query.update(compose_regex_query(term, ["name", "abbreviation"])) if verified is not None: db_query["verified"] = virtool.utils.to_bool(verified) base_query = None if ref_id is not None: base_query = { "reference.id": ref_id } if names is True or names == "true": cursor = db.otus.find({**db_query, **base_query}, ["name"], sort=[("name", 1)]) return [virtool.utils.base_processor(d) async for d in cursor] data = await paginate( db.otus, db_query, req_query, base_query=base_query, sort="name", projection=PROJECTION ) data["modified_count"] = len(await db.history.find({"index.id": "unbuilt"}, ["otu"]).distinct("otu.name")) return data
async def find(req): """ Get a list of all user documents in the database. """ db = req.app["db"] term = req.query.get("find", None) db_query = dict() if term: db_query.update(compose_regex_query(term, ["_id"])) data = await paginate(db.users, db_query, req.query, sort="_id", projection=virtool.users.db.PROJECTION) return json_response(data)
async def find(req): """ Return a list of job documents. """ db = req.app["db"] term = req.query.get("find", None) db_query = dict() if term: db_query.update(compose_regex_query(term, ["task", "user.id"])) data = await paginate(db.jobs, db_query, req.query, projection=virtool.jobs.db.PROJECTION, processor=virtool.jobs.db.processor) data["documents"].sort(key=lambda d: d["created_at"]) return json_response(data)
async def find_analyses(req): """ List the analyses associated with the given ``sample_id``. """ db = req.app["db"] sample_id = req.match_info["sample_id"] try: if not await virtool.samples.db.check_rights( db, sample_id, req["client"], write=False): return insufficient_rights() except virtool.errors.DatabaseError as err: if "Sample does not exist" in str(err): return not_found() raise term = req.query.get("term", None) db_query = dict() if term: db_query.update( compose_regex_query(term, ["reference.name", "user.id"])) base_query = {"sample.id": sample_id} data = await paginate(db.analyses, db_query, req.query, base_query=base_query, projection=virtool.analyses.db.PROJECTION, sort=[("created_at", -1)]) return json_response(data)
async def find(req): """ Find HMM annotation documents. """ db = req.app["db"] term = req.query.get("find", None) db_query = dict() if term: db_query.update(compose_regex_query(term, ["names"])) data = await paginate(db.hmm, db_query, req.query, sort="cluster", projection=virtool.hmm.db.PROJECTION, base_query={"hidden": False}) data["status"] = await virtool.hmm.db.get_status(db) return json_response(data)
async def find(req): """ Find samples, filtering by data passed as URL parameters. """ db = req.app["db"] algorithm_query = virtool.samples.db.compose_analysis_query(req.query) v = Validator(QUERY_SCHEMA, allow_unknown=True) if not v.validate(dict(req.query)): return invalid_query(v.errors) query = v.document rights_filter = [ # The requesting user is the sample owner { "user.id": req["client"].user_id }, # The sample rights allow all users to view the sample. { "all_read": True } ] if req["client"].groups: # The sample rights allow owner group members to view the sample and the requesting user is a member of # the owner group. rights_filter.append({ "group_read": True, "group": { "$in": req["client"].groups } }) base_query = {"$or": rights_filter} db_query = dict() term = query.get("find", None) if term: db_query = compose_regex_query(term, ["name", "user.id"]) if algorithm_query: if db_query: db_query = {"$and": [db_query, algorithm_query]} else: db_query = algorithm_query data = await paginate(db.samples, db_query, req.query, sort="created_at", projection=virtool.samples.db.LIST_PROJECTION, base_query=base_query, reverse=True) return json_response(data)