mirror of https://github.com/jumpserver/jumpserver
feat: 工单审批人中去除申请人
parent
7eec50804c
commit
14710e9c9e
|
@ -123,6 +123,8 @@ class LoginACL(BaseACL):
|
||||||
'org_id': Organization.ROOT_ID,
|
'org_id': Organization.ROOT_ID,
|
||||||
}
|
}
|
||||||
ticket = Ticket.objects.create(**data)
|
ticket = Ticket.objects.create(**data)
|
||||||
ticket.create_process_map_and_node(self.reviewers.all())
|
applicant = self.user
|
||||||
ticket.open(self.user)
|
assignees = self.reviewers.all()
|
||||||
|
ticket.create_process_map_and_node(assignees, applicant)
|
||||||
|
ticket.open(applicant)
|
||||||
return ticket
|
return ticket
|
||||||
|
|
|
@ -97,7 +97,7 @@ class LoginAssetACL(BaseACL, OrgModelMixin):
|
||||||
'org_id': org_id,
|
'org_id': org_id,
|
||||||
}
|
}
|
||||||
ticket = Ticket.objects.create(**data)
|
ticket = Ticket.objects.create(**data)
|
||||||
ticket.create_process_map_and_node(assignees)
|
ticket.create_process_map_and_node(assignees, user)
|
||||||
ticket.open(applicant=user)
|
ticket.open(applicant=user)
|
||||||
return ticket
|
return ticket
|
||||||
|
|
||||||
|
|
|
@ -181,8 +181,10 @@ class CommandFilterRule(OrgModelMixin):
|
||||||
'org_id': org_id,
|
'org_id': org_id,
|
||||||
}
|
}
|
||||||
ticket = Ticket.objects.create(**data)
|
ticket = Ticket.objects.create(**data)
|
||||||
ticket.create_process_map_and_node(self.reviewers.all())
|
applicant = session.user_obj
|
||||||
ticket.open(applicant=session.user_obj)
|
assignees = self.reviewers.all()
|
||||||
|
ticket.create_process_map_and_node(assignees, applicant)
|
||||||
|
ticket.open(applicant)
|
||||||
return ticket
|
return ticket
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -53,9 +53,10 @@ class TicketViewSet(CommonApiMixin, viewsets.ModelViewSet):
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
instance = serializer.save()
|
instance = serializer.save()
|
||||||
instance.create_related_node()
|
applicant = self.request.user
|
||||||
instance.process_map = instance.create_process_map()
|
instance.create_related_node(applicant)
|
||||||
instance.open(applicant=self.request.user)
|
instance.process_map = instance.create_process_map(applicant)
|
||||||
|
instance.open(applicant)
|
||||||
|
|
||||||
@action(detail=False, methods=[POST], permission_classes=[RBACPermission, ])
|
@action(detail=False, methods=[POST], permission_classes=[RBACPermission, ])
|
||||||
def open(self, request, *args, **kwargs):
|
def open(self, request, *args, **kwargs):
|
||||||
|
|
|
@ -188,22 +188,30 @@ class Ticket(CommonModelMixin, StatusMixin, OrgModelMixin):
|
||||||
.exclude(state=ProcessStatus.notified).first()
|
.exclude(state=ProcessStatus.notified).first()
|
||||||
return processor.assignee if processor else None
|
return processor.assignee if processor else None
|
||||||
|
|
||||||
def create_related_node(self):
|
def ignore_applicant(self, assignees, applicant=None):
|
||||||
|
applicant = applicant if applicant else self.applicant
|
||||||
|
if len(assignees) != 1:
|
||||||
|
assignees = set(assignees) - {applicant, }
|
||||||
|
return list(assignees)
|
||||||
|
|
||||||
|
def create_related_node(self, applicant=None):
|
||||||
org_id = self.flow.org_id
|
org_id = self.flow.org_id
|
||||||
approval_rule = self.get_current_ticket_flow_approve()
|
approval_rule = self.get_current_ticket_flow_approve()
|
||||||
ticket_step = TicketStep.objects.create(ticket=self, level=self.approval_step)
|
ticket_step = TicketStep.objects.create(ticket=self, level=self.approval_step)
|
||||||
ticket_assignees = []
|
ticket_assignees = []
|
||||||
assignees = approval_rule.get_assignees(org_id=org_id)
|
assignees = approval_rule.get_assignees(org_id=org_id)
|
||||||
|
assignees = self.ignore_applicant(assignees, applicant)
|
||||||
for assignee in assignees:
|
for assignee in assignees:
|
||||||
ticket_assignees.append(TicketAssignee(step=ticket_step, assignee=assignee))
|
ticket_assignees.append(TicketAssignee(step=ticket_step, assignee=assignee))
|
||||||
TicketAssignee.objects.bulk_create(ticket_assignees)
|
TicketAssignee.objects.bulk_create(ticket_assignees)
|
||||||
|
|
||||||
def create_process_map(self):
|
def create_process_map(self, applicant=None):
|
||||||
org_id = self.flow.org_id
|
org_id = self.flow.org_id
|
||||||
approval_rules = self.flow.rules.order_by('level')
|
approval_rules = self.flow.rules.order_by('level')
|
||||||
nodes = list()
|
nodes = list()
|
||||||
for node in approval_rules:
|
for node in approval_rules:
|
||||||
assignees = node.get_assignees(org_id=org_id)
|
assignees = node.get_assignees(org_id=org_id)
|
||||||
|
assignees = self.ignore_applicant(assignees, applicant)
|
||||||
assignee_ids = [assignee.id for assignee in assignees]
|
assignee_ids = [assignee.id for assignee in assignees]
|
||||||
assignees_display = [str(assignee) for assignee in assignees]
|
assignees_display = [str(assignee) for assignee in assignees]
|
||||||
nodes.append(
|
nodes.append(
|
||||||
|
@ -217,7 +225,8 @@ class Ticket(CommonModelMixin, StatusMixin, OrgModelMixin):
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
# TODO 兼容不存在流的工单
|
# TODO 兼容不存在流的工单
|
||||||
def create_process_map_and_node(self, assignees):
|
def create_process_map_and_node(self, assignees, applicant):
|
||||||
|
assignees = self.ignore_applicant(assignees, applicant)
|
||||||
self.process_map = [{
|
self.process_map = [{
|
||||||
'approval_level': 1,
|
'approval_level': 1,
|
||||||
'state': 'notified',
|
'state': 'notified',
|
||||||
|
|
Loading…
Reference in New Issue