Ejemplo n.º 1
0
async def fetch_open_proposals(request, next_id):
    """Get open proposals for a user, by their next_id.
    Args:
        request:
            obj: request object to api
        next_id:
            str: next_id of user for open proposals as assigned_approval
    """
    log_request(request)
    head_block = await get_request_block(request)
    start, limit = get_request_paging_info(request)
    conn = await create_connection()
    proposals = await proposals_query.fetch_all_proposal_resources(
        conn, start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(conn, proposal)
        proposal_resources.append(proposal_resource)
    conn.close()
    open_proposals = []
    for proposal_resource in proposal_resources:
        if (proposal_resource["status"] == "OPEN"
                and next_id in proposal_resource["assigned_approver"]):
            open_proposals.append(proposal_resource)

    return await create_response(conn,
                                 request.url,
                                 open_proposals,
                                 head_block,
                                 start=start,
                                 limit=limit)
Ejemplo n.º 2
0
async def fetch_confirmed_proposals(request, user_id):

    conn = await db_utils.create_connection(
        request.app.config.DB_HOST,
        request.app.config.DB_PORT,
        request.app.config.DB_NAME,
    )

    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    proposals = await proposals_query.fetch_all_proposal_resources(
        conn, head_block.get("num"), start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(
            conn, proposal, head_block.get("num"))
        proposal_resources.append(proposal_resource)

    confirmed_proposals = []
    for proposal_resource in proposal_resources:
        if (proposal_resource["status"] == "CONFIRMED"
                and user_id in proposal_resource["approvers"]):
            confirmed_proposals.append(proposal_resource)

    conn.close()

    return await utils.create_response(conn,
                                       request.url,
                                       confirmed_proposals,
                                       head_block,
                                       start=start,
                                       limit=limit)
Ejemplo n.º 3
0
async def fetch_confirmed_proposals(request, next_id):
    """Get confirmed proposals for a user, by their next_id."""
    log_request(request)
    head_block = await get_request_block(request)
    start, limit = get_request_paging_info(request)
    conn = await create_connection()
    proposals = await proposals_query.fetch_all_proposal_resources(
        conn, start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(conn, proposal)
        proposal_resources.append(proposal_resource)
    conn.close()

    confirmed_proposals = []
    for proposal_resource in proposal_resources:
        if (proposal_resource["status"] == "CONFIRMED"
                and next_id in proposal_resource["approvers"]):
            confirmed_proposals.append(proposal_resource)

    return await create_response(conn,
                                 request.url,
                                 confirmed_proposals,
                                 head_block,
                                 start=start,
                                 limit=limit)
Ejemplo n.º 4
0
async def fetch_rejected_proposals(request, user_id):
    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    proposals = await proposals_query.fetch_all_proposal_resources(
        request.app.config.DB_CONN, head_block.get("num"), start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(
            request.app.config.DB_CONN, proposal, head_block.get("num"))
        proposal_resources.append(proposal_resource)

    rejected_proposals = []
    for proposal_resource in proposal_resources:
        if (proposal_resource["status"] == "REJECTED"
                and user_id in proposal_resource["approvers"]):
            rejected_proposals.append(proposal_resource)

    return await utils.create_response(
        request.app.config.DB_CONN,
        request.url,
        rejected_proposals,
        head_block,
        start=start,
        limit=limit,
    )
Ejemplo n.º 5
0
async def fetch_open_proposals(request, next_id):
    """Get open proposals for a user, by their next_id."""
    conn = await create_connection()

    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    proposals = await proposals_query.fetch_all_proposal_resources(
        conn, start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(conn, proposal)
        proposal_resources.append(proposal_resource)

    open_proposals = []
    for proposal_resource in proposal_resources:
        if (proposal_resource["status"] == "OPEN"
                and next_id in proposal_resource["approvers"]):
            open_proposals.append(proposal_resource)

    conn.close()

    return await utils.create_response(conn,
                                       request.url,
                                       open_proposals,
                                       head_block,
                                       start=start,
                                       limit=limit)
Ejemplo n.º 6
0
async def fetch_confirmed_proposals(request, next_id):
    """Get confirmed proposals for a user, by their next_id."""
    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    proposals = await proposals_query.fetch_all_proposal_resources(
        request.app.config.DB_CONN, start, limit
    )
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(
            request.app.config.DB_CONN, proposal
        )
        proposal_resources.append(proposal_resource)

    confirmed_proposals = []
    for proposal_resource in proposal_resources:
        if (
            proposal_resource["status"] == "CONFIRMED"
            and next_id in proposal_resource["approvers"]
        ):
            confirmed_proposals.append(proposal_resource)

    return await utils.create_response(
        request.app.config.DB_CONN,
        request.url,
        confirmed_proposals,
        head_block,
        start=start,
        limit=limit,
    )
Ejemplo n.º 7
0
async def fetch_rejected_proposals(request, next_id):
    """Get confirmed proposals for a user, by their next_id."""
    conn = await db_utils.create_connection(
        request.app.config.DB_HOST,
        request.app.config.DB_PORT,
        request.app.config.DB_NAME,
    )

    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    proposals = await proposals_query.fetch_all_proposal_resources(
        conn, start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(conn, proposal)
        proposal_resources.append(proposal_resource)

    rejected_proposals = []
    for proposal_resource in proposal_resources:
        if (proposal_resource["status"] == "REJECTED"
                and next_id in proposal_resource["approvers"]):
            rejected_proposals.append(proposal_resource)

    conn.close()

    return await utils.create_response(conn,
                                       request.url,
                                       rejected_proposals,
                                       head_block,
                                       start=start,
                                       limit=limit)
Ejemplo n.º 8
0
async def get_all_roles(request):
    """Get all roles."""
    conn = await create_connection()

    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    role_resources = await roles_query.fetch_all_role_resources(conn, start, limit)
    conn.close()
    return await utils.create_response(
        conn, request.url, role_resources, head_block, start=start, limit=limit
    )
Ejemplo n.º 9
0
async def fetch_recommended_roles(request, user_id):
    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    recommended_resources = await roles_query.fetch_recommended_resources(
        request.app.config.DB_CONN, user_id, head_block.get("num"), 0, 6)
    return await utils.create_response(
        request.app.config.DB_CONN,
        request.url,
        recommended_resources,
        head_block,
        start=start,
        limit=limit,
    )
Ejemplo n.º 10
0
async def get_all_roles(request):
    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    role_resources = await roles_query.fetch_all_role_resources(
        request.app.config.DB_CONN, head_block.get("num"), start, limit)
    return await utils.create_response(
        request.app.config.DB_CONN,
        request.url,
        role_resources,
        head_block,
        start=start,
        limit=limit,
    )
Ejemplo n.º 11
0
async def fetch_all_users(request):
    head_block = await utils.get_request_block(request)
    LOGGER.info(head_block)
    start, limit = utils.get_request_paging_info(request)
    user_resources = await users_query.fetch_all_user_resources(
        request.app.config.DB_CONN, head_block.get("num"), start, limit)
    return await utils.create_response(
        request.app.config.DB_CONN,
        request.url,
        user_resources,
        head_block,
        start=start,
        limit=limit,
    )
Ejemplo n.º 12
0
async def get_all_tasks(request):
    """Get all tasks."""
    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    task_resources = await tasks_query.fetch_all_task_resources(
        request.app.config.DB_CONN, start, limit)
    return await utils.create_response(
        request.app.config.DB_CONN,
        request.url,
        task_resources,
        head_block,
        start=start,
        limit=limit,
    )
Ejemplo n.º 13
0
async def fetch_all_users(request):
    """Returns all users."""
    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    user_resources = await users_query.fetch_all_user_resources(
        request.app.config.DB_CONN, start, limit)
    return await utils.create_response(
        request.app.config.DB_CONN,
        request.url,
        user_resources,
        head_block,
        start=start,
        limit=limit,
    )
Ejemplo n.º 14
0
async def get_all_proposals(request):
    """Get all proposals"""
    log_request(request)
    head_block = await get_request_block(request)
    start, limit = get_request_paging_info(request)
    conn = await create_connection()
    proposals = await proposals_query.fetch_all_proposal_resources(conn, start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(conn, proposal)
        proposal_resources.append(proposal_resource)
    conn.close()
    return await create_response(
        conn, request.url, proposal_resources, head_block, start=start, limit=limit
    )
Ejemplo n.º 15
0
async def fetch_all_users(request):
    """Returns all users."""
    log_request(request)
    head_block = await get_request_block(request)
    start, limit = get_request_paging_info(request)
    conn = await create_connection()
    user_resources = await users_query.fetch_all_user_resources(
        conn, start, limit)
    conn.close()

    return await create_response(conn,
                                 request.url,
                                 user_resources,
                                 head_block,
                                 start=start,
                                 limit=limit)
Ejemplo n.º 16
0
async def get_all_tasks(request):
    """Get all tasks."""
    log_request(request)
    head_block = await get_request_block(request)
    start, limit = get_request_paging_info(request)
    conn = await create_connection()
    task_resources = await tasks_query.fetch_all_task_resources(
        conn, start, limit)
    conn.close()

    return await create_response(conn,
                                 request.url,
                                 task_resources,
                                 head_block,
                                 start=start,
                                 limit=limit)
Ejemplo n.º 17
0
async def get_all_blocks(request):
    """Get all blocks."""
    conn = await create_connection()
    log_request(request)
    head_block = await get_request_block(request)
    start, limit = get_request_paging_info(request)
    block_resources = await blocks_query.fetch_all_blocks(
        conn, head_block.get("num"), start, limit)
    conn.close()

    return await create_response(conn,
                                 request.url,
                                 block_resources,
                                 head_block,
                                 start=start,
                                 limit=limit)
Ejemplo n.º 18
0
async def get_all_tasks(request):

    conn = await db_utils.create_connection(
        request.app.config.DB_HOST,
        request.app.config.DB_PORT,
        request.app.config.DB_NAME,
    )

    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    task_resources = await tasks_query.fetch_all_task_resources(
        conn, head_block.get("num"), start, limit
    )
    conn.close()
    return await utils.create_response(
        conn, request.url, task_resources, head_block, start=start, limit=limit
    )
Ejemplo n.º 19
0
async def get_all_proposals(request):
    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    proposals = await proposals_query.fetch_all_proposal_resources(
        request.app.config.DB_CONN, head_block.get("num"), start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(
            request.app.config.DB_CONN, proposal, head_block.get("num"))
        proposal_resources.append(proposal_resource)
    return await utils.create_response(
        request.app.config.DB_CONN,
        request.url,
        proposal_resources,
        head_block,
        start=start,
        limit=limit,
    )
Ejemplo n.º 20
0
async def get_all_proposals(request):
    """Get all proposals"""
    conn = await db_utils.create_connection(
        request.app.config.DB_HOST,
        request.app.config.DB_PORT,
        request.app.config.DB_NAME,
    )

    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    proposals = await proposals_query.fetch_all_proposal_resources(conn, start, limit)
    proposal_resources = []
    for proposal in proposals:
        proposal_resource = await compile_proposal_resource(conn, proposal)
        proposal_resources.append(proposal_resource)
    conn.close()
    return await utils.create_response(
        conn, request.url, proposal_resources, head_block, start=start, limit=limit
    )
Ejemplo n.º 21
0
async def fetch_recommended_roles(request, user_id):

    conn = await db_utils.create_connection(
        request.app.config.DB_HOST,
        request.app.config.DB_PORT,
        request.app.config.DB_NAME,
    )

    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)
    recommended_resources = await roles_query.fetch_all_role_resources(
        conn, head_block.get("num"), 0, 10)

    conn.close()

    return await utils.create_response(conn,
                                       request.url,
                                       recommended_resources,
                                       head_block,
                                       start=start,
                                       limit=limit)
Ejemplo n.º 22
0
async def fetch_all_users(request):
    """Returns all users."""
    conn = await db_utils.create_connection(
        request.app.config.DB_HOST,
        request.app.config.DB_PORT,
        request.app.config.DB_NAME,
    )

    head_block = await utils.get_request_block(request)

    start, limit = utils.get_request_paging_info(request)
    user_resources = await users_query.fetch_all_user_resources(
        conn, start, limit)

    conn.close()

    return await utils.create_response(conn,
                                       request.url,
                                       user_resources,
                                       head_block,
                                       start=start,
                                       limit=limit)
Ejemplo n.º 23
0
async def get_all_packs(request):
    """Get all packs"""
    head_block = await utils.get_request_block(request)
    start, limit = utils.get_request_paging_info(request)

    conn = await db_utils.create_connection(
        request.app.config.DB_HOST,
        request.app.config.DB_PORT,
        request.app.config.DB_NAME,
    )

    pack_resources = await packs_query.fetch_all_pack_resources(
        conn, start, limit)

    conn.close()

    return await utils.create_response(conn,
                                       request.url,
                                       pack_resources,
                                       head_block,
                                       start=start,
                                       limit=limit)