Exemple #1
0
def list_label(appname):
    data = {}
    label = []
    app_names = NAV_DICT.keys()
    for app_name in app_names:
        app_dict = {}
        app_display = NAV_DICT.get(app_name)
        app_dict.setdefault("display_value", app_display)
        app_dict.setdefault("value", app_name)
        label.append(app_dict)
    data.setdefault("navigate", label)
    return json_response_ok(data, msg="")
Exemple #2
0
def init_navigate_list(appname, uid):
    '''
    return values like below:
        [
            {
            "display_value":"环信",
            "value":"square_console"
            }
        ]
    '''
    assert uid
    cond = {"_id": uid}
    user_info = User.find_one_user(appname, cond, None)
    app_names = []
    if user_info.get("is_superuser"):
        app_names = Right.find_right(
            appname, {}, {"app_name": 1}, toarray=True)
    else:
        user_right_info = user_info.get("permission_list")
        # get user privately-owned right
        for app_name in user_right_info:
            if user_right_info.get(app_name):
                app_names.append(app_name)

        # get user publicly-owned right
        gids = user_info.get("group_id")
        if gids:
            for gid in gids:
                group_info = Group.find_one_group(appname, {"_id": gid}, None)
                if group_info:
                    group_right_info = group_info.get("permission_list")
                    for app_name in group_right_info:
                        if group_right_info.get(app_name):
                            app_names.append(app_name)
                else:
                    _LOGGER.error("group id:%s error", gid)
    navigates = []
    if app_names:
        app_names = list(set(app_names))
        for app_name in app_names:
            app_dict = {}
            app_display = NAV_DICT.get(app_name)
            app_dict.setdefault("display_value", app_display)
            app_dict.setdefault("value", app_name)
            navigates.append(app_dict)
    return navigates
Exemple #3
0
    def wrapper(*args, **kwargs):
        # check projectname args
        projectname = kwargs.get("projectname")
        if projectname:
            if projectname not in NAV_DICT.keys():
                return json_response_error(
                    PARAM_ERROR, msg="invalid projectname: %s" % projectname)

        # check appname args
        appname = kwargs.get("appname")
        if appname not in MONGO_CONFIG:
            return json_response_error(
                PARAM_ERROR, msg="appname error, check url")

        # check applabel args
        applabel = kwargs.get("applabel")
        if applabel:
            app_cond = {'name': applabel, "app_name": projectname}
            if not App.find_one(appname, app_cond):
                return json_response_error(
                    PARAM_ERROR, msg="the app label not exist")

        # check module args
        module = kwargs.get("module")
        if module:
            module_cond = {'module_name': module, "app_name": projectname}
            if not Module.find_one(appname, module_cond):
                return json_response_error(
                    PARAM_ERROR, msg="the app module not exist")

        # check id args
        id = kwargs.get("id")
        if id:
            try:
                id = int(id)
            except ValueError:
                return json_response_error(PARAM_ERROR, msg="id error")
        return func(*args, **kwargs)
Exemple #4
0
def get_project_value(project):
    return NAV_DICT.get(project)