core: add types API to propertymapping
This commit is contained in:
parent
0993d5ce4a
commit
71f771c22c
|
@ -1,9 +1,16 @@
|
||||||
"""PropertyMapping API Views"""
|
"""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.serializers import ModelSerializer, SerializerMethodField
|
||||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
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.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):
|
class PropertyMappingSerializer(ModelSerializer, MetaNameSerializer):
|
||||||
|
@ -47,3 +54,19 @@ class PropertyMappingViewSet(ReadOnlyModelViewSet):
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return PropertyMapping.objects.select_subclasses()
|
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)
|
||||||
|
|
41
swagger.yaml
41
swagger.yaml
|
@ -3876,6 +3876,47 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- propertymappings
|
- propertymappings
|
||||||
parameters: []
|
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}/:
|
/propertymappings/all/{pm_uuid}/:
|
||||||
get:
|
get:
|
||||||
operationId: propertymappings_all_read
|
operationId: propertymappings_all_read
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { DefaultClient, AKResponse, QueryArguments } from "./Client";
|
import { DefaultClient, AKResponse, QueryArguments } from "./Client";
|
||||||
|
import { TypeCreate } from "./Providers";
|
||||||
|
|
||||||
export class PropertyMapping {
|
export class PropertyMapping {
|
||||||
pk: string;
|
pk: string;
|
||||||
|
@ -20,6 +21,10 @@ export class PropertyMapping {
|
||||||
return DefaultClient.fetch<AKResponse<PropertyMapping>>(["propertymappings", "all"], filter);
|
return DefaultClient.fetch<AKResponse<PropertyMapping>>(["propertymappings", "all"], filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getTypes(): Promise<TypeCreate[]> {
|
||||||
|
return DefaultClient.fetch<TypeCreate[]>(["propertymappings", "all", "types"]);
|
||||||
|
}
|
||||||
|
|
||||||
static adminUrl(rest: string): string {
|
static adminUrl(rest: string): string {
|
||||||
return `/administration/property-mappings/${rest}`;
|
return `/administration/property-mappings/${rest}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import "../../elements/buttons/ModalButton";
|
||||||
import "../../elements/buttons/Dropdown";
|
import "../../elements/buttons/Dropdown";
|
||||||
import "../../elements/buttons/SpinnerButton";
|
import "../../elements/buttons/SpinnerButton";
|
||||||
import { TableColumn } from "../../elements/table/Table";
|
import { TableColumn } from "../../elements/table/Table";
|
||||||
|
import { until } from "lit-html/directives/until";
|
||||||
|
|
||||||
@customElement("ak-property-mapping-list")
|
@customElement("ak-property-mapping-list")
|
||||||
export class PropertyMappingListPage extends TablePage<PropertyMapping> {
|
export class PropertyMappingListPage extends TablePage<PropertyMapping> {
|
||||||
|
@ -82,36 +83,18 @@ export class PropertyMappingListPage extends TablePage<PropertyMapping> {
|
||||||
<i class="fas fa-caret-down pf-c-dropdown__toggle-icon" aria-hidden="true"></i>
|
<i class="fas fa-caret-down pf-c-dropdown__toggle-icon" aria-hidden="true"></i>
|
||||||
</button>
|
</button>
|
||||||
<ul class="pf-c-dropdown__menu" hidden>
|
<ul class="pf-c-dropdown__menu" hidden>
|
||||||
<li>
|
${until(PropertyMapping.getTypes().then((types) => {
|
||||||
<ak-modal-button href="${PropertyMapping.adminUrl("create/?type=LDAPPropertyMapping")}">
|
return types.map((type) => {
|
||||||
<button slot="trigger" class="pf-c-dropdown__menu-item">${gettext("LDAP Property Mapping")}<br>
|
return html`<li>
|
||||||
<small>
|
<ak-modal-button href="${type.link}">
|
||||||
${gettext("Map LDAP Property to User or Group object attribute")}
|
<button slot="trigger" class="pf-c-dropdown__menu-item">${type.name}<br>
|
||||||
</small>
|
<small>${type.description}</small>
|
||||||
</button>
|
</button>
|
||||||
<div slot="modal"></div>
|
<div slot="modal"></div>
|
||||||
</ak-modal-button>
|
</ak-modal-button>
|
||||||
</li>
|
</li>`;
|
||||||
<li>
|
});
|
||||||
<ak-modal-button href="${PropertyMapping.adminUrl("create/?type=SAMLPropertyMapping")}">
|
}), html`<ak-spinner></ak-spinner>`)}
|
||||||
<button slot="trigger" class="pf-c-dropdown__menu-item">${gettext("SAML Property Mapping")}<br>
|
|
||||||
<small>
|
|
||||||
${gettext("Map User/Group attribute to SAML Attribute, which can be used by the Service Provider.")}
|
|
||||||
</small>
|
|
||||||
</button>
|
|
||||||
<div slot="modal"></div>
|
|
||||||
</ak-modal-button>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<ak-modal-button href="${PropertyMapping.adminUrl("create/?type=ScopeMapping")}">
|
|
||||||
<button slot="trigger" class="pf-c-dropdown__menu-item">${gettext("Scope Mapping")}<br>
|
|
||||||
<small>
|
|
||||||
${gettext("Map an OAuth Scope to users properties")}
|
|
||||||
</small>
|
|
||||||
</button>
|
|
||||||
<div slot="modal"></div>
|
|
||||||
</ak-modal-button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</ak-dropdown>
|
</ak-dropdown>
|
||||||
${super.renderToolbar()}`;
|
${super.renderToolbar()}`;
|
||||||
|
|
Reference in New Issue