def get(self): params = self.get_args(['appCode'], '') msg = self.check_str_empty_input(params, ['appCode']) if str_helper.is_null_or_empty(msg) == False: self.out_fail(code = 1001, msg = msg) return funcs = func_logic.query_all_by_app(appCode = params['appCode']) self.out_ok(funcs) return
def post(self): self.check_oper_right(right = state.operEdit) ps = self.get_page_config(title = '编辑角色权限') ps['roleID'] = int(self.get_arg('roleID', '0')) ps['appCode'] = self.get_arg('appCode', '') funcs = func_logic.query_all_by_app(ps['appCode']) #获得应用下的所有功能 funcs = role_logic.init_func_right(funcs) rights = [] for func in funcs: #收集权限数据 map = {} map['funcID'] = func['id'] r = int(self.get_arg(('right_%d_1' % func['id']), '0')) r = r + int(self.get_arg(('right_%d_2' % func['id']), '0')) r = r + int(self.get_arg(('right_%d_4' % func['id']), '0')) r = r + int(self.get_arg(('right_%d_8' % func['id']), '0')) func['right'] = r map['right'] = r customRight = '' if func['customJson'] != None: for c in func['customJson']: cid = self.get_arg(('rightcustom_%d_%s' % (func['id'], c['k'])), '') if cid != '': customRight = customRight + cid + ',' c['right'] = True else: c['right'] = False if customRight != '': customRight = ',' + customRight map['customRight'] = customRight rights.append(map) #保存权限信息 type = role_logic.add_right_by_role_app(appCode = ps['appCode'], roleID = ps['roleID'], rights = rights, user = self.get_oper_user()) roles = role_logic.query_all_by_active() apps = application_logic.query_all_by_active() ps['apps'] = apps ps['roles'] = roles ps = self.format_none_to_empty(ps) ps['funcs'] = funcs if type: self.write_oper_log(action = 'roleSetRight', targetType = 5, targetID = str(ps['roleID']), targetName = ps['appCode'], startStatus = '', endStatus= str_helper.json_encode(rights)) ps = self.get_ok_and_back_params(ps = ps, refUrl = ps['refUrl']) else: ps['msg'] = state.ResultInfo.get(104004, '') self.render('admin/role/right_edit.html', **ps)
def post(self): self.check_oper_right(right = state.operEdit) ps = self.get_page_config(title = '编辑角色权限') ps['roleID'] = int(self.get_arg('roleID', '0')) ps['appCode'] = self.get_arg('appCode', '') funcs = func_logic.query_all_by_app(ps['appCode']) #获得应用下的所有功能 funcs = role_logic.init_func_right(funcs) rights = [] for func in funcs: #收集权限数据 map = {} map['funcID'] = func['id'] r = int(self.get_arg(('right_%d_1' % func['id']), '0')) r = r + int(self.get_arg(('right_%d_2' % func['id']), '0')) r = r + int(self.get_arg(('right_%d_4' % func['id']), '0')) r = r + int(self.get_arg(('right_%d_8' % func['id']), '0')) func['right'] = r map['right'] = r customRight = '' if func['customJson'] != None: for c in func['customJson']: cid = self.get_arg(('rightcustom_%d_%s' % (func['id'], c['k'])), '') if cid != '': customRight = customRight + cid + ',' c['right'] = True else: c['right'] = False if customRight != '': customRight = ',' + customRight map['customRight'] = customRight rights.append(map) #保存权限信息 type = role_logic.add_right_by_role_app(appCode = ps['appCode'], roleID = ps['roleID'], rights = rights, user = self.get_oper_user()) roles = role_logic.query_all_by_active() apps = application_logic.query_all_by_active() ps['apps'] = apps ps['roles'] = roles ps = self.format_none_to_empty(ps) ps['funcs'] = funcs if type: self.write_oper_log(action = 'roleSetRight', targetType = 5, targetID = str(ps['roleID']), targetName = ps['appCode'], startStatus = '', endStatus= str_helper.json_encode(rights)) ps = self.get_ok_and_back_params(ps = ps, refUrl = ps['refUrl']) else: ps['msg'] = state.ResultInfo.get(104004, '') self.render('admin/role/right_edit_bs.html', **ps)
def query_user_group_app_right( userGroupID, appCode, funcs = None): '''查询用户组对应应用的权限信息''' if None == funcs: funcs = func_logic.query_all_by_app(appCode) funcs = role_logic.init_func_right(funcs) if funcs == None or len(funcs) <= 0: return funcs roles = query_all_group_roles(userGroupID) if None == roles or len(roles) <= 0: return funcs for role in roles: funcs = role_logic.format_role_func_right(appCode=appCode, roleID = role['roleID'], funcs = funcs) return funcs
def get_funcs_tree_by_appCode(self, appCode, appName): funcs = func_logic.query_all_by_app(appCode) if None == funcs: funcs = [] funcs.insert(0, {'id':0, 'parentID': -1, 'name': appName, 'open': True}) tree = '[' t = True for func in funcs: if t: t = False tree = '%s{id: %d, pId: %d, name: "%s", open: true}' % (tree, func['id'], func['parentID'], func['name'].replace('"','\\"')) else: tree = '%s,{id: %d, pId: %d, name: "%s", open: true}' % (tree, func['id'], func['parentID'], func['name'].replace('"','\\"')) tree = '%s]' % (tree) return tree
def query_user_group_app_right(userGroupID, appCode, funcs=None): '''查询用户组对应应用的权限信息''' if None == funcs: funcs = func_logic.query_all_by_app(appCode) funcs = role_logic.init_func_right(funcs) if funcs == None or len(funcs) <= 0: return funcs roles = query_all_group_roles(userGroupID) if None == roles or len(roles) <= 0: return funcs for role in roles: funcs = role_logic.format_role_func_right(appCode=appCode, roleID=role['roleID'], funcs=funcs) return funcs
def get(self): ps = self.get_page_config(title = '应用功能列表') apps = application_logic.query_all_by_active() if None == apps or len(apps) <= 0: ps['msg'] = state.ResultInfo.get(101004, '') ps['gotoUrl'] = ps['siteDomain'] + 'Admin/Application/Add' ps['apps'] = [] ps['funcs'] = [] self.render('admin/func/list.html', **ps) return appCode = self.get_arg('appCode', apps[0]['code']) ps['apps'] = apps appName = '' for app in apps: if app['code'] == appCode: appName = app['name'] break ps['funcs'] = func_logic.query_all_by_app(appCode) ps['appCode'] = appCode self.render('admin/func/list.html', **ps)
def get(self): ps = self.get_page_config(title = '应用功能列表') apps = application_logic.query_all_by_active() if None == apps or len(apps) <= 0: ps['msg'] = state.ResultInfo.get(101004, '') ps['gotoUrl'] = ps['siteDomain'] + 'Admin/Application/Add' ps['apps'] = [] ps['funcs'] = [] self.render('admin/func/list.html', **ps) return appCode = self.get_arg('appCode', apps[0]['code']) ps['apps'] = apps appName = '' for app in apps: if app['code'] == appCode: appName = app['name'] break ps['funcs'] = func_logic.query_all_by_app(appCode) ps['appCode'] = appCode self.render('admin/func/list_bs.html', **ps)
def get(self): ps = self.get_page_config(title = '编辑角色权限', refUrl = config.SOCRightConfig['siteDomain'] + 'Admin/Role/List') ps['roleID'] = int(self.get_arg('roleID', '0')) ps['appCode'] = self.get_arg('appCode', '') ps['roles'] = [] ps['apps'] = [] roles = role_logic.query_all_by_active() if None == roles or len(roles) == 0: ps['msg'] = state.ResultInfo.get(104003, '') ps['refUrl'] = ps['siteDomain'] +'Admin/Role/Add' self.render('admin/role/right_edit.html', **ps) return else: if 0 == ps['roleID']: ps['roleID'] = roles[0]['id'] apps = application_logic.query_all_by_active() if None == apps or len(apps) == 0: ps['msg'] = state.ResultInfo.get(104003, '') ps['refUrl'] = ps['siteDomain'] +'Admin/Application/Add' self.render('admin/role/right_edit.html', **ps) return else: if '' == ps['appCode']: ps['appCode'] = apps[0]['code'] ps['apps'] = apps ps['roles'] = roles ps = self.format_none_to_empty(ps) funcs = func_logic.query_all_by_app(ps['appCode']) #获得应用下的所有功能 if None != funcs and len(funcs) > 0: funcs = role_logic.init_func_right(funcs) funcs = role_logic.format_role_func_right(appCode = ps['appCode'], roleID = ps['roleID'], funcs = funcs) else: funcs = [] ps['funcs'] = funcs if self.is_edit(): self.check_oper_right(right = state.operEdit) self.render('admin/role/right_edit.html', **ps) else: self.check_oper_right(right = state.operView) self.render('admin/role/right_detail.html', **ps)
def get(self): ps = self.get_page_config(title = '编辑角色权限', refUrl = config.SOCRightConfig['siteDomain'] + 'Admin/Role/List') ps['roleID'] = int(self.get_arg('roleID', '0')) ps['appCode'] = self.get_arg('appCode', '') ps['roles'] = [] ps['apps'] = [] roles = role_logic.query_all_by_active() if None == roles or len(roles) == 0: ps['msg'] = state.ResultInfo.get(104003, '') ps['refUrl'] = ps['siteDomain'] +'Admin/Role/Add' self.render('admin/role/right_edit_bs.html', **ps) return else: if 0 == ps['roleID']: ps['roleID'] = roles[0]['id'] apps = application_logic.query_all_by_active() if None == apps or len(apps) == 0: ps['msg'] = state.ResultInfo.get(104003, '') ps['refUrl'] = ps['siteDomain'] +'Admin/Application/Add' self.render('admin/role/right_edit_bs.html', **ps) return else: if '' == ps['appCode']: ps['appCode'] = apps[0]['code'] ps['apps'] = apps ps['roles'] = roles ps = self.format_none_to_empty(ps) funcs = func_logic.query_all_by_app(ps['appCode']) #获得应用下的所有功能 if None != funcs and len(funcs) > 0: funcs = role_logic.init_func_right(funcs) funcs = role_logic.format_role_func_right(appCode = ps['appCode'], roleID = ps['roleID'], funcs = funcs) else: funcs = [] ps['funcs'] = funcs if self.is_edit(): self.check_oper_right(right = state.operEdit) self.render('admin/role/right_edit_bs.html', **ps) else: self.check_oper_right(right = state.operView) self.render('admin/role/right_detail_bs.html', **ps)
def query_user_app_right( userID, appCode): user = query_one(userID) if user == None: return None funcs = func_logic.query_all_by_app(appCode) if None == funcs or len(funcs) <= 0: return None ''' 初始化权限 ''' funcs = role_logic.init_func_right(funcs) ''' 统计绑定的用户组权限 ''' userGroups = usergroup_logic.query_all_user_groups(userID) if userGroups != None and len(userGroups) > 0: for userGroup in userGroups: funcs = usergroup_logic.query_user_group_app_right(userGroupID = userGroup['userGroupID'], appCode = appCode, funcs = funcs) ''' 统计绑定的角色权限 ''' roles = query_all_user_roles(userID) if None != roles and len(roles) > 0: for role in roles: funcs = role_logic.format_role_func_right(appCode = appCode, roleID = role['roleID'], funcs = funcs) return funcs