diff --git a/apps/acls/models/login_acl.py b/apps/acls/models/login_acl.py index 6e1fbff73..f9b24e426 100644 --- a/apps/acls/models/login_acl.py +++ b/apps/acls/models/login_acl.py @@ -123,6 +123,8 @@ class LoginACL(BaseACL): 'org_id': Organization.ROOT_ID, } ticket = Ticket.objects.create(**data) - ticket.create_process_map_and_node(self.reviewers.all()) - ticket.open(self.user) + applicant = self.user + assignees = self.reviewers.all() + ticket.create_process_map_and_node(assignees, applicant) + ticket.open(applicant) return ticket diff --git a/apps/acls/models/login_asset_acl.py b/apps/acls/models/login_asset_acl.py index 0bde3c14f..dda9d97c1 100644 --- a/apps/acls/models/login_asset_acl.py +++ b/apps/acls/models/login_asset_acl.py @@ -97,7 +97,7 @@ class LoginAssetACL(BaseACL, OrgModelMixin): 'org_id': org_id, } ticket = Ticket.objects.create(**data) - ticket.create_process_map_and_node(assignees) + ticket.create_process_map_and_node(assignees, user) ticket.open(applicant=user) return ticket diff --git a/apps/assets/models/cmd_filter.py b/apps/assets/models/cmd_filter.py index 82fd50e89..c92a25109 100644 --- a/apps/assets/models/cmd_filter.py +++ b/apps/assets/models/cmd_filter.py @@ -181,8 +181,10 @@ class CommandFilterRule(OrgModelMixin): 'org_id': org_id, } ticket = Ticket.objects.create(**data) - ticket.create_process_map_and_node(self.reviewers.all()) - ticket.open(applicant=session.user_obj) + applicant = session.user_obj + assignees = self.reviewers.all() + ticket.create_process_map_and_node(assignees, applicant) + ticket.open(applicant) return ticket @classmethod diff --git a/apps/tickets/api/ticket.py b/apps/tickets/api/ticket.py index 8e7923e8e..586188898 100644 --- a/apps/tickets/api/ticket.py +++ b/apps/tickets/api/ticket.py @@ -53,9 +53,10 @@ class TicketViewSet(CommonApiMixin, viewsets.ModelViewSet): def perform_create(self, serializer): instance = serializer.save() - instance.create_related_node() - instance.process_map = instance.create_process_map() - instance.open(applicant=self.request.user) + applicant = self.request.user + instance.create_related_node(applicant) + instance.process_map = instance.create_process_map(applicant) + instance.open(applicant) @action(detail=False, methods=[POST], permission_classes=[RBACPermission, ]) def open(self, request, *args, **kwargs): diff --git a/apps/tickets/models/ticket.py b/apps/tickets/models/ticket.py index aa536584d..c05fa8b3b 100644 --- a/apps/tickets/models/ticket.py +++ b/apps/tickets/models/ticket.py @@ -188,22 +188,30 @@ class Ticket(CommonModelMixin, StatusMixin, OrgModelMixin): .exclude(state=ProcessStatus.notified).first() 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 approval_rule = self.get_current_ticket_flow_approve() ticket_step = TicketStep.objects.create(ticket=self, level=self.approval_step) ticket_assignees = [] assignees = approval_rule.get_assignees(org_id=org_id) + assignees = self.ignore_applicant(assignees, applicant) for assignee in assignees: ticket_assignees.append(TicketAssignee(step=ticket_step, assignee=assignee)) TicketAssignee.objects.bulk_create(ticket_assignees) - def create_process_map(self): + def create_process_map(self, applicant=None): org_id = self.flow.org_id approval_rules = self.flow.rules.order_by('level') nodes = list() for node in approval_rules: assignees = node.get_assignees(org_id=org_id) + assignees = self.ignore_applicant(assignees, applicant) assignee_ids = [assignee.id for assignee in assignees] assignees_display = [str(assignee) for assignee in assignees] nodes.append( @@ -217,7 +225,8 @@ class Ticket(CommonModelMixin, StatusMixin, OrgModelMixin): return nodes # 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 = [{ 'approval_level': 1, 'state': 'notified',