Skip to content

Commit

Permalink
feat: 修复公共流程执行周期任务权限 --story=121224121
Browse files Browse the repository at this point in the history
  • Loading branch information
guohelu committed Jan 3, 2025
1 parent 9cfd9b6 commit 159199e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion gcloud/core/apis/drf/viewsets/common_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class CommonTemplatePermission(IamPermission):
"list": IamPermissionInfo(pass_all=True),
"list_for_periodic_task": IamPermissionInfo(pass_all=True),
"list_with_top_collection": IamPermissionInfo(pass_all=True),
"retrieve_for_periodic_task": IamPermissionInfo(pass_all=True),
"retrieve": IamPermissionInfo(
IAMMeta.COMMON_FLOW_VIEW_ACTION, res_factory.resources_for_common_flow_obj, HAS_OBJECT_PERMISSION
),
Expand Down Expand Up @@ -103,10 +104,24 @@ class CommonTemplateViewSet(GcloudModelViewSet):
ordering = ["-id"]

def get_serializer_class(self):
if self.action in ["list", "list_with_top_collection", "list_for_periodic_task"]:
if self.action in ["list", "list_with_top_collection", "list_for_periodic_task", "retrieve_for_periodic_task"]:
return CommonTemplateListSerializer
return CommonTemplateSerializer

@action(methods=["GET"], detail=False)
def retrieve_for_periodic_task(self, request, *args, **kwargs):
template_id = int(request.query_params.get("template_id"))
queryset = self.get_queryset().get(id=template_id)
serializer = self.get_serializer(queryset)
# 注入权限
data = self.injection_auth_actions(request, serializer.data, serializer.instance)
# 注入公共流程新建周期任务权限
create_periodic_task_action = Action(IAMMeta.COMMON_FLOW_CREATE_PERIODIC_TASK_ACTION)
templates = self._inject_project_based_task_create_action(request, [data["id"]], create_periodic_task_action)
if data["id"] in templates:
data["auth_actions"].append(IAMMeta.COMMON_FLOW_CREATE_PERIODIC_TASK_ACTION)
return Response(data)

@swagger_auto_schema(method="GET", operation_summary="带有创建周期任务权限指定的流程列表")
@action(methods=["GET"], detail=False)
def list_for_periodic_task(self, request, *args, **kwargs):
Expand Down

0 comments on commit 159199e

Please sign in to comment.