From 762e3773bb093f59e7c33a27e78b37dd4fa92968 Mon Sep 17 00:00:00 2001 From: guohelu <19503896967@163.com> Date: Wed, 25 Dec 2024 16:15:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E9=A2=84=E8=A7=88=20--story=3D121224121?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gcloud/contrib/template_market/permission.py | 10 ++++++- gcloud/contrib/template_market/serializers.py | 2 ++ gcloud/contrib/template_market/viewsets.py | 28 +++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/gcloud/contrib/template_market/permission.py b/gcloud/contrib/template_market/permission.py index d2821814f..57ed6b895 100644 --- a/gcloud/contrib/template_market/permission.py +++ b/gcloud/contrib/template_market/permission.py @@ -16,7 +16,9 @@ from rest_framework import permissions from gcloud.conf import settings +from gcloud.constants import PROJECT from gcloud.contrib.template_market.models import TemplateSharedRecord +from gcloud.common_template.models import CommonTemplate from gcloud.contrib.template_market.serializers import TemplateProjectBaseSerializer from gcloud.iam_auth import IAMMeta from gcloud.iam_auth.utils import iam_multi_resource_auth_or_raise @@ -29,7 +31,13 @@ def has_permission(self, request, view): template_id = int(serializer.validated_data["template_id"]) project_id = int(serializer.validated_data["project_id"]) - record = TemplateSharedRecord.objects.filter(project_id=project_id, template_id=template_id).first() + template_source = serializer.validated_data["template_source"] + + if template_source == PROJECT: + record = TemplateSharedRecord.objects.filter(project_id=project_id, template_id=template_id).first() + else: + record = CommonTemplate.objects.filter(id=template_id, is_deleted=False).first() + if record is None: logging.warning("The specified template could not be found") return False diff --git a/gcloud/contrib/template_market/serializers.py b/gcloud/contrib/template_market/serializers.py index 40c18d6dc..ae0710f65 100644 --- a/gcloud/contrib/template_market/serializers.py +++ b/gcloud/contrib/template_market/serializers.py @@ -14,6 +14,7 @@ from rest_framework import serializers +from gcloud.constants import PROJECT from gcloud.taskflow3.models import TaskTemplate from pipeline_web.constants import PWE @@ -32,6 +33,7 @@ def get_pipeline_tree(self, obj): class TemplateProjectBaseSerializer(serializers.Serializer): template_id = serializers.CharField(required=True, help_text="模板id") project_id = serializers.CharField(required=True, help_text="项目id") + template_source = serializers.CharField(help_text="流程模版类型", default=PROJECT) class SceneLabelSerializer(serializers.Serializer): diff --git a/gcloud/contrib/template_market/viewsets.py b/gcloud/contrib/template_market/viewsets.py index 7a4c0d1be..bf0539972 100644 --- a/gcloud/contrib/template_market/viewsets.py +++ b/gcloud/contrib/template_market/viewsets.py @@ -19,6 +19,7 @@ from rest_framework import permissions from gcloud import err_code +from gcloud.constants import PROJECT from gcloud.conf import settings from drf_yasg.utils import swagger_auto_schema from gcloud.contrib.template_market.serializers import ( @@ -28,6 +29,7 @@ SceneLabelSerializer, FileUploadAddrSerializer, ) +from gcloud.common_template.models import CommonTemplate from gcloud.contrib.template_market.models import TemplateSharedRecord from gcloud.taskflow3.models import TaskTemplate from gcloud.contrib.template_market.clients import MarketAPIClient @@ -47,10 +49,14 @@ def get(self, request, *args, **kwargs): template_id = request_serializer.validated_data["template_id"] project_id = request_serializer.validated_data["project_id"] + template_source = request_serializer.validated_data["template_source"] - instance = self.queryset.get(id=template_id, project_id=project_id) - serializer = self.serializer_class(instance) + if template_source == PROJECT: + instance = self.queryset.get(id=template_id, project_id=project_id) + else: + instance = CommonTemplate.objects.filter(pk=template_id, is_deleted=False).first() + serializer = self.serializer_class(instance) return Response({"result": True, "data": serializer.data, "code": err_code.SUCCESS.code}) @@ -98,7 +104,7 @@ def get_service_category(self, request, *args, **kwargs): error_response = self._handle_response(response_data, "Failed to obtain scene category") if error_response: return error_response - return Response({"result": True, "data": response_data["data"], "code": err_code.SUCCESS.code}) + return Response({"result": True, "message": "OK", "data": response_data["data"], "code": err_code.SUCCESS.code}) @action(detail=False, methods=["get"]) def get_file_upload_addr(self, request, *args, **kwargs): @@ -114,7 +120,7 @@ def get_file_upload_addr(self, request, *args, **kwargs): error_response = self._handle_response(response_data, "Failed to obtain file upload address") if error_response: return error_response - return Response({"result": True, "data": response_data["data"], "code": err_code.SUCCESS.code}) + return Response({"result": True, "message": "OK", "data": response_data["data"], "code": err_code.SUCCESS.code}) @action(detail=False, methods=["get"]) def get_scene_label(self, request, *args, **kwargs): @@ -123,7 +129,7 @@ def get_scene_label(self, request, *args, **kwargs): error_response = self._handle_response(response_data, "Failed to obtain scene tag list") if error_response: return error_response - return Response({"result": True, "data": response_data["data"], "code": err_code.SUCCESS.code}) + return Response({"result": True, "message": "OK", "data": response_data["data"], "code": err_code.SUCCESS.code}) @action(detail=False, methods=["post"]) @swagger_auto_schema(request_body=SceneLabelSerializer) @@ -143,7 +149,7 @@ def add_scene_label(self, request, *args, **kwargs): if create_response: return create_response - return Response({"result": True, "data": response_data["data"], "code": err_code.SUCCESS.code}) + return Response({"result": True, "message": "OK", "data": response_data["data"], "code": err_code.SUCCESS.code}) @action(detail=False, methods=["get"]) def get_risk_level(self, request, *args, **kwargs): @@ -152,7 +158,7 @@ def get_risk_level(self, request, *args, **kwargs): error_response = self._handle_response(response_data, "Failed to obtain the risk level list") if error_response: return error_response - return Response({"result": True, "data": response_data["data"], "code": err_code.SUCCESS.code}) + return Response({"result": True, "message": "OK", "data": response_data["data"], "code": err_code.SUCCESS.code}) @action(detail=False, methods=["get"]) def get_scene_template_list(self, request, *args, **kwargs): @@ -161,7 +167,7 @@ def get_scene_template_list(self, request, *args, **kwargs): error_response = self._handle_response(response_data, "Failed to obtain the list") if error_response: return error_response - return Response({"result": True, "data": response_data, "code": err_code.SUCCESS.code}) + return Response({"result": True, "message": "OK", "data": response_data["data"], "code": err_code.SUCCESS.code}) @swagger_auto_schema(request_body=TemplateSharedRecordSerializer) def create(self, request, *args, **kwargs): @@ -181,11 +187,11 @@ def create(self, request, *args, **kwargs): market_record_id=response_data["data"]["id"], creator=request.user.username, ) - return Response({"result": True, "data": response_data, "code": err_code.SUCCESS.code}) + return Response({"result": True, "message": "OK", "data": response_data["data"], "code": err_code.SUCCESS.code}) @swagger_auto_schema(request_body=TemplateSharedRecordSerializer) def partial_update(self, request, *args, **kwargs): - market_record_id = kwargs["pk"] + market_record_id = int(kwargs["pk"]) serializer = self.serializer_class(data=request.data, partial=True) serializer.is_valid(raise_exception=True) @@ -209,4 +215,4 @@ def partial_update(self, request, *args, **kwargs): creator=request.user.username, existing_market_template_ids=existing_market_template_ids, ) - return Response({"result": True, "data": response_data, "code": err_code.SUCCESS.code}) + return Response({"result": True, "message": "OK", "data": response_data["data"], "code": err_code.SUCCESS.code})