54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
"""Provider API Views"""
|
|
from rest_framework.fields import ReadOnlyField
|
|
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
|
from rest_framework.viewsets import ModelViewSet
|
|
|
|
from authentik.core.api.utils import MetaNameSerializer
|
|
from authentik.core.models import Provider
|
|
|
|
|
|
class ProviderSerializer(ModelSerializer, MetaNameSerializer):
|
|
"""Provider Serializer"""
|
|
|
|
assigned_application_slug = ReadOnlyField(source="application.slug")
|
|
assigned_application_name = ReadOnlyField(source="application.name")
|
|
|
|
object_type = SerializerMethodField()
|
|
|
|
def get_object_type(self, obj):
|
|
"""Get object type so that we know which API Endpoint to use to get the full object"""
|
|
return obj._meta.object_name.lower().replace("provider", "")
|
|
|
|
class Meta:
|
|
|
|
model = Provider
|
|
fields = [
|
|
"pk",
|
|
"name",
|
|
"application",
|
|
"authorization_flow",
|
|
"property_mappings",
|
|
"object_type",
|
|
"assigned_application_slug",
|
|
"assigned_application_name",
|
|
"verbose_name",
|
|
"verbose_name_plural",
|
|
]
|
|
|
|
|
|
class ProviderViewSet(ModelViewSet):
|
|
"""Provider Viewset"""
|
|
|
|
queryset = Provider.objects.none()
|
|
serializer_class = ProviderSerializer
|
|
filterset_fields = {
|
|
"application": ["isnull"],
|
|
}
|
|
search_fields = [
|
|
"name",
|
|
"application__name",
|
|
]
|
|
|
|
def get_queryset(self):
|
|
return Provider.objects.select_subclasses()
|