From c3398004ff3ed5a9976274e07ed7872f61e5105d Mon Sep 17 00:00:00 2001 From: Jens L Date: Mon, 15 May 2023 14:39:48 +0200 Subject: [PATCH] blueprints: add meta models to schema (#5611) these models were previously ignored Signed-off-by: Jens Langhammer --- .../commands/make_blueprint_schema.py | 22 ++++---- blueprints/schema.json | 51 +++++++++++++++++++ 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/authentik/blueprints/management/commands/make_blueprint_schema.py b/authentik/blueprints/management/commands/make_blueprint_schema.py index 1ac014858..5ca5d4eca 100644 --- a/authentik/blueprints/management/commands/make_blueprint_schema.py +++ b/authentik/blueprints/management/commands/make_blueprint_schema.py @@ -10,7 +10,7 @@ from rest_framework.serializers import Serializer from structlog.stdlib import get_logger from authentik.blueprints.v1.importer import SERIALIZER_CONTEXT_BLUEPRINT, is_model_allowed -from authentik.blueprints.v1.meta.registry import registry +from authentik.blueprints.v1.meta.registry import BaseMetaModel, registry from authentik.lib.models import SerializerModel LOGGER = get_logger() @@ -74,14 +74,18 @@ class Command(BaseCommand): def build(self): """Build all models into the schema""" for model in registry.get_models(): - if model._meta.abstract: - continue - if not is_model_allowed(model): - continue - model_instance: Model = model() - if not isinstance(model_instance, SerializerModel): - continue - serializer = model_instance.serializer( + if issubclass(model, BaseMetaModel): + serializer_class = model.serializer() + else: + if model._meta.abstract: + continue + if not is_model_allowed(model): + continue + model_instance: Model = model() + if not isinstance(model_instance, SerializerModel): + continue + serializer_class = model_instance.serializer + serializer = serializer_class( context={ SERIALIZER_CONTEXT_BLUEPRINT: False, } diff --git a/blueprints/schema.json b/blueprints/schema.json index 96e95a387..ea4c2a386 100644 --- a/blueprints/schema.json +++ b/blueprints/schema.json @@ -2560,6 +2560,42 @@ "$ref": "#/$defs/model_authentik_core.token" } } + }, + { + "type": "object", + "required": [ + "model", + "identifiers" + ], + "properties": { + "model": { + "const": "authentik_blueprints.metaapplyblueprint" + }, + "id": { + "type": "string" + }, + "state": { + "type": "string", + "enum": [ + "absent", + "present", + "created" + ], + "default": "present" + }, + "conditions": { + "type": "array", + "items": { + "type": "boolean" + } + }, + "attrs": { + "$ref": "#/$defs/model_authentik_blueprints.metaapplyblueprint" + }, + "identifiers": { + "$ref": "#/$defs/model_authentik_blueprints.metaapplyblueprint" + } + } } ] } @@ -8314,6 +8350,21 @@ } }, "required": [] + }, + "model_authentik_blueprints.metaapplyblueprint": { + "type": "object", + "properties": { + "identifiers": { + "type": "object", + "additionalProperties": true, + "title": "Identifiers" + }, + "required": { + "type": "boolean", + "title": "Required" + } + }, + "required": [] } } }