23 lines
873 B
Python
23 lines
873 B
Python
"""Even superusers use the response-content gate in the application admin."""
|
|
from django.contrib import admin
|
|
from django.db.models import Q
|
|
|
|
from .dispatch_responses import sealed_message_q
|
|
from .models import Ticket
|
|
from .policies import TicketPolicy
|
|
|
|
|
|
class ResponseContentAdmin(admin.ModelAdmin):
|
|
message_prefix = ""
|
|
|
|
def get_queryset(self, request):
|
|
query = super().get_queryset(request).exclude(sealed_message_q(self.message_prefix))
|
|
ticket_path = self.message_prefix + "ticket"
|
|
allowed = Ticket.objects.filter(TicketPolicy.viewable_q(request.user)).values("pk")
|
|
return query.filter(Q(**{ticket_path + "__group_dispatch__response_control__isnull": True})
|
|
| Q(**{ticket_path + "__in": allowed})).distinct()
|
|
|
|
|
|
class RelatedResponseContentAdmin(ResponseContentAdmin):
|
|
message_prefix = "message__"
|