*: fix type annotations for serializer model

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-08-16 13:23:22 +02:00
parent 54eeb7add6
commit 6000a33a8e
31 changed files with 38 additions and 38 deletions

View file

@ -20,7 +20,7 @@ from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from guardian.mixins import GuardianUserMixin from guardian.mixins import GuardianUserMixin
from model_utils.managers import InheritanceManager from model_utils.managers import InheritanceManager
from rest_framework.serializers import BaseSerializer, Serializer from rest_framework.serializers import Serializer
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
from authentik.blueprints.models import ManagedModel from authentik.blueprints.models import ManagedModel
@ -482,7 +482,7 @@ class UserSourceConnection(SerializerModel, CreatedUpdatedModel):
objects = InheritanceManager() objects = InheritanceManager()
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[Serializer]:
"""Get serializer for this model""" """Get serializer for this model"""
raise NotImplementedError raise NotImplementedError
@ -553,7 +553,7 @@ class Token(SerializerModel, ManagedModel, ExpiringModel):
description = models.TextField(default="", blank=True) description = models.TextField(default="", blank=True)
@property @property
def serializer(self) -> Serializer: def serializer(self) -> type[Serializer]:
from authentik.core.api.tokens import TokenSerializer from authentik.core.api.tokens import TokenSerializer
return TokenSerializer return TokenSerializer

View file

@ -165,7 +165,7 @@ class Flow(SerializerModel, PolicyBindingModel):
stages = models.ManyToManyField(Stage, through="FlowStageBinding", blank=True) stages = models.ManyToManyField(Stage, through="FlowStageBinding", blank=True)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.flows.api.flows import FlowSerializer from authentik.flows.api.flows import FlowSerializer
return FlowSerializer return FlowSerializer
@ -225,7 +225,7 @@ class FlowStageBinding(SerializerModel, PolicyBindingModel):
objects = InheritanceManager() objects = InheritanceManager()
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.flows.api.bindings import FlowStageBindingSerializer from authentik.flows.api.bindings import FlowStageBindingSerializer
return FlowStageBindingSerializer return FlowStageBindingSerializer

View file

@ -12,7 +12,7 @@ class SerializerModel(models.Model):
"""Base Abstract Model which has a serializer""" """Base Abstract Model which has a serializer"""
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
"""Get serializer for this model""" """Get serializer for this model"""
raise NotImplementedError raise NotImplementedError

View file

@ -24,7 +24,7 @@ class DummyPolicy(Policy):
wait_max = models.IntegerField(default=30) wait_max = models.IntegerField(default=30)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.dummy.api import DummyPolicySerializer from authentik.policies.dummy.api import DummyPolicySerializer
return DummyPolicySerializer return DummyPolicySerializer

View file

@ -54,7 +54,7 @@ class EventMatcherPolicy(Policy):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.event_matcher.api import EventMatcherPolicySerializer from authentik.policies.event_matcher.api import EventMatcherPolicySerializer
return EventMatcherPolicySerializer return EventMatcherPolicySerializer

View file

@ -21,7 +21,7 @@ class PasswordExpiryPolicy(Policy):
days = models.IntegerField() days = models.IntegerField()
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.expiry.api import PasswordExpiryPolicySerializer from authentik.policies.expiry.api import PasswordExpiryPolicySerializer
return PasswordExpiryPolicySerializer return PasswordExpiryPolicySerializer

View file

@ -14,7 +14,7 @@ class ExpressionPolicy(Policy):
expression = models.TextField() expression = models.TextField()
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.expression.api import ExpressionPolicySerializer from authentik.policies.expression.api import ExpressionPolicySerializer
return ExpressionPolicySerializer return ExpressionPolicySerializer

View file

@ -26,7 +26,7 @@ class HaveIBeenPwendPolicy(Policy):
allowed_count = models.IntegerField(default=0) allowed_count = models.IntegerField(default=0)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.hibp.api import HaveIBeenPwendPolicySerializer from authentik.policies.hibp.api import HaveIBeenPwendPolicySerializer
return HaveIBeenPwendPolicySerializer return HaveIBeenPwendPolicySerializer

View file

@ -102,7 +102,7 @@ class PolicyBinding(SerializerModel):
return PolicyResult(False) return PolicyResult(False)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.api.bindings import PolicyBindingSerializer from authentik.policies.api.bindings import PolicyBindingSerializer
return PolicyBindingSerializer return PolicyBindingSerializer

