core: add source endpoint

This commit is contained in:
Jens Langhammer 2021-02-10 20:12:02 +01:00
parent 2b7a22a29a
commit a367d8515f
2 changed files with 62 additions and 1 deletions

View File

@ -1,8 +1,16 @@
"""Source API Views"""
from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses
from drf_yasg2.utils import swagger_auto_schema
from rest_framework.decorators import action
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.serializers import ModelSerializer, SerializerMethodField
from rest_framework.viewsets import ReadOnlyModelViewSet
from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _
from authentik.core.api.utils import MetaNameSerializer
from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
from authentik.core.models import Source
@ -40,3 +48,20 @@ class SourceViewSet(ReadOnlyModelViewSet):
def get_queryset(self):
return Source.objects.select_subclasses()
@swagger_auto_schema(responses={200: TypeCreateSerializer(many=True)})
@action(detail=False)
# pylint: disable=unused-argument
def types(self, request: Request) -> Response:
"""Get all creatable source types"""
data = []
for subclass in all_subclasses(self.queryset.model):
data.append(
{
"name": verbose_name(subclass),
"description": subclass.__doc__,
"link": reverse("authentik_admin:source-create")
+ f"?type={subclass.__name__}",
}
)
return Response(TypeCreateSerializer(data, many=True).data)

View File

@ -4909,6 +4909,42 @@ paths:
tags:
- sources
parameters: []
/sources/all/types/:
get:
operationId: sources_all_types
description: Get all creatable source types
parameters:
- name: ordering
in: query
description: Which field to use when ordering the results.
required: false
type: string
- name: search
in: query
description: A search term.
required: false
type: string
- name: page
in: query
description: A page number within the paginated result set.
required: false
type: integer
- name: page_size
in: query
description: Number of results to return per page.
required: false
type: integer
responses:
'200':
description: ''
schema:
description: ''
type: array
items:
$ref: '#/definitions/TypeCreate'
tags:
- sources
parameters: []
/sources/all/{slug}/:
get:
operationId: sources_all_read