Browse Source

Merge pull request #6911 from jumpserver/pr@dev@ticket_perf

perf: 工单优化
pull/6912/head
feng626 3 years ago committed by GitHub
parent
commit
7578bda588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      apps/tickets/models/ticket.py
  2. 5
      apps/tickets/permissions/comment.py
  3. 2
      apps/tickets/permissions/ticket.py

6
apps/tickets/models/ticket.py

@ -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)

5
apps/tickets/permissions/comment.py

@ -15,4 +15,7 @@ class IsApplicant(permissions.BasePermission):
class IsAssignee(permissions.BasePermission):
def has_permission(self, request, view):
return view.ticket.has_assignee(request.user)
if view.action == 'list':
return view.ticket.has_all_assignee(request.user)
elif view.action == 'create':
return view.ticket.has_current_assignee(request.user)

2
apps/tickets/permissions/ticket.py

@ -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):

Loading…
Cancel
Save