diff --git a/apps/tickets/models/ticket.py b/apps/tickets/models/ticket.py index 9abd29c96..beb6d129b 100644 --- a/apps/tickets/models/ticket.py +++ b/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) diff --git a/apps/tickets/permissions/comment.py b/apps/tickets/permissions/comment.py index c478c7529..deea43d52 100644 --- a/apps/tickets/permissions/comment.py +++ b/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) diff --git a/apps/tickets/permissions/ticket.py b/apps/tickets/permissions/ticket.py index bd77421a8..29c7dd7b5 100644 --- a/apps/tickets/permissions/ticket.py +++ b/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):