From 23098bb6a060a5d60ec4c04029f92cb952b3d3ef Mon Sep 17 00:00:00 2001 From: hanshuaikang <1758504262@qq.com> Date: Thu, 21 Dec 2023 15:53:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E6=B8=A0?= =?UTF-8?q?=E9=81=93=E5=90=8C=E6=97=B6=E5=AE=A1=E6=89=B9=E6=97=B6=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E4=BC=9A=E5=AF=BC=E8=87=B4=E9=87=8D=E5=A4=8D=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E5=AE=A1=E6=89=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- itsm/component/bkchat/utils.py | 15 +++++++++++++++ itsm/openapi/ticket/views.py | 9 +++++++++ .../components/collections/itsm_approval_node.py | 3 ++- .../components/collections/itsm_sign.py | 6 ++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/itsm/component/bkchat/utils.py b/itsm/component/bkchat/utils.py index b7251ed3a..f04e7ecf4 100644 --- a/itsm/component/bkchat/utils.py +++ b/itsm/component/bkchat/utils.py @@ -198,6 +198,21 @@ def proceed_fast_approval(request): approve_action = result.get("status") ticket = Ticket.objects.get(id=ticket_id) + + node_status = ticket.node_status.get(state_id=state_id) + if not node_status.can_sign_state_operate(receiver): + return JsonResponse( + { + "result": False, + "data": { + "approve_result": ticket.get_state_approve_result(state_id), + "approver": ticket.get_approver(state_id), + }, + "code": -1, + "message": "单据审批失败,{}不是当前节点的审批人,无法审批".format(receiver), + } + ) + # 3.判断当前节点是否是RUNNING状态,否则通知 current_status = Status.objects.get(state_id=state_id, ticket_id=ticket_id) if current_status.status != "RUNNING": diff --git a/itsm/openapi/ticket/views.py b/itsm/openapi/ticket/views.py index 3093f7b67..f5faf7e92 100644 --- a/itsm/openapi/ticket/views.py +++ b/itsm/openapi/ticket/views.py @@ -571,6 +571,14 @@ def proceed_approval(self, request): ticket = Ticket.objects.get(sn=ticket_id) except Exception: raise ValidationError("process_inst_id = {} 对应的单据不存在!".format(ticket_id)) + + node_status = ticket.node_status.get(state_id=state_id) + + if not node_status.can_sign_state_operate(serializer.validated_data["handler"]): + raise OperateTicketError( + "单据审批失败,{}不是当前节点的审批人,无法审批".format(serializer.validated_data["handler"]) + ) + try: node_fields = TicketField.objects.filter( state_id=state_id, ticket_id=ticket.id @@ -581,6 +589,7 @@ def proceed_approval(self, request): state_id, ticket_id ) ) + fields = [] remarked = False for field in node_fields: diff --git a/itsm/pipeline_plugins/components/collections/itsm_approval_node.py b/itsm/pipeline_plugins/components/collections/itsm_approval_node.py index 1b42c6ca4..70543d35f 100644 --- a/itsm/pipeline_plugins/components/collections/itsm_approval_node.py +++ b/itsm/pipeline_plugins/components/collections/itsm_approval_node.py @@ -92,7 +92,8 @@ def execute(self, data, parent_data): ) activity_id = ticket.activity_for_state(state_id) auto_approve.apply_async( - (node_status.id, "system", activity_id, callback_data), countdown=20 + (node_status.id, "system", activity_id, callback_data), + countdown=settings.AUTO_APPROVE_TIME, ) # 20秒之后自动回调 return True diff --git a/itsm/pipeline_plugins/components/collections/itsm_sign.py b/itsm/pipeline_plugins/components/collections/itsm_sign.py index 63c66c422..4b90a942c 100644 --- a/itsm/pipeline_plugins/components/collections/itsm_sign.py +++ b/itsm/pipeline_plugins/components/collections/itsm_sign.py @@ -94,6 +94,11 @@ def schedule(self, data, parent_data, callback_data=None): code_key = data.outputs.get("code_key") ticket = Ticket.objects.get(id=ticket_id) node_status = Status.objects.get(ticket_id=ticket_id, state_id=state_id) + + # 并发情况下如果用户到这里已经被其他渠道回调过 + if not node_status.can_sign_state_operate(operator): + return True + try: ticket.do_in_sign_state(node_status, fields, operator, source) ticket.update_ticket_fields(fields=fields) @@ -119,6 +124,7 @@ def schedule(self, data, parent_data, callback_data=None): self.finish_schedule() finally: self.final_execute(node_status, operator) + ticket.close_moa_ticket(state_id, operator) ticket.set_current_processors() except Exception as err: logger.error("ItsmSignService schedule err, reason is {}".format(err))