View file

@ -33,7 +33,7 @@ class PasswordPolicy(Policy):
error_message = models.TextField() error_message = models.TextField()
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.password.api import PasswordPolicySerializer from authentik.policies.password.api import PasswordPolicySerializer
return PasswordPolicySerializer return PasswordPolicySerializer

View file

@ -25,7 +25,7 @@ class ReputationPolicy(Policy):
threshold = models.IntegerField(default=-5) threshold = models.IntegerField(default=-5)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.reputation.api import ReputationPolicySerializer from authentik.policies.reputation.api import ReputationPolicySerializer
return ReputationPolicySerializer return ReputationPolicySerializer
@ -73,7 +73,7 @@ class Reputation(SerializerModel):
updated = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now_add=True)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.policies.reputation.api import ReputationSerializer from authentik.policies.reputation.api import ReputationSerializer
return ReputationSerializer return ReputationSerializer

View file

@ -58,7 +58,7 @@ class PlexSource(Source):
return "ak-source-plex-form" return "ak-source-plex-form"
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.sources.plex.api.source import PlexSourceSerializer from authentik.sources.plex.api.source import PlexSourceSerializer
return PlexSourceSerializer return PlexSourceSerializer

View file

@ -23,7 +23,7 @@ class AuthenticatorDuoStage(ConfigurableStage, Stage):
api_hostname = models.TextField() api_hostname = models.TextField()
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.authenticator_duo.api import AuthenticatorDuoStageSerializer from authentik.stages.authenticator_duo.api import AuthenticatorDuoStageSerializer
return AuthenticatorDuoStageSerializer return AuthenticatorDuoStageSerializer

View file

@ -127,7 +127,7 @@ class AuthenticatorSMSStage(ConfigurableStage, Stage):
raise raise
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.authenticator_sms.api import AuthenticatorSMSStageSerializer from authentik.stages.authenticator_sms.api import AuthenticatorSMSStageSerializer
return AuthenticatorSMSStageSerializer return AuthenticatorSMSStageSerializer
@ -186,7 +186,7 @@ class SMSDevice(SerializerModel, SideChannelDevice):
return self.phone_number.startswith("hash:") return self.phone_number.startswith("hash:")
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.authenticator_sms.api import SMSDeviceSerializer from authentik.stages.authenticator_sms.api import SMSDeviceSerializer
return SMSDeviceSerializer return SMSDeviceSerializer

View file

@ -16,7 +16,7 @@ class AuthenticatorStaticStage(ConfigurableStage, Stage):
token_count = models.IntegerField(default=6) token_count = models.IntegerField(default=6)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.authenticator_static.api import AuthenticatorStaticStageSerializer from authentik.stages.authenticator_static.api import AuthenticatorStaticStageSerializer
return AuthenticatorStaticStageSerializer return AuthenticatorStaticStageSerializer

View file

@ -23,7 +23,7 @@ class AuthenticatorTOTPStage(ConfigurableStage, Stage):
digits = models.IntegerField(choices=TOTPDigits.choices) digits = models.IntegerField(choices=TOTPDigits.choices)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.authenticator_totp.api import AuthenticatorTOTPStageSerializer from authentik.stages.authenticator_totp.api import AuthenticatorTOTPStageSerializer
return AuthenticatorTOTPStageSerializer return AuthenticatorTOTPStageSerializer

View file

@ -70,7 +70,7 @@ class AuthenticatorValidateStage(Stage):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.authenticator_validate.api import AuthenticatorValidateStageSerializer from authentik.stages.authenticator_validate.api import AuthenticatorValidateStageSerializer
return AuthenticatorValidateStageSerializer return AuthenticatorValidateStageSerializer

View file

@ -82,7 +82,7 @@ class AuthenticateWebAuthnStage(ConfigurableStage, Stage):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.authenticator_webauthn.api import AuthenticateWebAuthnStageSerializer from authentik.stages.authenticator_webauthn.api import AuthenticateWebAuthnStageSerializer
return AuthenticateWebAuthnStageSerializer return AuthenticateWebAuthnStageSerializer

View file

@ -19,7 +19,7 @@ class CaptchaStage(Stage):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.captcha.api import CaptchaStageSerializer from authentik.stages.captcha.api import CaptchaStageSerializer
return CaptchaStageSerializer return CaptchaStageSerializer

