Skip to content

Commit

Permalink
Merge pull request #1250 from hanshuaikang/feature/develop_by_han
Browse files Browse the repository at this point in the history
Feature/develop by han
  • Loading branch information
hanshuaikang authored Dec 21, 2023
2 parents 0370139 + 23098bb commit bf20d1f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
15 changes: 15 additions & 0 deletions itsm/component/bkchat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
9 changes: 9 additions & 0 deletions itsm/openapi/ticket/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -581,6 +589,7 @@ def proceed_approval(self, request):
state_id, ticket_id
)
)

fields = []
remarked = False
for field in node_fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions itsm/pipeline_plugins/components/collections/itsm_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down

0 comments on commit bf20d1f

Please sign in to comment.