From c7c387eb382eed6373cb9e56e9a1170090cf9e70 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 4 Feb 2021 09:50:14 +0100 Subject: [PATCH] providers/*: add assigned application name and slug --- authentik/core/api/providers.py | 5 +++++ authentik/providers/oauth2/api.py | 6 ++++++ authentik/providers/proxy/api.py | 7 ++++++- authentik/providers/saml/api.py | 10 +++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/authentik/core/api/providers.py b/authentik/core/api/providers.py index 08358be49..19e9b7f09 100644 --- a/authentik/core/api/providers.py +++ b/authentik/core/api/providers.py @@ -1,4 +1,5 @@ """Provider API Views""" +from rest_framework.fields import ReadOnlyField from rest_framework.serializers import ModelSerializer, SerializerMethodField from rest_framework.viewsets import ModelViewSet @@ -44,6 +45,10 @@ class ProviderViewSet(ModelViewSet): filterset_fields = { "application": ["isnull"], } + search_fields = [ + "name", + "application__name", + ] def get_queryset(self): return Provider.objects.select_subclasses() diff --git a/authentik/providers/oauth2/api.py b/authentik/providers/oauth2/api.py index e3a28c70a..1c2da3e21 100644 --- a/authentik/providers/oauth2/api.py +++ b/authentik/providers/oauth2/api.py @@ -1,4 +1,5 @@ """OAuth2Provider API Views""" +from rest_framework.fields import ReadOnlyField from rest_framework.serializers import ModelSerializer from rest_framework.viewsets import ModelViewSet @@ -9,6 +10,9 @@ from authentik.providers.oauth2.models import OAuth2Provider, ScopeMapping class OAuth2ProviderSerializer(ModelSerializer, MetaNameSerializer): """OAuth2Provider Serializer""" + assigned_application_slug = ReadOnlyField(source="application.slug") + assigned_application_name = ReadOnlyField(source="application.name") + class Meta: model = OAuth2Provider @@ -27,6 +31,8 @@ class OAuth2ProviderSerializer(ModelSerializer, MetaNameSerializer): "sub_mode", "property_mappings", "issuer_mode", + "assigned_application_slug", + "assigned_application_name", "verbose_name", "verbose_name_plural", ] diff --git a/authentik/providers/proxy/api.py b/authentik/providers/proxy/api.py index b1765bb28..b91451881 100644 --- a/authentik/providers/proxy/api.py +++ b/authentik/providers/proxy/api.py @@ -1,6 +1,6 @@ """ProxyProvider API Views""" from drf_yasg2.utils import swagger_serializer_method -from rest_framework.fields import CharField, ListField, SerializerMethodField +from rest_framework.fields import CharField, ListField, ReadOnlyField, SerializerMethodField from rest_framework.request import Request from rest_framework.response import Response from rest_framework.serializers import ModelSerializer, Serializer @@ -37,6 +37,9 @@ class OpenIDConnectConfigurationSerializer(Serializer): class ProxyProviderSerializer(MetaNameSerializer, ModelSerializer): """ProxyProvider Serializer""" + assigned_application_slug = ReadOnlyField(source="application.slug") + assigned_application_name = ReadOnlyField(source="application.name") + def create(self, validated_data): instance: ProxyProvider = super().create(validated_data) instance.set_oauth_defaults() @@ -61,6 +64,8 @@ class ProxyProviderSerializer(MetaNameSerializer, ModelSerializer): "basic_auth_enabled", "basic_auth_password_attribute", "basic_auth_user_attribute", + "assigned_application_slug", + "assigned_application_name", "verbose_name", "verbose_name_plural", ] diff --git a/authentik/providers/saml/api.py b/authentik/providers/saml/api.py index ab91ca59f..11ca9a051 100644 --- a/authentik/providers/saml/api.py +++ b/authentik/providers/saml/api.py @@ -1,5 +1,8 @@ """SAMLProvider API Views""" -from rest_framework.serializers import ModelSerializer +from typing import Optional +from authentik.core.models import Application +from rest_framework.fields import ReadOnlyField, SerializerMethodField +from rest_framework.serializers import ModelSerializer, Serializer, CharField from rest_framework.viewsets import ModelViewSet from authentik.core.api.utils import MetaNameSerializer @@ -9,6 +12,9 @@ from authentik.providers.saml.models import SAMLPropertyMapping, SAMLProvider class SAMLProviderSerializer(ModelSerializer, MetaNameSerializer): """SAMLProvider Serializer""" + assigned_application_slug = ReadOnlyField(source="application.slug") + assigned_application_name = ReadOnlyField(source="application.name") + class Meta: model = SAMLProvider @@ -27,6 +33,8 @@ class SAMLProviderSerializer(ModelSerializer, MetaNameSerializer): "signature_algorithm", "signing_kp", "verification_kp", + "assigned_application_slug", + "assigned_application_name", "verbose_name", "verbose_name_plural", ]