diff --git a/authentik/core/api/propertymappings.py b/authentik/core/api/propertymappings.py index b87865c86..147ba44fe 100644 --- a/authentik/core/api/propertymappings.py +++ b/authentik/core/api/propertymappings.py @@ -1,9 +1,16 @@ """PropertyMapping API Views""" +from django.shortcuts import reverse +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 authentik.core.api.utils import MetaNameSerializer +from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer from authentik.core.models import PropertyMapping +from authentik.lib.templatetags.authentik_utils import verbose_name +from authentik.lib.utils.reflection import all_subclasses class PropertyMappingSerializer(ModelSerializer, MetaNameSerializer): @@ -47,3 +54,19 @@ class PropertyMappingViewSet(ReadOnlyModelViewSet): def get_queryset(self): return PropertyMapping.objects.select_subclasses() + + @swagger_auto_schema(responses={200: TypeCreateSerializer(many=True)}) + @action(detail=False) + def types(self, request: Request) -> Response: + """Get all creatable property-mapping types""" + data = [] + for subclass in all_subclasses(self.queryset.model): + data.append( + { + "name": verbose_name(subclass), + "description": subclass.__doc__, + "link": reverse("authentik_admin:property-mapping-create") + + f"?type={subclass.__name__}", + } + ) + return Response(TypeCreateSerializer(data, many=True).data) diff --git a/swagger.yaml b/swagger.yaml index 99d8fb2fc..3274888bc 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -3876,6 +3876,47 @@ paths: tags: - propertymappings parameters: [] + /propertymappings/all/types/: + get: + operationId: propertymappings_all_types + description: Get all creatable property-mapping types + parameters: + - name: managed__isnull + in: query + description: '' + required: false + type: string + - 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: Types of an object that can be created + schema: + description: '' + type: array + items: + $ref: '#/definitions/TypeCreate' + tags: + - propertymappings + parameters: [] /propertymappings/all/{pm_uuid}/: get: operationId: propertymappings_all_read diff --git a/web/src/api/PropertyMapping.ts b/web/src/api/PropertyMapping.ts index 1a61133f5..eae1f176f 100644 --- a/web/src/api/PropertyMapping.ts +++ b/web/src/api/PropertyMapping.ts @@ -1,4 +1,5 @@ import { DefaultClient, AKResponse, QueryArguments } from "./Client"; +import { TypeCreate } from "./Providers"; export class PropertyMapping { pk: string; @@ -20,6 +21,10 @@ export class PropertyMapping { return DefaultClient.fetch>(["propertymappings", "all"], filter); } + static getTypes(): Promise { + return DefaultClient.fetch(["propertymappings", "all", "types"]); + } + static adminUrl(rest: string): string { return `/administration/property-mappings/${rest}`; } diff --git a/web/src/pages/property-mappings/PropertyMappingListPage.ts b/web/src/pages/property-mappings/PropertyMappingListPage.ts index 7fa245f5d..210059ce1 100644 --- a/web/src/pages/property-mappings/PropertyMappingListPage.ts +++ b/web/src/pages/property-mappings/PropertyMappingListPage.ts @@ -8,6 +8,7 @@ import "../../elements/buttons/ModalButton"; import "../../elements/buttons/Dropdown"; import "../../elements/buttons/SpinnerButton"; import { TableColumn } from "../../elements/table/Table"; +import { until } from "lit-html/directives/until"; @customElement("ak-property-mapping-list") export class PropertyMappingListPage extends TablePage { @@ -82,36 +83,18 @@ export class PropertyMappingListPage extends TablePage { ${super.renderToolbar()}`;