Example #1
0
def group_get(appname, gid):
    '''
        this api is used to view one group
        Request URL: /auth/user/{gid}
        HTTP Method:GET
        Return:
            Parameters: None
            {
                "status":0
                "data":{
                "item":[
                    {
                        "id":"2",
                        "role":"admin",
                        "last_login":"******"
                    }
            }
    '''
    group_info = Group.find_one_group(appname, {"_id": gid})
    if not group_info:
        return json_response_error(PARAM_ERROR, msg="the group not exist")
    group_info = user_info(appname, gid)
    data = {}
    data.setdefault("items", group_info)
    return json_response_ok(data)
Example #2
0
def get_check_uids(
        appname, projectname, applabel, module,
        action="checked", perm_lc="all"):
    # get perm id
    perm_name = '%s-%s-%s' % (applabel, module, action)
    right_cond = {
        'perm_name': perm_name, 'app_name': projectname, "lc": perm_lc}
    perm = Right.find_one(appname, right_cond)
    if not perm:
        _LOGGER.error("the right:%s not exist" % perm_name)
    #get user who has this right
    check_ids = []
    perm_id = perm["_id"]
    perm_key = "permission_list.%s" % projectname
    group_cond = {perm_key: perm_id}
    groups_info = Group.find(appname, group_cond)
    group_ids = [i["_id"] for i in groups_info]
    for gid in group_ids:
        group_info = user_info(appname, gid)
        user_ids = [i["id"] for i in group_info]
        check_ids += user_ids

    user_cond = {perm_key: perm_id}
    users_info = User.find(appname, user_cond)
    user_ids = [i["_id"] for i in users_info]
    check_ids += user_ids
    check_ids = list(set(check_ids))
    return check_ids
Example #3
0
def group_delete(appname, gid):
    '''
    this api is used to delete group,when one group removed,the user who
    in this group ,the group id will remove too.
    Request URL: /auth/group/delete
    HTTP Method: POST
    Parameters:
        {
            "gids":3
        }
    Return:
     {
     "status":0
     "data":{}
     "msg":"delete successfully"
     }
    '''
    gid = int(gid)
    group = Group.find_one_group(appname, {"_id": gid}, None)
    data = {"id": gid}
    if group:
        users = user_info(appname, int(gid))
        if users:
            _LOGGER.info("group id %s is refer" % gid)
            return json_response_error(DATA_RELETED_BY_OTHER, data)
        else:
            Group.del_group(appname, gid)
            return json_response_ok(data, msg="delete group success")
    else:
        _LOGGER.info("group id %s is not exist" % gid)
        return json_response_error(
            PARAM_ERROR, data, msg="invalid group id,check parameters")