api: fix types for config API

This commit is contained in:
Jens Langhammer 2021-03-03 19:52:56 +01:00
parent ea784d47f4
commit 466723573c
3 changed files with 18 additions and 16 deletions

View File

@ -24,9 +24,10 @@ class TaskSerializer(Serializer):
task_description = CharField() task_description = CharField()
task_finish_timestamp = DateTimeField(source="finish_timestamp") task_finish_timestamp = DateTimeField(source="finish_timestamp")
status = ChoiceField(source="result.status.name", choices=[ status = ChoiceField(
(x.name, x.name) for x in TaskResultStatus source="result.status.name",
]) choices=[(x.name, x.name) for x in TaskResultStatus],
)
messages = ListField(source="result.messages") messages = ListField(source="result.messages")
def create(self, validated_data: dict) -> Model: def create(self, validated_data: dict) -> Model:

View File

@ -1,10 +1,11 @@
"""core Configs API""" """core Configs API"""
from django.db.models import Model from django.db.models import Model
from drf_yasg2.utils import swagger_auto_schema from drf_yasg2.utils import swagger_auto_schema
from rest_framework.fields import BooleanField, CharField
from rest_framework.permissions import AllowAny from rest_framework.permissions import AllowAny
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.serializers import ReadOnlyField, Serializer from rest_framework.serializers import Serializer
from rest_framework.viewsets import ViewSet from rest_framework.viewsets import ViewSet
from authentik.lib.config import CONFIG from authentik.lib.config import CONFIG
@ -13,12 +14,12 @@ from authentik.lib.config import CONFIG
class ConfigSerializer(Serializer): class ConfigSerializer(Serializer):
"""Serialize authentik Config into DRF Object""" """Serialize authentik Config into DRF Object"""
branding_logo = ReadOnlyField() branding_logo = CharField(read_only=True)
branding_title = ReadOnlyField() branding_title = CharField(read_only=True)
error_reporting_enabled = ReadOnlyField() error_reporting_enabled = BooleanField(read_only=True)
error_reporting_environment = ReadOnlyField() error_reporting_environment = CharField(read_only=True)
error_reporting_send_pii = ReadOnlyField() error_reporting_send_pii = BooleanField(read_only=True)
def create(self, validated_data: dict) -> Model: def create(self, validated_data: dict) -> Model:
raise NotImplementedError raise NotImplementedError
@ -32,7 +33,7 @@ class ConfigsViewSet(ViewSet):
permission_classes = [AllowAny] permission_classes = [AllowAny]
@swagger_auto_schema(responses={200: ConfigSerializer(many=True)}) @swagger_auto_schema(responses={200: ConfigSerializer(many=False)})
def list(self, request: Request) -> Response: def list(self, request: Request) -> Response:
"""Retrive public configuration options""" """Retrive public configuration options"""
config = ConfigSerializer( config = ConfigSerializer(

View File

@ -5841,10 +5841,7 @@ paths:
'200': '200':
description: Serialize authentik Config into DRF Object description: Serialize authentik Config into DRF Object
schema: schema:
description: '' $ref: '#/definitions/Config'
type: array
items:
$ref: '#/definitions/Config'
tags: tags:
- root - root
parameters: [] parameters: []
@ -11815,21 +11812,24 @@ definitions:
title: Branding logo title: Branding logo
type: string type: string
readOnly: true readOnly: true
minLength: 1
branding_title: branding_title:
title: Branding title title: Branding title
type: string type: string
readOnly: true readOnly: true
minLength: 1
error_reporting_enabled: error_reporting_enabled:
title: Error reporting enabled title: Error reporting enabled
type: string type: boolean
readOnly: true readOnly: true
error_reporting_environment: error_reporting_environment:
title: Error reporting environment title: Error reporting environment
type: string type: string
readOnly: true readOnly: true
minLength: 1
error_reporting_send_pii: error_reporting_send_pii:
title: Error reporting send pii title: Error reporting send pii
type: string type: boolean
readOnly: true readOnly: true
Source: Source:
description: Source Serializer description: Source Serializer