Exemplo n.º 1
0
def user_list(appname, page=0, page_size=PAGE_SIZE, searchKeyword=None):
    """
        list api for show user list.

        Request URL:  /appname/auth/user/list

        Http Method:  GET

        Parameters : None

        Return :
        {
        "status":0
        "data":{
                "items":[
                {
                "_id":"2",
                "user_name":"admin",
                "email":"*****@*****.**",
                "permission_list":[19,20,21,22]
                },
                {
                    "_id":4,
                    "user_name":"translator",
                    "email":"*****@*****.**",
                    "permission_list":[22,23]
                }
                ]
                }
            }

     """
    cond = {}
    if searchKeyword:
        cond = search_cond(appname, searchKeyword)
    fields = {"password": 0, "super": 0, "permission_list": 0, "department": 0, "is_superuser": 0}
    sort = [("last_login", -1)]
    user_cursor = User.find_users(appname, cond, fields)
    if sort is not None:
        user_cursor = user_cursor.sort(sort)
    user_cursor = user_cursor.skip(page * page_size).limit(page_size)
    total = User.find_users(appname, cond).count()
    users = []
    for item in user_cursor:
        item["id"] = item.pop("_id")
        item["last_login"] = unixto_string(item.get("last_login"))
        item["role"] = get_role(appname, item["group_id"])
        users.append(item)
    data = {}
    data.setdefault("items", users)
    data.setdefault("total", total)
    return json_response_ok(data)
Exemplo n.º 2
0
def user_info(appname, gid):
    """
        get user info by group id

        Parameters : groupid

        Return :
        {
            "items":[
                {
                    "id":2,
                    "user_name":"*****@*****.**",
                    "role":[19,20,21,22],
                    "last_login":"******",
                    "total_login": 2,
                    "mark": ""
                },
                {
                    "id":2,
                    "user_name":"*****@*****.**",
                    "role":[19,20,21,22],
                    "last_login":"******",
                    "total_login": 2,
                    "mark": ""
                }
            ]
        }

     """
    cond = {"group_id": gid}
    fields = {"password": 0, "super": 0, "permission_list": 0, "department": 0, "is_superuser": 0}
    sort = [("last_login", -1)]
    user_cursor = User.find_users(appname, cond, fields).sort(sort)
    users = []
    for item in user_cursor:
        item["id"] = item.pop("_id")
        item["last_login"] = unixto_string(item.get("last_login"))
        item["role"] = get_role(appname, item["group_id"])
        users.append(item)
    return users