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.core.models import PropertyMapping
from authentik.lib.templatetags.authentik_utils import verbose_name from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses from authentik.lib.utils.reflection import all_subclasses
from authentik.managed.api import ManagedSerializer
from authentik.policies.api.exec import PolicyTestSerializer from authentik.policies.api.exec import PolicyTestSerializer
@ -32,7 +33,7 @@ class PropertyMappingTestResultSerializer(PassiveSerializer):
successful = BooleanField(read_only=True) successful = BooleanField(read_only=True)
class PropertyMappingSerializer(ModelSerializer, MetaNameSerializer): class PropertyMappingSerializer(ManagedSerializer, ModelSerializer, MetaNameSerializer):
"""PropertyMapping Serializer""" """PropertyMapping Serializer"""
object_type = SerializerMethodField() object_type = SerializerMethodField()
@ -52,6 +53,7 @@ class PropertyMappingSerializer(ModelSerializer, MetaNameSerializer):
model = PropertyMapping model = PropertyMapping
fields = [ fields = [
"pk", "pk",
"managed",
"name", "name",
"expression", "expression",
"object_type", "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.api.utils import PassiveSerializer
from authentik.core.models import Token from authentik.core.models import Token
from authentik.events.models import Event, EventAction from authentik.events.models import Event, EventAction
from authentik.managed.api import ManagedSerializer
class TokenSerializer(ModelSerializer): class TokenSerializer(ManagedSerializer, ModelSerializer):
"""Token Serializer""" """Token Serializer"""
user = UserSerializer(required=False) user = UserSerializer(required=False)
@ -25,6 +26,7 @@ class TokenSerializer(ModelSerializer):
model = Token model = Token
fields = [ fields = [
"pk", "pk",
"managed",
"identifier", "identifier",
"intent", "intent",
"user", "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 type: string
format: uuid format: uuid
readOnly: true readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
identifier: identifier:
title: Identifier title: Identifier
type: string type: string
@ -16534,6 +16540,12 @@ definitions:
type: string type: string
format: uuid format: uuid
readOnly: true readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
name: name:
title: Name title: Name
type: string type: string
@ -16578,6 +16590,12 @@ definitions:
type: string type: string
format: uuid format: uuid
readOnly: true readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
name: name:
title: Name title: Name
type: string type: string
@ -16614,6 +16632,12 @@ definitions:
type: string type: string
format: uuid format: uuid
readOnly: true readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
name: name:
title: Name title: Name
type: string type: string
@ -16654,6 +16678,12 @@ definitions:
type: string type: string
format: uuid format: uuid
readOnly: true readOnly: true
managed:
title: Managed
type: string
readOnly: true
minLength: 1
x-nullable: true
name: name:
title: Name title: Name
type: string type: string