Example #1
0
async def insert(
    license: str,
    creator: str,
    data: ProjectCreate,
    client: str = None,
    contract: str = None
):
    logging.info(">>> " + __name__ + ":insert")
    logging.info(data)

    # Project otomatis memiliki seluruh modul yang tersedia
    aces_modules = await find_project_modules()
    logging.info(aces_modules)
    try:
        project = ProjectInDB(
            **data.dict(),
            license=license,
            clientId=client,
            contractId=contract,
            # admin=creator,
            createdBy=creator,
            modules=aces_modules,
        )
        logging.info("======")
        logging.info(project)
        props = fields_in_create(project)
        collection = get_collection(DOCTYPE_PROJECT)
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            return await collection.find_one({"_id": rs.inserted_id})
    except Exception as e:
        raise_server_error(str(e))
Example #2
0
async def create_doc(license: str, projectId: str, personaId: str,
                     fullname: str) -> GPQEvidence:
    logging.info(">>> " + __name__ + ":create_doc")

    # Check item numbers from project
    # Assume it is 30
    items = 30
    # Per item = 3 minutes
    maxTime = items * 3 * 60 * 1000
    seqs = [i for i in range(1, items + 1)]
    shuffle(seqs)
    strSeqs = ' '.join(map(str, seqs))
    logging.info(strSeqs)
    model = GPQEvidenceCreate(license=license,
                              projectId=projectId,
                              personaId=personaId,
                              fullname=fullname,
                              items=items,
                              maxTime=maxTime,
                              sequence=strSeqs)
    props = fields_in_create(model)
    try:
        collection = get_collection(DOCTYPE_EV_GPQ)
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            return await collection.find_one({"_id": rs.inserted_id})
    except Exception as e:
        raise_server_error(str(e.detail))
Example #3
0
async def insert(data: ModuleCreate):
    try:
        props = fields_in_create(data)
        collection = get_collection(DOCTYPE_MODULE)
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            return await collection.find_one({"_id": rs.inserted_id})
    except Exception as e:
        raise_server_error(str(e))
Example #4
0
async def insert(slug: str, client: str, data: ContractCreate):
    try:
        contract = ContractInDB(**data.dict(), license=slug, clientId=client)
        props = fields_in_create(contract)
        collection = get_collection(DOCTYPE_CONTRACT)
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            return await collection.find_one({"_id": rs.inserted_id})
    except Exception as e:
        raise_server_error(str(e))
Example #5
0
async def insert(slug: str, data: ClientCreate):
    logging.info(">>> " + __name__ + ":insert")
    collection = get_collection(DOCUMENT_TYPE)
    client = ClientWithLicense(**data.dict(), license=slug)
    props = fields_in_create(client)
    try:
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            client = await collection.find_one({"_id": rs.inserted_id})
            return client
    except Exception as e:
        raise_server_error(str(e))
Example #6
0
async def insert_one(data: LicenseCreate):
    logging.info(">>> " + __name__ + ":insert_one")
    collection = get_collection(DOCUMENT_TYPE)
    props = fields_in_create(data)
    logging.info(props)
    try:
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            license = await collection.find_one({"_id": rs.inserted_id})
            return license
    except Exception as e:
        logging.info(e)
        raise_server_error(str(e))
Example #7
0
async def o_insert(license: str, project: str, data: PersonaCreate):
    hashed_password = get_password_hash(data.password)
    model = PersonaInDB(**data.dict(),
                        license=license,
                        projectId=project,
                        hashed_password=hashed_password)
    props = fields_in_create(model)
    try:
        collection = get_collection(DOCTYPE_PERSONA)
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            member = await collection.find_one({"_id": rs.inserted_id})
            return member
    except Exception as e:
        logging.info(e)
        raise_server_error(str(e))
Example #8
0
async def insert(project: str, data: MemberCreate):
    fpwd = create_fpwd(data.username)
    hashed_password = get_password_hash(fpwd)
    model = MemberInDB(**data.dict(),
                       projectId=project,
                       hashed_password=hashed_password)
    props = fields_in_create(model)
    props["xfpwd"] = fpwd[::-1]
    try:
        collection = get_collection(DOCTYPE_PROJECT_MEMBER)
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            member = await collection.find_one({"_id": rs.inserted_id})
            return member
    except Exception as e:
        logging.info(e)
        raise_server_error(str(e))
Example #9
0
async def insert_one(license: str, data: UserCreate, license_owner: bool):
    logging.info(">>> " + __name__ + ":insert_one")
    collection = get_collection(DOCUMENT_TYPE)
    fpwd = create_fpwd(data.username)
    hashed_password = get_password_hash(fpwd)
    model = UserSave(**data.dict(),
                     license=license,
                     hashed_password=hashed_password)
    props = fields_in_create(model)
    props["xfpwd"] = fpwd[::-1]
    try:
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            user = await collection.find_one({"_id": rs.inserted_id})
            return user
    except Exception as e:
        logging.info(e)
        raise_server_error(str(e))
Example #10
0
async def insert_one(data: UserCreate):
    logging.info(">>> " + __name__ + ":insert_one")

    # Check license
    valid = await is_license_valid(data.license)
    if not valid:
        raise_bad_request("License is not valid")

    collection = get_collection(DOCUMENT_TYPE)
    hashed_password = get_password_hash(data.password)
    model = UserInDB(**data.dict(), hashed_password=hashed_password)
    props = fields_in_create(model)

    try:
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            user = await collection.find_one({"_id": rs.inserted_id})
            return user
    except Exception as e:
        logging.info(e)
        raise_server_error(str(e))
Example #11
0
async def insert(license: str, project: str, data: PersonaCreate):
    # Create temporary password
    fpwd = create_fpwd(data.username)
    hashed_password = get_password_hash(fpwd)

    model = PersonaInDB(**data.dict(),
                        license=license,
                        projectId=project,
                        hashed_password=hashed_password)
    props = fields_in_create(model)
    # Persist inverted fpwd in xfpwd
    props["xfpwd"] = fpwd[::-1]
    logging.info(fpwd)
    logging.info(props["xfpwd"])

    try:
        collection = get_collection(DOCTYPE_PERSONA)
        rs = await collection.insert_one(props)
        if rs.inserted_id:
            member = await collection.find_one({"_id": rs.inserted_id})
            return member
    except Exception as e:
        logging.info(e)
        raise_server_error(str(e))