def list_base_tasks(self, eid): cfg = config_service.get_config_by_key(eid) if not cfg: # init base tasks logger.info("Enterprise id: {}; initialize basic tasks information".format(eid)) data = self.init_base_task() # TODO: handle error config_service.add_config_without_reload(key=eid, default_value=json.dumps(data), type="json") else: data = json.loads(cfg) need_update = False for item in data: if not item["status"]: ctx = BaseTaskStatusContext(eid, item["key"]) status = ctx.confirm_status() if status: logger.info("Enterprise id: {0}; Task: {1}; Original status: False; " "update status.".format(eid, item["key"])) item["status"] = status need_update = True if need_update: # TODO: handle error config_service.update_config(eid, json.dumps(data)) return data
def put(self, request, *args, **kwargs): """ 修改当前云帮Title --- parameters: - name: title description: 云帮标题 required: true type: string paramType: form """ try: title = request.data.get("title", None) if title: config_service.update_config("TITLE", title) code = "0000" msg = "success" msg_show = "title修改成功" result = generate_result(code, msg, msg_show) except Exception as e: result = generate_error_result() logger.exception(e) return Response(result)
def put(self, request, *args, **kwargs): """ 修改开启、关闭注册状态 """ try: user_id = request.user.user_id enterprise_id = request.user.enterprise_id admin = enterprise_user_perm_repo.get_user_enterprise_perm( user_id=user_id, enterprise_id=enterprise_id) is_regist = request.data.get("is_regist") if admin: if is_regist is False: # 修改全局配置 config_service.update_config("REGISTER_STATUS", "no") return Response(general_message(200, "close register", "关闭注册"), status=200) else: config_service.update_config("REGISTER_STATUS", "yes") return Response(general_message(200, "open register", "开启注册"), status=200) else: return Response(general_message(400, "no jurisdiction", "没有权限"), status=400) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])
def update_region_config(self): region_json_data = self.generate_region_config() if not config_service.get_config_by_key("REGION_SERVICE_API"): config_service.add_config("REGION_SERVICE_API", region_json_data, 'json', "数据中心配置") else: config_service.update_config("REGION_SERVICE_API", region_json_data)