View file

@ -31,7 +31,7 @@ class ConsentStage(Stage):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.consent.api import ConsentStageSerializer from authentik.stages.consent.api import ConsentStageSerializer
return ConsentStageSerializer return ConsentStageSerializer

View file

@ -11,7 +11,7 @@ class DenyStage(Stage):
"""Cancells the current flow.""" """Cancells the current flow."""
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.deny.api import DenyStageSerializer from authentik.stages.deny.api import DenyStageSerializer
return DenyStageSerializer return DenyStageSerializer

View file

@ -13,7 +13,7 @@ class DummyStage(Stage):
__debug_only__ = True __debug_only__ = True
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.dummy.api import DummyStageSerializer from authentik.stages.dummy.api import DummyStageSerializer
return DummyStageSerializer return DummyStageSerializer

View file

@ -82,7 +82,7 @@ class EmailStage(Stage):
template = models.TextField(default=EmailTemplates.PASSWORD_RESET) template = models.TextField(default=EmailTemplates.PASSWORD_RESET)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.email.api import EmailStageSerializer from authentik.stages.email.api import EmailStageSerializer
return EmailStageSerializer return EmailStageSerializer

View file

@ -92,7 +92,7 @@ class IdentificationStage(Stage):
show_source_labels = models.BooleanField(default=False) show_source_labels = models.BooleanField(default=False)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.identification.api import IdentificationStageSerializer from authentik.stages.identification.api import IdentificationStageSerializer
return IdentificationStageSerializer return IdentificationStageSerializer

View file

@ -27,7 +27,7 @@ class InvitationStage(Stage):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.invitation.api import InvitationStageSerializer from authentik.stages.invitation.api import InvitationStageSerializer
return InvitationStageSerializer return InvitationStageSerializer

View file

@ -48,7 +48,7 @@ class PasswordStage(ConfigurableStage, Stage):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.password.api import PasswordStageSerializer from authentik.stages.password.api import PasswordStageSerializer
return PasswordStageSerializer return PasswordStageSerializer

View file

@ -1,5 +1,5 @@
"""prompt models""" """prompt models"""
from typing import Any, Optional from typing import Any, Optional, Type
from urllib.parse import urlparse, urlunparse from urllib.parse import urlparse, urlunparse
from uuid import uuid4 from uuid import uuid4
@ -111,7 +111,7 @@ class Prompt(SerializerModel):
placeholder_expression = models.BooleanField(default=False) placeholder_expression = models.BooleanField(default=False)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> Type[BaseSerializer]:
from authentik.stages.prompt.api import PromptSerializer from authentik.stages.prompt.api import PromptSerializer
return PromptSerializer return PromptSerializer
@ -207,7 +207,7 @@ class PromptStage(Stage):
validation_policies = models.ManyToManyField(Policy, blank=True) validation_policies = models.ManyToManyField(Policy, blank=True)
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.prompt.api import PromptStageSerializer from authentik.stages.prompt.api import PromptStageSerializer
return PromptStageSerializer return PromptStageSerializer

View file

@ -12,7 +12,7 @@ class UserDeleteStage(Stage):
Use with caution.""" Use with caution."""
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.user_delete.api import UserDeleteStageSerializer from authentik.stages.user_delete.api import UserDeleteStageSerializer
return UserDeleteStageSerializer return UserDeleteStageSerializer

View file

@ -23,7 +23,7 @@ class UserLoginStage(Stage):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.user_login.api import UserLoginStageSerializer from authentik.stages.user_login.api import UserLoginStageSerializer
return UserLoginStageSerializer return UserLoginStageSerializer

View file

@ -11,7 +11,7 @@ class UserLogoutStage(Stage):
"""Resets the users current session.""" """Resets the users current session."""
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.user_logout.api import UserLogoutStageSerializer from authentik.stages.user_logout.api import UserLogoutStageSerializer
return UserLogoutStageSerializer return UserLogoutStageSerializer

View file

@ -32,7 +32,7 @@ class UserWriteStage(Stage):
) )
@property @property
def serializer(self) -> BaseSerializer: def serializer(self) -> type[BaseSerializer]:
from authentik.stages.user_write.api import UserWriteStageSerializer from authentik.stages.user_write.api import UserWriteStageSerializer
return UserWriteStageSerializer return UserWriteStageSerializer