Skip to content

Commit

Permalink
fix: 添加公共流程周期任务 --story=121334648
Browse files Browse the repository at this point in the history
  • Loading branch information
guohelu committed Dec 23, 2024
1 parent 6d5c635 commit fc46ecf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gcloud/contrib/template_market/permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions gcloud/contrib/template_market/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
26 changes: 16 additions & 10 deletions gcloud/contrib/template_market/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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")
Expand All @@ -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,
)
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion gcloud/core/apis/drf/viewsets/common_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit fc46ecf

Please sign in to comment.