Esempio n. 1
0
async def update_module(
    project: str,
    id: str,
    data: ProjectModuleUpdate,
    current_user: User = Depends(get_current_project_admin)):
    logging.info(">>> " + __name__ + ":update_module")
    if (not data.title) and (not data.description):
        raise_bad_request("Nothing to update")
    return await crud.update_one(project, id, data)
Esempio n. 2
0
async def create_client(slug: str,
                        data: ClientCreate,
                        current_user: User = Depends(get_current_active_user)):
    logging.info(">>> " + __name__ + ":create_client")
    slug = slug.strip().lower()
    found = await find_license(slug)
    if not found:
        raise_bad_request("License is not valid.")
    return await crud.insert(slug, data)
Esempio n. 3
0
async def set_simulations(
    project: str,
    search: str,
    sims: List[str],
    current_user: User = Depends(get_current_project_admin)):
    logging.info(">>> " + __name__ + ":set_simulations")

    if len(sims) == 0:
        raise_bad_request("Sims cannot be empty")
    return await crud.set_simulations(project, search, sims)
Esempio n. 4
0
async def delete(search: str):
    '''
    Search: `id`, `username`, or `email`.
    '''
    logging.info(">>> " + __name__ + ":find")
    user = await crud.find_one(search)
    if not user:
        raise_not_found("User not found.")
    if user['licenseOwner']:
        raise_bad_request("Could not delete license owner.")
    return await crud.delete(search)
Esempio n. 5
0
async def update_module(id: str):
    id = id.strip().lower()

    if not ObjectId.is_valid(id):
        raise_bad_request("Not valid module ID.")

    module = await crud.find_one(id)
    if not module:
        raise_not_found()

    return await crud.delete(id)
Esempio n. 6
0
async def find_project(license: str, id: str):
    id = id.strip().lower()

    if not ObjectId.is_valid(id):
        raise_bad_request("Not valid project ID.")

    project = await crud.find_one(license, id)
    if not project:
        raise_not_found()

    return project
Esempio n. 7
0
async def add_persona(project: str,
                      data: PersonaCreate,
                      current_user: User = Depends(get_current_project_admin)):
    logging.info(">>> " + __name__ + ":add_persona")
    persona = await crud.find_by_email_or_username(project, data.email,
                                                   data.username)
    logging.info(persona)
    if persona:
        raise_bad_request(
            "Username or email is already registered in the system.")

    return await crud.insert(current_user.license, project, data)
Esempio n. 8
0
async def delete_license_user(
    slug: str,
    search: str,
    current_user: User = Depends(get_current_license_owner)):
    logging.info(">>> " + __name__ + ":find")
    slug = slug.strip().lower()
    user = await crud.find_license_user(slug, search)
    if not user:
        raise_not_found("User not found.")
    if user['licenseOwner']:
        raise_bad_request("Could not delete license owner.")
    return await crud.delete(search)
Esempio n. 9
0
async def add_member(project: str,
                     data: MemberCreate,
                     current_user: User = Depends(get_current_project_admin)):
    logging.info(">>> " + __name__ + ":add_member")
    member = await crud.find_by_email_or_username(project, data.email,
                                                  data.username)
    logging.info(member)
    if member:
        raise_bad_request(
            "Username or email is already registered in the system.")

    return await crud.insert(project, data)
Esempio n. 10
0
async def set_tests(project: str,
                    search: str,
                    tests: List[str],
                    current_user: User = Depends(get_current_project_admin)):
    logging.info(">>> " + __name__ + ":set_tests")

    persona = await crud.find_one(project, search)
    if not persona:
        raise_not_found("Could not find persona.")

    if len(tests) == 0:
        raise_bad_request("Tests cannot be empty")
    return await crud.set_tests(project, search, tests)
Esempio n. 11
0
async def find_client(slug: str,
                      id: str,
                      current_user: User = Depends(get_current_active_user)):
    '''slug: license's slug or * (all)'''
    logging.info(">>> " + __name__ + ":find_client")
    slug = slug.strip().lower()
    id = id.strip().lower()
    found = await find_license(slug)
    if not found:
        raise_bad_request("License is not valid.")
    client = await crud.find_one(slug, id)
    if client:
        return client
    raise_not_found("Not found.")
