class FeatureConfigView(BaseOpenAPIView): @swagger_auto_schema( operation_description="获取指定的功能配置", responses={200: FeatureConfigRespSerializer()}, tags=['openapi-config'], ) def get(self, req, key): queryset = config_service.list_by_keys([key]) queryset["OPEN_DATA_CENTER_STATUS"] = queryset.get("OPEN_DATA_CENTER_STATUS", None) if key.upper() == "OPEN_DATA_CENTER_STATUS" and queryset["OPEN_DATA_CENTER_STATUS"] is None: queryset["OPEN_DATA_CENTER_STATUS"] = False serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data) @swagger_auto_schema( operation_description="删除指定的功能配置", responses={ status.HTTP_200_OK: None, status.HTTP_404_NOT_FOUND: None }, tags=['openapi-config'], ) def delete(self, req, key): try: config_service.delete_by_key(key) except ConsoleSysConfig.DoesNotExist: return Response(None, status.HTTP_404_NOT_FOUND) return Response(None, status.HTTP_200_OK)
def get(self, request): user = request.user queryset = config_service.initialization_or_get_config() oauth_services = [] services = oauth_repo.get_all_oauth_services(str(user.enterprise_id)) for service in services: oauth_services.append( { "service_id": service.ID, "enable": service.enable, "name": service.name, "client_id": service.client_id, "auth_url": service.auth_url, "redirect_uri": service.redirect_uri, "oauth_type": service.oauth_type, "is_console": service.is_console, "home_url": service.home_url, "eid": service.eid, "access_token_url": service.access_token_url, "api_url": service.api_url, "client_secret": service.client_secret, "is_auto_login": service.is_auto_login } ) queryset["oauth_services"]["value"] = oauth_services serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data)
def get(self, req, key): queryset = config_service.list_by_keys([key]) queryset["OPEN_DATA_CENTER_STATUS"] = queryset.get("OPEN_DATA_CENTER_STATUS", None) if key.upper() == "OPEN_DATA_CENTER_STATUS" and queryset["OPEN_DATA_CENTER_STATUS"] is None: queryset["OPEN_DATA_CENTER_STATUS"] = False serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data)
class ListFeatureConfigView(BaseOpenAPIView): @swagger_auto_schema( operation_description="获取全部功能配置", responses={200: FeatureConfigRespSerializer()}, tags=['openapi-config'], ) def get(self, request): queryset = config_service.initialization_or_get_config() serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data) @swagger_auto_schema( operation_description="修改指定的功能配置及状态", request_body=UpdateFeatureCfgReqSerializer(), responses={ status.HTTP_200_OK: None, status.HTTP_404_NOT_FOUND: None }, tags=['openapi-config'], ) def put(self, req): serializer = UpdateFeatureCfgReqSerializer(data=req.data) serializer.is_valid(raise_exception=True) for key in serializer.validated_data.keys(): if key.upper() in config_service.feature_cfg_keys: data = serializer.validated_data[key] if "enable" in data.keys(): enable = data.get("enable") if data.get("value"): value = dict(data.get("value")) else: value = data.get("value") try: config_service.update_by_key(key, enable, value) except ConsoleSysConfig.DoesNotExist: return Response(None, status.HTTP_404_NOT_FOUND) else: return Response(u"缺少参数:enable", status.HTTP_400_BAD_REQUEST) return Response(None, status.HTTP_200_OK) else: return Response(u"要配置的项目找不到", status.HTTP_400_BAD_REQUEST)
class ListFeatureConfigView(BaseOpenAPIView): @swagger_auto_schema( operation_description="获取全部功能配置", responses={200: FeatureConfigRespSerializer()}, tags=['openapi-config'], ) def get(self, request): queryset = config_service.list_by_keys(config_service.feature_cfg_keys) serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data) @swagger_auto_schema( operation_description="新增或更新功能配置", request_body=UpdateFeatureCfgReqSerializer(), responses={200: None}, tags=['openapi-config'], ) def put(self, req): serializer = UpdateFeatureCfgReqSerializer(data=req.data) serializer.is_valid(raise_exception=True) config_service.update_or_create(req.user.enterprise_id, req.data) return Response(None, status=status.HTTP_200_OK)
class ListFeatureConfigView(BaseOpenAPIView): @swagger_auto_schema( operation_description="获取全部功能配置", responses={200: FeatureConfigRespSerializer()}, tags=['openapi-config'], ) def get(self, request): user = request.user queryset = config_service.initialization_or_get_config() oauth_services = [] services = oauth_repo.get_all_oauth_services(str(user.enterprise_id)) for service in services: oauth_services.append( { "service_id": service.ID, "enable": service.enable, "name": service.name, "client_id": service.client_id, "auth_url": service.auth_url, "redirect_uri": service.redirect_uri, "oauth_type": service.oauth_type, "is_console": service.is_console, "home_url": service.home_url, "eid": service.eid, "access_token_url": service.access_token_url, "api_url": service.api_url, "client_secret": service.client_secret, "is_auto_login": service.is_auto_login } ) queryset["oauth_services"]["value"] = oauth_services serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data) @swagger_auto_schema( operation_description="修改指定的功能配置及状态", request_body=UpdateFeatureCfgReqSerializer(), responses={ status.HTTP_200_OK: None, status.HTTP_404_NOT_FOUND: None }, tags=['openapi-config'], ) def put(self, req): serializer = UpdateFeatureCfgReqSerializer(data=req.data) serializer.is_valid(raise_exception=True) for key in serializer.validated_data.keys(): if key.upper() in config_service.feature_cfg_keys: data = serializer.validated_data[key] if "enable" in data.keys(): enable = data.get("enable") if data.get("value"): if isinstance(data.get("value"), dict): value = dict(data.get("value")) elif isinstance(data.get("value"), list): value = list(data.get("value")) else: value = data.get("value") else: value = data.get("value") try: config_service.update_by_key(key, enable, value) except ConsoleSysConfig.DoesNotExist: return Response(None, status.HTTP_404_NOT_FOUND) else: return Response(u"缺少参数:enable", status.HTTP_400_BAD_REQUEST) return Response(None, status.HTTP_200_OK) else: return Response(u"要配置的项目找不到", status.HTTP_400_BAD_REQUEST)
def get(self, request): queryset = config_service.initialization_or_get_config() serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data)
def get(self, req, key): queryset = config_service.list_by_keys([key]) serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data)
def get(self, request): queryset = config_service.list_by_keys(config_service.feature_cfg_keys) serializer = FeatureConfigRespSerializer(queryset) return Response(serializer.data)