From 1333c01e584d767a5304cd268f3acf7afadf05f0 Mon Sep 17 00:00:00 2001 From: guohelu <19503896967@163.com> Date: Mon, 23 Dec 2024 19:41:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20sre=E8=A7=86=E5=9B=BE=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20--story=3D121334648?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gcloud/contrib/template_market/permission.py | 2 +- gcloud/contrib/template_market/serializers.py | 3 +-- gcloud/contrib/template_market/viewsets.py | 26 ++++++++++++------- .../core/apis/drf/viewsets/common_template.py | 7 ++++- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/gcloud/contrib/template_market/permission.py b/gcloud/contrib/template_market/permission.py index d2f684701..d2821814f 100644 --- a/gcloud/contrib/template_market/permission.py +++ b/gcloud/contrib/template_market/permission.py @@ -47,7 +47,7 @@ def has_permission(self, request, view): serializer = view.serializer_class(data=request.data) serializer.is_valid(raise_exception=True) - template_id_list = serializer.validated_data["template_ids"] + template_id_list = serializer.validated_data["templates"] try: iam_multi_resource_auth_or_raise( username, IAMMeta.FLOW_EDIT_ACTION, template_id_list, "resources_list_for_flows" diff --git a/gcloud/contrib/template_market/serializers.py b/gcloud/contrib/template_market/serializers.py index c809b0da9..40c18d6dc 100644 --- a/gcloud/contrib/template_market/serializers.py +++ b/gcloud/contrib/template_market/serializers.py @@ -47,9 +47,8 @@ class FileUploadAddrSerializer(serializers.Serializer): class TemplateSharedRecordSerializer(serializers.Serializer): project_code = serializers.CharField(required=True, max_length=32, help_text="项目id") - template_ids = serializers.ListField(required=True, help_text="关联的模板列表") + templates = serializers.ListField(required=True, help_text="关联的模板列表") name = serializers.CharField(required=True, help_text="共享名称") - code = serializers.CharField(required=True, help_text="共享标识") category = serializers.CharField(required=True, help_text="共享分类") risk_level = serializers.IntegerField(required=True, help_text="风险级别") usage_id = serializers.IntegerField(required=False, help_text="使用说明id") diff --git a/gcloud/contrib/template_market/viewsets.py b/gcloud/contrib/template_market/viewsets.py index 38436c668..bab179ced 100644 --- a/gcloud/contrib/template_market/viewsets.py +++ b/gcloud/contrib/template_market/viewsets.py @@ -62,9 +62,14 @@ class TemplateSceneViewSet(viewsets.ViewSet): market_client = MarketAPIClient def _build_template_data(self, serializer, **kwargs): - templates = TaskTemplate.objects.filter(id__in=serializer.validated_data["template_ids"], is_deleted=False) + templates = TaskTemplate.objects.filter( + id__in=serializer.validated_data["templates"], + project_id=serializer.validated_data["project_code"], + is_deleted=False, + ) template_info = [{"id": template.id, "name": template.name} for template in templates] - data = {"source_system": settings.APP_CODE, "templates": template_info, **serializer.validated_data} + serializer.validated_data["templates"] = template_info + data = {"source_system": settings.APP_CODE, **serializer.validated_data} market_record_id = kwargs.get("market_record_id") if market_record_id: data["id"] = market_record_id @@ -119,7 +124,7 @@ def get_scene_label(self, request, *args, **kwargs): @action(detail=False, methods=["post"]) @swagger_auto_schema(request_body=SceneLabelSerializer) - def create_scene_label(self, request, *args, **kwargs): + def add_scene_label(self, request, *args, **kwargs): serializer = SceneLabelSerializer(data=request.data) serializer.is_valid(raise_exception=True) @@ -146,7 +151,8 @@ def get_risk_level(self, request, *args, **kwargs): return error_response return Response({"result": True, "data": response_data["data"], "code": err_code.SUCCESS.code}) - def list(self, request, *args, **kwargs): + @action(detail=False, methods=["get"]) + def get_scene_template_list(self, request, *args, **kwargs): client = self.market_client(username=request.user.username) response_data = client.get_template_scene_list() error_response = self._handle_response(response_data, "Failed to obtain the list") @@ -162,13 +168,13 @@ def create(self, request, *args, **kwargs): data = self._build_template_data(serializer) client = self.market_client(username=request.user.username) response_data = client.create_template_scene(data) - create_response = self._handle_response(response_data, "Failed to create market template record") + create_response = self._handle_response(response_data, "Failed to create record") if create_response: return create_response - TemplateSharedRecord.objects.update_shared_record( + self.queryset.model.objects.update_shared_record( project_id=int(serializer.validated_data["project_code"]), - new_template_ids=serializer.validated_data["template_ids"], + new_template_ids=request.data["templates"], market_record_id=response_data["data"]["id"], creator=request.user.username, ) @@ -189,13 +195,13 @@ def partial_update(self, request, *args, **kwargs): data = self._build_template_data(serializer, market_record_id=market_record_id) response_data = client.patch_template_scene(data, market_record_id) - update_response = self._handle_response(response_data, "Failed to update market template record") + update_response = self._handle_response(response_data, "Failed to update record") if update_response: return update_response - TemplateSharedRecord.objects.update_shared_record( + self.queryset.model.objects.update_shared_record( project_id=int(serializer.validated_data["project_code"]), - new_template_ids=serializer.validated_data["template_ids"], + new_template_ids=request.data["templates"], market_record_id=market_record_id, creator=request.user.username, existing_market_template_ids=existing_market_template_ids, diff --git a/gcloud/core/apis/drf/viewsets/common_template.py b/gcloud/core/apis/drf/viewsets/common_template.py index eb5ef89bd..9b5ac8033 100644 --- a/gcloud/core/apis/drf/viewsets/common_template.py +++ b/gcloud/core/apis/drf/viewsets/common_template.py @@ -91,7 +91,12 @@ class CommonTemplateViewSet(GcloudModelViewSet): pagination_class = LimitOffsetPagination iam_resource_helper = ViewSetResourceHelper( resource_func=res_factory.resources_for_common_flow_obj, - actions=[IAMMeta.COMMON_FLOW_VIEW_ACTION, IAMMeta.COMMON_FLOW_EDIT_ACTION, IAMMeta.COMMON_FLOW_DELETE_ACTION], + actions=[ + IAMMeta.COMMON_FLOW_VIEW_ACTION, + IAMMeta.COMMON_FLOW_EDIT_ACTION, + IAMMeta.COMMON_FLOW_DELETE_ACTION, + IAMMeta.COMMON_FLOW_CREATE_PERIODIC_TASK_ACTION, + ], ) filterset_class = CommonTemplateFilter permission_classes = [permissions.IsAuthenticated, CommonTemplatePermission] From bcae7413bd47d073b434d543a49e13c47fd67fcc Mon Sep 17 00:00:00 2001 From: guohelu <19503896967@163.com> Date: Mon, 23 Dec 2024 20:33:50 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E4=BF=A1=E6=81=AF=20--story=3D121334648?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gcloud/contrib/template_market/viewsets.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/gcloud/contrib/template_market/viewsets.py b/gcloud/contrib/template_market/viewsets.py index bab179ced..e493a2387 100644 --- a/gcloud/contrib/template_market/viewsets.py +++ b/gcloud/contrib/template_market/viewsets.py @@ -77,15 +77,17 @@ def _build_template_data(self, serializer, **kwargs): def _handle_response(self, response_data, error_message): if not response_data.get("result"): - message = "market template {}, error message: {}".format(error_message, response_data["message"]) - logger.error(message) - return Response( - { - "result": False, - "message": message, - "code": err_code.OPERATION_FAIL.code, - } - ) + response_structure = { + "result": False, + "message": "market template {}, error message: {}".format(error_message, response_data.get("message")), + "code": err_code.OPERATION_FAIL.code, + } + logger.error(response_structure["message"]) + + if response_data.get("code") == 9007: + response_structure["data"] = response_data.get("data") + + return Response(response_structure) return None @action(detail=False, methods=["get"]) From 8b64ecc53631ef8e4d1233640a8e14f900f3b30d Mon Sep 17 00:00:00 2001 From: guohelu <19503896967@163.com> Date: Mon, 23 Dec 2024 20:44:34 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=9D=83=E9=99=90=20--story=3D121334648?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gcloud/contrib/template_market/viewsets.py | 4 ++-- gcloud/core/apis/drf/viewsets/common_template.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/gcloud/contrib/template_market/viewsets.py b/gcloud/contrib/template_market/viewsets.py index e493a2387..b7e24f27b 100644 --- a/gcloud/contrib/template_market/viewsets.py +++ b/gcloud/contrib/template_market/viewsets.py @@ -174,7 +174,7 @@ def create(self, request, *args, **kwargs): if create_response: return create_response - self.queryset.model.objects.update_shared_record( + TemplateSharedRecord.objects.update_shared_record( project_id=int(serializer.validated_data["project_code"]), new_template_ids=request.data["templates"], market_record_id=response_data["data"]["id"], @@ -201,7 +201,7 @@ def partial_update(self, request, *args, **kwargs): if update_response: return update_response - self.queryset.model.objects.update_shared_record( + TemplateSharedRecord.objects.update_shared_record( project_id=int(serializer.validated_data["project_code"]), new_template_ids=request.data["templates"], market_record_id=market_record_id, diff --git a/gcloud/core/apis/drf/viewsets/common_template.py b/gcloud/core/apis/drf/viewsets/common_template.py index 9b5ac8033..ebdda0daf 100644 --- a/gcloud/core/apis/drf/viewsets/common_template.py +++ b/gcloud/core/apis/drf/viewsets/common_template.py @@ -95,7 +95,6 @@ class CommonTemplateViewSet(GcloudModelViewSet): IAMMeta.COMMON_FLOW_VIEW_ACTION, IAMMeta.COMMON_FLOW_EDIT_ACTION, IAMMeta.COMMON_FLOW_DELETE_ACTION, - IAMMeta.COMMON_FLOW_CREATE_PERIODIC_TASK_ACTION, ], ) filterset_class = CommonTemplateFilter