Esempio n. 12
0
async def find_project(
    slug: str, id: str,
    current_user: User = Depends(get_current_active_user)) -> Any:
    slug = slug.strip().lower()
    id = id.strip().lower()

    if not ObjectId.is_valid(id):
        raise_bad_request("Not valid project ID.")

    project = await crud.find_one(slug, id)
    if not project:
        raise_not_found()

    return project
Esempio n. 13
0
async def create_project(
    slug: str,
    data: ProjectCreate,
    current_user: User = Depends(get_current_project_admin),
    client: str = None,
    contract: str = None,
) -> Any:
    logging.info(">>> " + __name__ + ":create_project")
    slug = slug.strip().lower()

    if client:
        client = client.strip().lower()
        if not ObjectId.is_valid(client):
            raise_bad_request("Not valid client id.")
        db_client = await find_client(slug, id=client)
        if not db_client:
            raise_bad_request("Client reference not found.")

    if contract:
        contract = contract.strip().lower()
        if not ObjectId.is_valid(contract):
            raise_bad_request("Not valid contract id.")
        db_client = await find_contract(slug, id=contract)
        if not db_client:
            raise_bad_request("Contract reference not found.")

    creator = current_user.username
    if not data.admin:
        data.admin = creator
    return await crud.insert(slug, creator, data, client, contract)
Esempio n. 14
0
async def update_contract(
    slug: str, id: str, current_user: User = Depends(get_current_active_user)):
    slug = slug.strip().lower()
    id = id.strip().lower()

    # TODO: If there are related projects, CANCEL

    if not ObjectId.is_valid(id):
        raise_bad_request("Not valid license ID.")

    contract = await crud.find_one(slug, id)
    if not contract:
        raise_not_found()

    return await crud.delete(slug, id)
Esempio n. 15
0
async def create_license_user(
    slug: str,
    data: UserCreate,
    current_user: User = Depends(get_current_active_user)):
    logging.info(">>> " + __name__ + ":create")
    slug = slug.strip().lower()
    # data.license = license
    logging.info(data)
    model = UserCreate(**data.dict())
    # model.license = slug
    logging.info(model)
    user = await crud.find_by_email_or_username(data.email, data.username)
    if user:
        raise_bad_request(
            "Username or email is already registered in the system.")
    return await crud.insert_one(slug, model, license_owner=False)
Esempio n. 16
0
async def create_contract(
    slug: str,
    client: str,
    data: ContractCreate,
    current_user: User = Depends(get_current_active_user)):
    slug = slug.strip().lower()
    client = client.strip().lower()

    if not ObjectId.is_valid(client):
        raise_bad_request("Not valid client id.")

    # Check client
    db_client = await find_client(slug, id=client)
    if not db_client:
        raise_bad_request("Client not found.")

    return await crud.insert(slug, client, data)
Esempio n. 17
0
async def update_contract(
    slug: str,
    id: str,
    data: ContractUpdate,
    current_user: User = Depends(get_current_active_user)):
    '''
    Pricing harus update whole array.
    '''
    slug = slug.strip().lower()
    id = id.strip().lower()

    if not ObjectId.is_valid(id):
        raise_bad_request("Not valid license ID.")

    contract = await crud.find_one(slug, id)
    if not contract:
        raise_not_found()

    return await crud.update(slug, id, data)
Esempio n. 18
0
async def delete_project(
    slug: str,
    id: str,
    current_user: User = Depends(get_current_project_admin)) -> Any:
    slug = slug.strip().lower()
    id = id.strip().lower()

    if not crud.is_valid_project_admin(current_user, id):
        raise HTTPException(status_code=400,
                            detail="You'r not the admin of the project.")

    if not ObjectId.is_valid(id):
        raise_bad_request("Not valid license ID.")

    project = await crud.find_one(slug, id)
    if not project:
        raise_not_found()

    return await crud.delete(slug, id)
Esempio n. 19
0
async def create_license_owner(data: UserCreate):
    '''
    Required: `license, name, username, email, password`
    '''
    logging.info(">>> " + __name__ + ":create")
    license = await find_license(data.license)
    if not license:
        raise_bad_request("Could not find license with the specified slug")

    user = await crud.find_license_owner(data.license)
    if user:
        raise_bad_request("License owner user already exists in the system.")

    user = await crud.find_by_email_or_username(data.email, data.username)
    if user:
        raise_bad_request(
            'Email or username is already registered in the system.')

    return await crud.insert_license_owner(data)