def dept_index(): dept_list = Role.query.order_by(Role.pid.asc()).all() list = [] if dept_list: dept_data = {} for item in dept_list: if not item.pid and item.id not in dept_data: dept_data[item.id] = { "self": item, "sub": [] } if item.pid: dept_data[item.pid]['sub'].append( item ) for item in dept_data.values(): list.append( item['self'] ) list.extend( item['sub']) set_flag = RBACService.checkPageRelatePrivilege("set") ops_flag = RBACService.checkPageRelatePrivilege("ops") return UtilHelper.renderView("home/rbac/dept/index.html", { "list": list, "set_flag": set_flag, "ops_flag": ops_flag, } )
def grant_index(): req = request.values kw = req.get("kw", "").strip() page = int(req.get("p", 1)) query = Action.query if kw: query = query.filter( or_(Action.name.ilike('%{}%'.format(kw)), Action.level1_name.ilike('%{}%'.format(kw)), Action.level2_name.ilike('%{}%'.format(kw)))) page_params = { "total": query.count(), "page_size": CommonConstant.PAGE_SIZE, "page": page, "display": CommonConstant.PAGE_DISPLAY } pages = UtilHelper.iPagination(page_params) offset = (page - 1) * CommonConstant.PAGE_SIZE limit = CommonConstant.PAGE_SIZE * page list = query.order_by(Action.id.desc())[offset:limit] sc = {"kw": kw} set_flag = RBACService.checkPageRelatePrivilege("set") ops_flag = RBACService.checkPageRelatePrivilege("ops") return UtilHelper.renderView( "home/rbac/grant/index.html", { "list": list, "pages": pages, "sc": sc, "set_flag": set_flag, "ops_flag": ops_flag, })
def grant_index(): req = request.values page = int(req.get("p", 1)) query = Action.query page_params = { "total": query.count(), "page_size": CommonConstant.PAGE_SIZE, "page": page, "display": CommonConstant.PAGE_DISPLAY } pages = UtilHelper.iPagination(page_params) offset = (page - 1) * CommonConstant.PAGE_SIZE limit = CommonConstant.PAGE_SIZE * page list = query.order_by(Action.id.desc())[offset:limit] sc = {} set_flag = RBACService.checkPageRelatePrivilege("set") ops_flag = RBACService.checkPageRelatePrivilege("ops") return UtilHelper.renderView("home/rbac/grant/index.html", { "list": list, "pages": pages, "sc": sc, "set_flag": set_flag, "ops_flag": ops_flag, } )
def server_index(): req = request.values kw = req.get("kw", "").strip() page = int(req.get("p", 1)) query = JobServer.query if kw: query = query.filter(JobServer.name.ilike('%{}%'.format(kw))) page_params = { "total": query.count(), "page_size": CommonConstant.PAGE_SIZE, "page": page, "display": CommonConstant.PAGE_DISPLAY } pages = UtilHelper.iPagination(page_params) offset = (page - 1) * CommonConstant.PAGE_SIZE limit = CommonConstant.PAGE_SIZE * page list = query.order_by(JobServer.id.desc())[offset:limit] data = [] server_env_map = CommonConstant.server_env_map if list: for item in list: tmp_data = ModelHelper.model2Dict(item) tmp_env_ids = (item.env).strip( CommonConstant.special_strike).split( CommonConstant.special_strike) tmp_env_list = [] for _env_id in tmp_env_ids: if int(_env_id) not in server_env_map.keys(): continue tmp_env_list.append(server_env_map.get(int(_env_id))) tmp_data['env'] = ",".join(tmp_env_list) data.append(tmp_data) sc = {'kw': kw} set_flag = RBACService.checkPageRelatePrivilege("set") ops_flag = RBACService.checkPageRelatePrivilege("ops") return UtilHelper.renderView( "home/job/server/index.html", { "list": data, "pages": pages, "server_env_map": CommonConstant.server_env_map, "sc": sc, "set_flag": set_flag, "ops_flag": ops_flag })
def before_request(): ignore_urls = app.config['IGNORE_URLS_HOME'] ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS'] path = request.path #如果是静态文件就不要查询用户信息了 pattern = re.compile('%s' % "|".join( ignore_check_login_urls ) ) if pattern.match( path ) or "/home" not in path: return # 多查询一次数据也没有什么问题 user_info = check_login() g.current_user = None if user_info: g.current_user = user_info #将忽略数组换成字符串 pattern = re.compile('%s' % "|".join( ignore_urls ) ) if pattern.match( path ): return if not user_info : response = make_response( redirect(GlobalUrlService.buildHomeUrl("/user/logout"))) return response #判断RBAC的权限 if not RBACService.checkPrivilege( path ): if UtilHelper.isAjax(): return UtilHelper.renderErrJSON("无权限,请联系管理员" ) response = make_response(redirect( GlobalUrlService.buildHomeUrl("/error/ban",{ "msg" : path }) )) return response g.menus = MenuService.getMenu() AppLogService.addAccessLog( user_info ) return
def staff_index(): req = request.values kw = req.get("kw", "").strip() page = int(req.get("p", 1)) query = User.query if kw: query = query.filter( or_( User.name.ilike( '%{}%'.format(kw) ) ,User.email.ilike( '%{}%'.format(kw) ) )) page_params = { "total": query.count(), "page_size": CommonConstant.PAGE_SIZE, "page": page, "display": CommonConstant.PAGE_DISPLAY, } pages = UtilHelper.iPagination(page_params) offset = (page - 1) * CommonConstant.PAGE_SIZE limit = CommonConstant.PAGE_SIZE * page list = query.order_by( User.id.desc() )[offset:limit] dept_map = ModelHelper.getDictFilterField( Role ) sc = { 'kw': kw } set_flag = RBACService.checkPageRelatePrivilege("set") ops_flag = RBACService.checkPageRelatePrivilege("ops") return UtilHelper.renderView( "home/rbac/staff/index.html", { "list": list, "pages": pages, "dept_map" : dept_map, "sc": sc, "set_flag": set_flag, "ops_flag": ops_flag, })
def getMenu(): menus = MenuService.definedMenu() prefix = '/home' for _key, _item in menus.items(): #如果强制设置了不显示,那就不要在判断 if hasattr(_item, "hidden") and _item['hidden']: continue tmp_counter = len(_item['sub']) for _sub_key, _sub_item in enumerate(_item['sub']): if hasattr(_sub_item, "hidden") and _sub_item['hidden']: tmp_counter -= 1 continue if not RBACService.checkPrivilege(prefix + _sub_item['url']): menus[_key]['sub'][_sub_key]['hidden'] = True tmp_counter -= 1 if tmp_counter <= 0: menus[_key]['hidden'] = True return menus
def job_index(): req = request.values cate_id = int(req.get("cate_id", CommonConstant.default_status_false)) owner_uid = int(req.get("owner_uid", CurrentUserService.getUid())) env_id = int(req.get("env_id", CommonConstant.default_status_false)) server_id = int(req.get("server_id", CommonConstant.default_status_false)) status = int(req.get("status", CommonConstant.default_status_neg_99)) display_status = int( req.get("display_status", CommonConstant.default_status_neg_99)) job_type = int(req.get("job_type", CommonConstant.default_status_neg_99)) job_level = int(req.get("job_level", CommonConstant.default_status_neg_99)) kw = req.get("kw", "").strip() page = int(req.get("p", 1)) query = JobList.query if RBACService.checkDataPrivilege("all"): pass else: query = query.filter_by(owner_uid=CurrentUserService.getUid()) if cate_id: query = query.filter_by(cate_id=cate_id) if env_id: query = query.filter_by(env_id=env_id) if owner_uid: query = query.filter_by(owner_uid=owner_uid) if server_id: query = query.filter_by(server_id=server_id) if status > CommonConstant.default_status_neg_99: query = query.filter_by(status=status) if display_status > CommonConstant.default_status_neg_99: query = query.filter_by(is_del=display_status) if job_type > CommonConstant.default_status_neg_99: query = query.filter_by(job_type=job_type) if job_level > CommonConstant.default_status_neg_99: query = query.filter_by(job_level=job_level) if kw: if kw.isdigit(): query = query.filter_by(id=int(kw)) else: query = query.filter( or_(JobList.name.ilike('%{}%'.format(kw)), JobList.command.ilike('%{}%'.format(kw)))) page_params = { "total": query.count(), "page_size": CommonConstant.PAGE_SIZE, "page": page, "display": CommonConstant.PAGE_DISPLAY } pages = UtilHelper.iPagination(page_params) offset = (page - 1) * CommonConstant.PAGE_SIZE limit = CommonConstant.PAGE_SIZE * page list = query.order_by(JobList.id.desc())[offset:limit] data = [] server_map = ModelHelper.getDictFilterField(JobServer) cate_map = ModelHelper.getDictFilterField(JobCategory) staff_map = ModelHelper.getDictFilterField(User) server_env_map = CommonConstant.server_env_map run_status_map = CommonConstant.run_status_map job_type_map = CommonConstant.job_type_map job_level_map = CommonConstant.job_level_map if list: for item in list: tmp_data = ModelHelper.model2Dict(item) tmp_server_info = ModelHelper.model2Dict( server_map.get(tmp_data['server_id'])) tmp_cate_info = ModelHelper.model2Dict( cate_map.get(tmp_data['cate_id'])) tmp_owner_staff_info = ModelHelper.model2Dict( staff_map.get(tmp_data['owner_uid'])) tmp_relate_staff_info = ModelHelper.model2Dict( staff_map.get(tmp_data['relate_uid'])) tmp_data['next_run_time'] = DateHelper.getDateOnTimestamps( tmp_data['next_run_time'], '%Y-%m-%d %H:%M') tmp_data['env_name'] = server_env_map.get(tmp_data['env_id']) tmp_data['run_status_desc'] = run_status_map.get( tmp_data['run_status']) tmp_data['job_status_desc'] = job_status_map.get( tmp_data['status']) tmp_data['server_name'] = tmp_server_info.get("name") tmp_data['cate_name'] = tmp_cate_info.get("name", '') tmp_data['owner_name'] = tmp_owner_staff_info.get("name", '') tmp_data['relate_name'] = tmp_relate_staff_info.get("name", '') tmp_data['run_interval_desc'] = DateHelper.formatBeautyTime( tmp_data['run_interval'] * 60) data.append(tmp_data) sc = { 'kw': kw, 'cate_id': cate_id, 'owner_uid': owner_uid, 'env_id': env_id, 'server_id': server_id, 'status': status, 'display_status': display_status, 'job_type': job_type, 'job_level': job_level, } set_flag = RBACService.checkPageRelatePrivilege("set") ops_flag = RBACService.checkPageRelatePrivilege("ops") return UtilHelper.renderView( "home/job/index/index.html", { "list": data, "pages": pages, "job_status_map": job_status_map, "server_env_map": server_env_map, "server_map": server_map, "staff_map": staff_map, "cate_map": cate_map, "display_status_map": display_status_map, "job_type_map": job_type_map, "job_level_map": job_level_map, "sc": sc, "set_flag": set_flag, "ops_flag": ops_flag, })