*: ensure all resources can be filtered

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-07 16:12:38 +02:00
parent decb91e5f1
commit 9c9addb0ce
40 changed files with 1722 additions and 11 deletions

View File

@ -30,3 +30,5 @@ class NotificationRuleViewSet(UsedByMixin, ModelViewSet):
queryset = NotificationRule.objects.all()
serializer_class = NotificationRuleSerializer
filterset_fields = ["name", "severity", "group__name"]
ordering = ["name"]

View File

@ -5,11 +5,12 @@ from rest_framework.decorators import action
from rest_framework.fields import CharField, ListField, SerializerMethodField
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.serializers import ModelSerializer, Serializer
from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet
from authentik.api.decorators import permission_required
from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import PassiveSerializer
from authentik.events.models import (
Notification,
NotificationSeverity,
@ -41,23 +42,19 @@ class NotificationTransportSerializer(ModelSerializer):
]
class NotificationTransportTestSerializer(Serializer):
class NotificationTransportTestSerializer(PassiveSerializer):
"""Notification test serializer"""
messages = ListField(child=CharField())
def create(self, validated_data: Request) -> Response:
raise NotImplementedError
def update(self, request: Request) -> Response:
raise NotImplementedError
class NotificationTransportViewSet(UsedByMixin, ModelViewSet):
"""NotificationTransport Viewset"""
queryset = NotificationTransport.objects.all()
serializer_class = NotificationTransportSerializer
filterset_fields = ["name", "mode", "webhook_url", "send_once"]
ordering = ["name"]
@permission_required("authentik_events.change_notificationtransport")
@extend_schema(

View File

@ -99,6 +99,8 @@ class OutpostViewSet(UsedByMixin, ModelViewSet):
serializer_class = OutpostSerializer
filterset_fields = {
"providers": ["isnull"],
"name": ["iexact", "icontains"],
"service_connection__name": ["iexact", "icontains"],
}
search_fields = [
"name",

View File

@ -115,6 +115,8 @@ class DockerServiceConnectionViewSet(UsedByMixin, ModelViewSet):
queryset = DockerServiceConnection.objects.all()
serializer_class = DockerServiceConnectionSerializer
filterset_fields = ["name", "local", "url", "tls_verification", "tls_authentication"]
ordering = ["name"]
class KubernetesServiceConnectionSerializer(ServiceConnectionSerializer):
@ -147,3 +149,5 @@ class KubernetesServiceConnectionViewSet(UsedByMixin, ModelViewSet):
queryset = KubernetesServiceConnection.objects.all()
serializer_class = KubernetesServiceConnectionSerializer
filterset_fields = ["name", "local"]
ordering = ["name"]

View File

@ -19,3 +19,5 @@ class DummyPolicyViewSet(UsedByMixin, ModelViewSet):
queryset = DummyPolicy.objects.all()
serializer_class = DummyPolicySerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -23,3 +23,5 @@ class EventMatcherPolicyViewSet(UsedByMixin, ModelViewSet):
queryset = EventMatcherPolicy.objects.all()
serializer_class = EventMatcherPolicySerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -19,3 +19,5 @@ class PasswordExpiryPolicyViewSet(UsedByMixin, ModelViewSet):
queryset = PasswordExpiryPolicy.objects.all()
serializer_class = PasswordExpiryPolicySerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -26,3 +26,5 @@ class ExpressionPolicyViewSet(UsedByMixin, ModelViewSet):
queryset = ExpressionPolicy.objects.all()
serializer_class = ExpressionPolicySerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -19,3 +19,5 @@ class HaveIBeenPwendPolicyViewSet(UsedByMixin, ModelViewSet):
queryset = HaveIBeenPwendPolicy.objects.all()
serializer_class = HaveIBeenPwendPolicySerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -27,3 +27,5 @@ class PasswordPolicyViewSet(UsedByMixin, ModelViewSet):
queryset = PasswordPolicy.objects.all()
serializer_class = PasswordPolicySerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -25,6 +25,8 @@ class ReputationPolicyViewSet(UsedByMixin, ModelViewSet):
queryset = ReputationPolicy.objects.all()
serializer_class = ReputationPolicySerializer
filterset_fields = "__all__"
ordering = ["name"]
class IPReputationSerializer(ModelSerializer):

View File

@ -29,6 +29,7 @@ class LDAPProviderViewSet(UsedByMixin, ModelViewSet):
queryset = LDAPProvider.objects.all()
serializer_class = LDAPProviderSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -62,6 +62,25 @@ class OAuth2ProviderViewSet(UsedByMixin, ModelViewSet):
queryset = OAuth2Provider.objects.all()
serializer_class = OAuth2ProviderSerializer
filterset_fields = [
"name",
"authorization_flow",
"property_mappings",
"application",
"authorization_flow",
"client_type",
"client_id",
"access_code_validity",
"token_validity",
"include_claims_in_id_token",
"jwt_alg",
"rsa_key",
"redirect_uris",
"sub_mode",
"property_mappings",
"issuer_mode",
]
ordering = ["name"]
@extend_schema(
responses={

View File

@ -23,3 +23,5 @@ class ScopeMappingViewSet(UsedByMixin, ModelViewSet):
queryset = ScopeMapping.objects.all()
serializer_class = ScopeMappingSerializer
filterset_fields = ["scope_name", "name", "managed"]
ordering = ["scope_name", "name"]

View File

@ -80,6 +80,7 @@ class ProxyProviderViewSet(UsedByMixin, ModelViewSet):
queryset = ProxyProvider.objects.all()
serializer_class = ProxyProviderSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -89,6 +89,8 @@ class SAMLProviderViewSet(UsedByMixin, ModelViewSet):
queryset = SAMLProvider.objects.all()
serializer_class = SAMLProviderSerializer
filterset_fields = "__all__"
ordering = ["name"]
@extend_schema(
responses={
@ -183,3 +185,5 @@ class SAMLPropertyMappingViewSet(UsedByMixin, ModelViewSet):
queryset = SAMLPropertyMapping.objects.all()
serializer_class = SAMLPropertyMappingSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -48,6 +48,31 @@ class LDAPSourceViewSet(UsedByMixin, ModelViewSet):
queryset = LDAPSource.objects.all()
serializer_class = LDAPSourceSerializer
lookup_field = "slug"
filterset_fields = [
"name",
"slug",
"enabled",
"authentication_flow",
"enrollment_flow",
"policy_engine_mode",
"server_uri",
"bind_cn",
"start_tls",
"base_dn",
"additional_user_dn",
"additional_group_dn",
"user_object_filter",
"group_object_filter",
"group_membership_field",
"object_uniqueness_field",
"sync_users",
"sync_users_password",
"sync_groups",
"sync_parent_group",
"property_mappings",
"property_mappings_group",
]
ordering = ["name"]
@extend_schema(
responses={
@ -81,3 +106,5 @@ class LDAPPropertyMappingViewSet(UsedByMixin, ModelViewSet):
queryset = LDAPPropertyMapping.objects.all()
serializer_class = LDAPPropertyMappingSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -83,6 +83,22 @@ class OAuthSourceViewSet(UsedByMixin, ModelViewSet):
queryset = OAuthSource.objects.all()
serializer_class = OAuthSourceSerializer
lookup_field = "slug"
filterset_fields = [
"name",
"slug",
"enabled",
"authentication_flow",
"enrollment_flow",
"policy_engine_mode",
"user_matching_mode",
"provider_type",
"request_token_url",
"authorization_url",
"access_token_url",
"profile_url",
"consumer_key",
]
ordering = ["name"]
@extend_schema(responses={200: SourceTypeSerializer(many=True)})
@action(detail=False, pagination_class=None, filter_backends=[])

View File

@ -49,6 +49,18 @@ class PlexSourceViewSet(UsedByMixin, ModelViewSet):
queryset = PlexSource.objects.all()
serializer_class = PlexSourceSerializer
lookup_field = "slug"
filterset_fields = [
"name",
"slug",
"enabled",
"authentication_flow",
"enrollment_flow",
"policy_engine_mode",
"user_matching_mode",
"client_id",
"allow_friends",
]
ordering = ["name"]
@permission_required(None)
@extend_schema(

View File

@ -40,6 +40,8 @@ class SAMLSourceViewSet(UsedByMixin, ModelViewSet):
queryset = SAMLSource.objects.all()
serializer_class = SAMLSourceSerializer
lookup_field = "slug"
filterset_fields = "__all__"
ordering = ["name"]
@extend_schema(responses={200: SAMLMetadataSerializer(many=False)})
@action(methods=["GET"], detail=True)

View File

@ -43,6 +43,13 @@ class AuthenticatorDuoStageViewSet(UsedByMixin, ModelViewSet):
queryset = AuthenticatorDuoStage.objects.all()
serializer_class = AuthenticatorDuoStageSerializer
filterset_fields = [
"name",
"configure_flow",
"client_id",
"api_hostname",
]
ordering = ["name"]
@extend_schema(
request=OpenApiTypes.NONE,

View File

@ -27,6 +27,8 @@ class AuthenticatorStaticStageViewSet(UsedByMixin, ModelViewSet):
queryset = AuthenticatorStaticStage.objects.all()
serializer_class = AuthenticatorStaticStageSerializer
filterset_fields = "__all__"
ordering = ["name"]
class StaticDeviceTokenSerializer(ModelSerializer):

View File

@ -27,6 +27,8 @@ class AuthenticatorTOTPStageViewSet(UsedByMixin, ModelViewSet):
queryset = AuthenticatorTOTPStage.objects.all()
serializer_class = AuthenticatorTOTPStageSerializer
filterset_fields = "__all__"
ordering = ["name"]
class TOTPDeviceSerializer(ModelSerializer):

View File

@ -38,3 +38,5 @@ class AuthenticatorValidateStageViewSet(UsedByMixin, ModelViewSet):
queryset = AuthenticatorValidateStage.objects.all()
serializer_class = AuthenticatorValidateStageSerializer
filterset_fields = ["name", "not_configured_action", "configuration_stage"]
ordering = ["name"]

View File

@ -26,6 +26,8 @@ class AuthenticateWebAuthnStageViewSet(UsedByMixin, ModelViewSet):
queryset = AuthenticateWebAuthnStage.objects.all()
serializer_class = AuthenticateWebAuthnStageSerializer
filterset_fields = "__all__"
ordering = ["name"]
class WebAuthnDeviceSerializer(ModelSerializer):

View File

@ -21,3 +21,5 @@ class CaptchaStageViewSet(UsedByMixin, ModelViewSet):
queryset = CaptchaStage.objects.all()
serializer_class = CaptchaStageSerializer
filterset_fields = ["name", "public_key"]
ordering = ["name"]

View File

@ -26,6 +26,8 @@ class ConsentStageViewSet(UsedByMixin, ModelViewSet):
queryset = ConsentStage.objects.all()
serializer_class = ConsentStageSerializer
filterset_fields = "__all__"
ordering = ["name"]
class UserConsentSerializer(StageSerializer):

View File

@ -20,3 +20,5 @@ class DenyStageViewSet(UsedByMixin, ModelViewSet):
queryset = DenyStage.objects.all()
serializer_class = DenyStageSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -20,3 +20,5 @@ class DummyStageViewSet(UsedByMixin, ModelViewSet):
queryset = DummyStage.objects.all()
serializer_class = DummyStageSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -52,6 +52,21 @@ class EmailStageViewSet(UsedByMixin, ModelViewSet):
queryset = EmailStage.objects.all()
serializer_class = EmailStageSerializer
filterset_fields = [
"name",
"use_global_settings",
"host",
"port",
"username",
"use_tls",
"use_ssl",
"timeout",
"from_address",
"token_expiry",
"subject",
"template",
]
ordering = ["name"]
@extend_schema(responses={200: TypeCreateSerializer(many=True)})
@action(detail=False, pagination_class=None, filter_backends=[])

View File

@ -28,3 +28,12 @@ class IdentificationStageViewSet(UsedByMixin, ModelViewSet):
queryset = IdentificationStage.objects.all()
serializer_class = IdentificationStageSerializer
filterset_fields = [
"name",
"password_stage",
"case_insensitive_matching",
"show_matched_user",
"enrollment_flow",
"recovery_flow",
]
ordering = ["name"]

View File

@ -26,6 +26,8 @@ class InvitationStageViewSet(UsedByMixin, ModelViewSet):
queryset = InvitationStage.objects.all()
serializer_class = InvitationStageSerializer
filterset_fields = "__all__"
ordering = ["name"]
class InvitationSerializer(ModelSerializer):

View File

@ -24,3 +24,9 @@ class PasswordStageViewSet(UsedByMixin, ModelViewSet):
queryset = PasswordStage.objects.all()
serializer_class = PasswordStageSerializer
filterset_fields = [
"name",
"configure_flow",
"failed_attempts_before_cancel",
]
ordering = ["name"]

View File

@ -27,6 +27,8 @@ class PromptStageViewSet(UsedByMixin, ModelViewSet):
queryset = PromptStage.objects.all()
serializer_class = PromptStageSerializer
filterset_fields = "__all__"
ordering = ["name"]
class PromptSerializer(ModelSerializer):

View File

@ -20,3 +20,5 @@ class UserDeleteStageViewSet(UsedByMixin, ModelViewSet):
queryset = UserDeleteStage.objects.all()
serializer_class = UserDeleteStageSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -22,3 +22,5 @@ class UserLoginStageViewSet(UsedByMixin, ModelViewSet):
queryset = UserLoginStage.objects.all()
serializer_class = UserLoginStageSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -20,3 +20,5 @@ class UserLogoutStageViewSet(UsedByMixin, ModelViewSet):
queryset = UserLogoutStage.objects.all()
serializer_class = UserLogoutStageSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -20,3 +20,5 @@ class UserWriteStageViewSet(UsedByMixin, ModelViewSet):
queryset = UserWriteStage.objects.all()
serializer_class = UserWriteStageSerializer
filterset_fields = "__all__"
ordering = ["name"]

View File

@ -70,6 +70,7 @@ class TenantViewSet(UsedByMixin, ModelViewSet):
"domain",
"branding_title",
]
filterset_fields = "__all__"
ordering = ["domain"]
@extend_schema(

1548
schema.yml

File diff suppressed because it is too large Load Diff