managed: add API serializer, add managed field

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-02 12:03:33 +02:00
parent 75d67e0e05
commit 742f570c4c
4 changed files with 46 additions and 2 deletions

View File

@ -22,6 +22,7 @@ from authentik.core.expression import PropertyMappingEvaluator
from authentik.core.models import PropertyMapping
from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses
from authentik.managed.api import ManagedSerializer
from authentik.policies.api.exec import PolicyTestSerializer
@ -32,7 +33,7 @@ class PropertyMappingTestResultSerializer(PassiveSerializer):
successful = BooleanField(read_only=True)
class PropertyMappingSerializer(ModelSerializer, MetaNameSerializer):
class PropertyMappingSerializer(ManagedSerializer, ModelSerializer, MetaNameSerializer):
"""PropertyMapping Serializer"""
object_type = SerializerMethodField()
@ -52,6 +53,7 @@ class PropertyMappingSerializer(ModelSerializer, MetaNameSerializer):
model = PropertyMapping
fields = [
"pk",
"managed",
"name",
"expression",
"object_type",

View File

@ -13,9 +13,10 @@ from authentik.core.api.users import UserSerializer
from authentik.core.api.utils import PassiveSerializer
from authentik.core.models import Token
from authentik.events.models import Event, EventAction
from authentik.managed.api import ManagedSerializer
class TokenSerializer(ModelSerializer):
class TokenSerializer(ManagedSerializer, ModelSerializer):
"""Token Serializer"""
user = UserSerializer(required=False)
@ -25,6 +26,7 @@ class TokenSerializer(ModelSerializer):
model = Token
fields = [
"pk",
"managed",
"identifier",
"intent",
"user",

10
authentik/managed/api.py Normal file
View File

@ -0,0 +1,10 @@
"""Serializer mixin for managed models"""
from rest_framework.fields import CharField
from authentik.core.api.utils import PassiveSerializer
class ManagedSerializer(PassiveSerializer):
"""Managed Serializer"""
managed = CharField(read_only=True, allow_null=True)

View File

@ -14876,6 +14876,12 @@ definitions:
type: string
format: uuid
readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
identifier:
title: Identifier
type: string
@ -16534,6 +16540,12 @@ definitions:
type: string
format: uuid
readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
name:
title: Name
type: string
@ -16578,6 +16590,12 @@ definitions:
type: string
format: uuid
readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
name:
title: Name
type: string
@ -16614,6 +16632,12 @@ definitions:
type: string
format: uuid
readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
name:
title: Name
type: string
@ -16654,6 +16678,12 @@ definitions:
type: string
format: uuid
readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
name:
title: Name
type: string