2021-08-25 11:02:50 +00:00
|
|
|
from django_filters import rest_framework as filters
|
2022-06-28 09:19:33 +00:00
|
|
|
from django.db.models import Subquery, OuterRef
|
|
|
|
|
2021-08-25 11:02:50 +00:00
|
|
|
from common.drf.filters import BaseFilterSet
|
|
|
|
|
2022-06-23 05:52:28 +00:00
|
|
|
from tickets.models import (
|
2022-08-16 08:34:16 +00:00
|
|
|
Ticket, TicketStep, ApplyAssetTicket,
|
2022-06-23 05:52:28 +00:00
|
|
|
ApplyLoginTicket, ApplyLoginAssetTicket, ApplyCommandTicket
|
|
|
|
)
|
2021-08-25 11:02:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TicketFilter(BaseFilterSet):
|
|
|
|
assignees__id = filters.UUIDFilter(method='filter_assignees_id')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Ticket
|
|
|
|
fields = (
|
2022-06-23 05:52:28 +00:00
|
|
|
'id', 'title', 'type', 'status', 'state', 'applicant', 'assignees__id'
|
2021-08-25 11:02:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def filter_assignees_id(self, queryset, name, value):
|
2022-06-28 09:19:33 +00:00
|
|
|
step_qs = TicketStep.objects.filter(
|
|
|
|
level=OuterRef("approval_step")
|
|
|
|
).values_list('id', flat=True)
|
|
|
|
return queryset.filter(
|
|
|
|
ticket_steps__id__in=Subquery(step_qs),
|
|
|
|
ticket_steps__ticket_assignees__assignee__id=value
|
|
|
|
)
|
2022-06-23 05:52:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ApplyAssetTicketFilter(BaseFilterSet):
|
|
|
|
class Meta:
|
|
|
|
model = ApplyAssetTicket
|
|
|
|
fields = ('id',)
|
|
|
|
|
|
|
|
|
|
|
|
class ApplyLoginTicketFilter(BaseFilterSet):
|
|
|
|
class Meta:
|
|
|
|
model = ApplyLoginTicket
|
|
|
|
fields = ('id',)
|
|
|
|
|
|
|
|
|
|
|
|
class ApplyLoginAssetTicketFilter(BaseFilterSet):
|
|
|
|
class Meta:
|
|
|
|
model = ApplyLoginAssetTicket
|
|
|
|
fields = ('id',)
|
|
|
|
|
|
|
|
|
|
|
|
class ApplyCommandTicketFilter(BaseFilterSet):
|
|
|
|
class Meta:
|
|
|
|
model = ApplyCommandTicket
|
|
|
|
fields = ('id',)
|