Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 添加公共流程预览 --story=121224121 #7653

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion gcloud/contrib/template_market/permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gcloud/contrib/template_market/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down
28 changes: 17 additions & 11 deletions gcloud/contrib/template_market/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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})


Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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})
Loading