perf: 工单评论优化

pull/6934/head v2.14.1
feng626 2021-09-22 15:46:23 +08:00 committed by 老广
parent 93b5876469
commit 95412d739a
3 changed files with 6 additions and 4 deletions

View File

@ -206,10 +206,12 @@ class Ticket(CommonModelMixin, OrgModelMixin):
self.save()
post_change_ticket_action.send(sender=self.__class__, ticket=self, action=action)
# ticket
def has_assignee(self, assignee):
def has_current_assignee(self, assignee):
return self.ticket_steps.filter(ticket_assignees__assignee=assignee, level=self.approval_step).exists()
def has_all_assignee(self, assignee):
return self.ticket_steps.filter(ticket_assignees__assignee=assignee).exists()
@classmethod
def get_user_related_tickets(cls, user):
queries = Q(applicant=user) | Q(ticket_steps__ticket_assignees__assignee=user)

View File

@ -15,4 +15,4 @@ class IsApplicant(permissions.BasePermission):
class IsAssignee(permissions.BasePermission):
def has_permission(self, request, view):
return view.ticket.has_assignee(request.user)
return view.ticket.has_all_assignee(request.user)

View File

@ -3,7 +3,7 @@ from rest_framework import permissions
class IsAssignee(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
return obj.has_assignee(request.user)
return obj.has_current_assignee(request.user)
class IsApplicant(permissions.BasePermission):