Example #1
0
async def find_one(project: str, search: str):
    collection = get_collection(DOCTYPE_PROJECT_MEMBER)
    seek = seek_by_search(project, search)
    member = await collection.find_one(seek)
    if member:
        return member
    raise_not_found()
Example #2
0
async def find_license(slug: str):
    '''Required: `slug`'''
    logging.info(">>> " + __name__ + ":find")
    license = await crud.find_one(slug)
    if not license:
        raise_not_found("License not found.")
    return license
Example #3
0
async def create_evidence_doc(
    project: str,
    username: str,
    current_user: User = Depends(get_current_active_user)
) -> Any:
    '''TEST'''
    logging.info(">>> " + __name__ + ":create_evidence_doc")
    project = project.strip().lower()
    username = username.strip().lower()
    persona = find_persona(project, username)
    if not persona:
        raise_not_found()

    model = EvidenceBase(
        "license" = current_user.license,
        "projectId" = project,
        "username" = username,
        "fullname" = persona.fullname
    )

    # Check item numbers from project
    # Assume it is 30
    numItems = 30
    rows: List[GPQRow] = []
    seqs = [i for i in range(1, numItems + 1)]
    shuffle(seqs)
    for i in range(numItems):
        rows.append(GPQRow(
            "seq" = i + 1,
            "wbSeq" = seqs[i]
        ))
Example #4
0
async def enable(project: str, id: str, enable: bool):
    logging.info(">>> " + __name__ + ":enable")

    collection = get_collection(DOCTYPE_PROJECT)
    rs = await collection.find_one_and_update(
        {
            "_id": ObjectId(project),
            "modules": {
                "$elemMatch": {
                    "ref": id
                }
            }
        }, {
            "$set": {
                "modules.$.enabled": enable,
                "updatedAt": datetime.utcnow()
            }
        }, {
            "_id": False,
            "modules": {
                "$elemMatch": {
                    "ref": id
                }
            }
        },
        return_document=ReturnDocument.AFTER)

    if rs == None:
        raise_not_found()

    if rs and rs["modules"] and len(rs["modules"]) > 0:
        return rs["modules"][0]

    raise_server_error()
Example #5
0
async def update_one(project: str, id: str, data: ProjectModuleUpdate):
    logging.info(">>> " + __name__ + ":update_one")

    props = {"updatedAt": datetime.utcnow()}
    if data.title:
        props["modules.$.title"] = data.title
    if data.description:
        props["modules.$.description"] = data.description

    collection = get_collection(DOCTYPE_PROJECT)
    rs = await collection.find_one_and_update(
        {
            "_id": ObjectId(project),
            "modules": {
                "$elemMatch": {
                    "ref": id
                }
            }
        }, {"$set": props}, {
            "_id": False,
            "modules": {
                "$elemMatch": {
                    "ref": id
                }
            }
        },
        return_document=ReturnDocument.AFTER)

    if rs == None:
        raise_not_found()

    if rs and rs["modules"] and len(rs["modules"]) > 0:
        return rs["modules"][0]

    raise_server_error()
Example #6
0
async def update_license(slug: str, data: LicenseUpdate):
    '''Required: `slug`'''
    logging.info(">>> " + __name__ + ":update")

    license = await crud.find_one(slug)
    if not license:
        raise_not_found("License not found.")

    return await crud.update_one(slug, data)
Example #7
0
async def read_evidence_doc(
    project: str,
    personaId: str,
    current_user: User = Depends(get_current_active_user)
) -> Any:
    logging.info(">>> " + __name__ + ":read_evidence_doc")
    doc = await crud.find_one(project, personaId)
    if not doc:
        raise_not_found()
    return doc
Example #8
0
async def read_module(project: str, id: str):
    collection = get_collection(DOCTYPE_PROJECT)
    rs = await collection.find_one({"_id": ObjectId(project)}, {
        "_id": False,
        "modules": {
            "$elemMatch": {
                "ref": id
            }
        }
    })
    logging.info(rs)
    if rs and rs["modules"] and len(rs["modules"]) > 0:
        return rs["modules"][0]
    raise_not_found()
Example #9
0
async def find_one(license: str, id: str):
    logging.info(">>> " + __name__ + ":find_one")

    collection = get_collection(DOCUMENT_TYPE)
    seek = _seek_client(license, id)
    found = await collection.find_one(seek)
    return found if found else raise_not_found()
Example #10
0
async def find_one(slug: str):
    logging.info(">>> " + __name__ + ":find_one")

    collection = get_collection(DOCUMENT_TYPE)
    seek = _seek(slug)
    found = await collection.find_one(seek)
    return found if found else raise_not_found()
Example #11
0
async def create_evidence_doc(
    project: str,
    personaId: str,
    current_user: User = Depends(get_current_active_user)
) -> Any:
    '''TEST'''
    logging.info(">>> " + __name__ + ":create_evidence_doc")
    projectId = project.strip().lower()
    personaId = personaId.strip().lower()

    # Check if persona exists
    persona = await find_persona(projectId, personaId)
    if not persona:
        raise_not_found("Could not find persona.")

    # Check if doc has been created before
    doc = await crud.find_one(projectId, personaId)
    if doc:
        raise_server_error("Doc already exists in the sytem.")

    fullname = persona["fullname"]
    doc = await crud.create_doc(current_user.license, projectId, personaId, fullname)
    return doc