예제 #1
0
async def fetch_all_user_resources(conn, head_block_num, start, limit):
    return (await r.table("users").order_by(index="user_id").filter(
        (head_block_num >= r.row["start_block_num"])
        & (head_block_num < r.row["end_block_num"])).slice(
            start, start + limit).map(lambda user: user.merge({
                "id":
                user["user_id"],
                "subordinates":
                fetch_user_ids_by_manager(user["user_id"], head_block_num),
                "ownerOf":
                r.union(
                    fetch_relationships_by_id("task_owners", user["user_id"],
                                              "task_id", head_block_num),
                    fetch_relationships_by_id("role_owners", user["user_id"],
                                              "role_id", head_block_num),
                ),
                "administratorOf":
                r.union(
                    fetch_relationships_by_id("task_admins", user["user_id"],
                                              "task_id", head_block_num),
                    fetch_relationships_by_id("role_admins", user["user_id"],
                                              "role_id", head_block_num),
                ),
                "memberOf":
                fetch_relationships_by_id("role_members", user["user_id"],
                                          "role_id", head_block_num),
                "proposals":
                fetch_proposal_ids_by_opener(user["user_id"], head_block_num),
            })).map(lambda user: (user["manager_id"] != "").branch(
                user.merge({"manager": user["manager_id"]}), user)).map(
                    lambda user: (user["metadata"] == "").branch(
                        user.without("metadata"), user)).without(
                            "user_id", "manager_id", "start_block_num",
                            "end_block_num").coerce_to("array").run(conn))
예제 #2
0
async def fetch_user_resource(conn, user_id, head_block_num):
    resource = (
        await r.table("users")
        .get_all(user_id, index="user_id")
        .filter(
            (head_block_num >= r.row["start_block_num"])
            & (head_block_num < r.row["end_block_num"])
        )
        .merge(
            {
                "id": r.row["user_id"],
                "email": r.db("rbac")
                .table("auth")
                .filter({"user_id": user_id})
                .get_field("email")
                .coerce_to("array")
                .nth(0),
                "subordinates": fetch_user_ids_by_manager(user_id, head_block_num),
                "ownerOf": r.union(
                    fetch_relationships_by_id(
                        "task_owners", user_id, "task_id", head_block_num
                    ),
                    fetch_relationships_by_id(
                        "role_owners", user_id, "role_id", head_block_num
                    ),
                ),
                "administratorOf": r.union(
                    fetch_relationships_by_id(
                        "task_admins", user_id, "task_id", head_block_num
                    ),
                    fetch_relationships_by_id(
                        "role_admins", user_id, "role_id", head_block_num
                    ),
                ),
                "memberOf": fetch_relationships_by_id(
                    "role_members", user_id, "role_id", head_block_num
                ),
                "proposals": fetch_proposal_ids_by_opener(user_id, head_block_num),
            }
        )
        .map(
            lambda user: (user["manager_id"] != "").branch(
                user.merge({"manager": user["manager_id"]}), user
            )
        )
        .map(
            lambda user: (user["metadata"] == "").branch(user.without("metadata"), user)
        )
        .without("user_id", "manager_id", "start_block_num", "end_block_num")
        .coerce_to("array")
        .run(conn)
    )
    try:
        return resource[0]
    except IndexError:
        raise ApiNotFound("Not Found: No user with the id {} exists".format(user_id))
예제 #3
0
async def fetch_user_resource(conn, user_id, head_block_num):
    resource = await r.table('users')\
        .get_all(user_id, index='user_id')\
        .filter((head_block_num >= r.row['start_block_num'])
                & (head_block_num < r.row['end_block_num']))\
        .merge({
            'id': r.row['user_id'],
            'subordinates': fetch_user_ids_by_manager(
                user_id, head_block_num
            ),
            'ownerOf': r.union(
                fetch_relationships_by_id(
                    'task_owners', user_id, 'task_id', head_block_num
                ),
                fetch_relationships_by_id(
                    'role_owners', user_id, 'role_id', head_block_num
                )
            ),
            'administratorOf': r.union(
                fetch_relationships_by_id(
                    'task_admins', user_id, 'task_id', head_block_num
                ),
                fetch_relationships_by_id(
                    'role_admins', user_id, 'role_id', head_block_num
                )
            ),
            'memberOf': fetch_relationships_by_id(
                'role_members', user_id, 'role_id', head_block_num
            ),
            'proposals': fetch_proposal_ids_by_opener(
                user_id, head_block_num
            )
        })\
        .map(lambda user: (user['manager_id'] != "").branch(
            user.merge({'manager': user['manager_id']}), user
        ))\
        .map(lambda user: (user['metadata'] == "").branch(
            user.without('metadata'), user
        ))\
        .without('user_id', 'manager_id', 'start_block_num', 'end_block_num')\
        .coerce_to('array').run(conn)
    try:
        return resource[0]
    except IndexError:
        raise ApiNotFound(
            'Not Found: No user with the id {} exists'.format(user_id)
        )
예제 #4
0
async def fetch_all_user_resources(conn, head_block_num, start, limit):
    return await r.table('users')\
        .order_by(index='user_id')\
        .filter((head_block_num >= r.row['start_block_num'])
                & (head_block_num < r.row['end_block_num']))\
        .slice(start, start+limit)\
        .map(lambda user: user.merge({
            'id': user['user_id'],
            'subordinates': fetch_user_ids_by_manager(
                user['user_id'], head_block_num
            ),
            'ownerOf': r.union(
                fetch_relationships_by_id(
                    'task_owners', user['user_id'], 'task_id', head_block_num
                ),
                fetch_relationships_by_id(
                    'role_owners', user['user_id'], 'role_id', head_block_num
                )
            ),
            'administratorOf': r.union(
                fetch_relationships_by_id(
                    'task_admins', user['user_id'], 'task_id', head_block_num
                ),
                fetch_relationships_by_id(
                    'role_admins', user['user_id'], 'role_id', head_block_num
                )
            ),
            'memberOf': fetch_relationships_by_id(
                'role_members', user['user_id'], 'role_id', head_block_num
            ),
            'proposals': fetch_proposal_ids_by_opener(
                user['user_id'], head_block_num
            )
        }))\
        .map(lambda user: (user['manager_id'] != "").branch(
            user.merge({'manager': user['manager_id']}), user
        ))\
        .map(lambda user: (user['metadata'] == "").branch(
            user.without('metadata'), user
        ))\
        .without('user_id', 'manager_id', 'start_block_num', 'end_block_num')\
        .coerce_to('array').run(conn)
예제 #5
0
파일: app.py 프로젝트: daemondev/tChat
def watch_chats():
    print(
        '\n#################################\n###>>> Watching db for new chats!\n#################################\n\n'
    )
    conn = yield r.connect(host='localhost', port=28015, db='pyBOT')
    feed = yield r.table("botChat").changes().run(conn)
    union = yield r.union(
        r.table("botChat").changes(),
        r.table("botScripts").changes()).run(conn)

    while (yield feed.fetch_next()):
        change = yield feed.next()
        print("\nconexiones WS: %d\n" % len(connections))
        for c in connections:
            #change['new_val']['created'] = str(change['new_val']['created'])
            change['new_val']['ins'] = str(change['new_val']['ins'])
            payload = {"event": "new chat", "data": change["new_val"]}
            c.write_message(payload)
        print(change)
        print("watching db CHANGES ############")