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 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 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 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 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, })