authentik.tenants.api.domains

Serializer for tenants models

 1"""Serializer for tenants models"""
 2
 3from django.apps import apps
 4from django.http import HttpResponseNotFound
 5from rest_framework.filters import OrderingFilter, SearchFilter
 6from rest_framework.permissions import IsAuthenticated
 7from rest_framework.viewsets import ModelViewSet
 8
 9from authentik.core.api.utils import ModelSerializer
10from authentik.tenants.api.tenants import TenantApiKeyAuthentication
11from authentik.tenants.models import Domain
12
13
14class DomainSerializer(ModelSerializer):
15    """Domain Serializer"""
16
17    class Meta:
18        model = Domain
19        fields = "__all__"
20
21
22class DomainViewSet(ModelViewSet):
23    """Domain ViewSet"""
24
25    queryset = Domain.objects.all()
26    serializer_class = DomainSerializer
27    search_fields = [
28        "domain",
29        "tenant__name",
30        "tenant__schema_name",
31    ]
32    ordering = ["domain"]
33    authentication_classes = [TenantApiKeyAuthentication]
34    permission_classes = [IsAuthenticated]
35    filter_backends = [OrderingFilter, SearchFilter]
36    filterset_fields = []
37
38    def dispatch(self, request, *args, **kwargs):
39        # This only checks the license in the default tenant, which is what we want
40        if not apps.get_app_config("authentik_enterprise").enabled():
41            return HttpResponseNotFound()
42        return super().dispatch(request, *args, **kwargs)
class DomainSerializer(authentik.core.api.utils.ModelSerializer):
15class DomainSerializer(ModelSerializer):
16    """Domain Serializer"""
17
18    class Meta:
19        model = Domain
20        fields = "__all__"

Domain Serializer

class DomainSerializer.Meta:
18    class Meta:
19        model = Domain
20        fields = "__all__"
fields = '__all__'
class DomainViewSet(rest_framework.viewsets.ModelViewSet):
23class DomainViewSet(ModelViewSet):
24    """Domain ViewSet"""
25
26    queryset = Domain.objects.all()
27    serializer_class = DomainSerializer
28    search_fields = [
29        "domain",
30        "tenant__name",
31        "tenant__schema_name",
32    ]
33    ordering = ["domain"]
34    authentication_classes = [TenantApiKeyAuthentication]
35    permission_classes = [IsAuthenticated]
36    filter_backends = [OrderingFilter, SearchFilter]
37    filterset_fields = []
38
39    def dispatch(self, request, *args, **kwargs):
40        # This only checks the license in the default tenant, which is what we want
41        if not apps.get_app_config("authentik_enterprise").enabled():
42            return HttpResponseNotFound()
43        return super().dispatch(request, *args, **kwargs)

Domain ViewSet

queryset = <QuerySet []>
serializer_class = <class 'DomainSerializer'>
search_fields = ['domain', 'tenant__name', 'tenant__schema_name']
ordering = ['domain']
authentication_classes = [<class 'authentik.tenants.api.tenants.TenantApiKeyAuthentication'>]
permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
filter_backends = [<class 'rest_framework.filters.OrderingFilter'>, <class 'rest_framework.filters.SearchFilter'>]
filterset_fields = []
def dispatch(self, request, *args, **kwargs):
39    def dispatch(self, request, *args, **kwargs):
40        # This only checks the license in the default tenant, which is what we want
41        if not apps.get_app_config("authentik_enterprise").enabled():
42            return HttpResponseNotFound()
43        return super().dispatch(request, *args, **kwargs)

.dispatch() is pretty much the same as Django's regular dispatch, but with extra hooks for startup, finalize, and exception handling.