From a3d92ebc0a9744efbe3f3940d83e357fad0c63d5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 20 Jul 2020 16:23:30 +0200 Subject: [PATCH] stages/*: remove path-based import from all stages --- passbook/stages/captcha/models.py | 15 +++++++++++++-- passbook/stages/captcha/stage.py | 2 +- passbook/stages/consent/models.py | 15 +++++++++++++-- passbook/stages/consent/stage.py | 2 +- passbook/stages/dummy/models.py | 15 +++++++++++++-- passbook/stages/dummy/stage.py | 2 +- passbook/stages/email/models.py | 15 +++++++++++++-- passbook/stages/identification/models.py | 15 +++++++++++++-- passbook/stages/invitation/models.py | 14 ++++++++++++-- passbook/stages/otp_static/models.py | 15 ++++++++++++--- passbook/stages/otp_time/models.py | 15 ++++++++++++--- passbook/stages/otp_validate/models.py | 15 +++++++++++++-- passbook/stages/password/models.py | 15 ++++++++++++--- passbook/stages/password/stage.py | 2 +- passbook/stages/prompt/models.py | 14 ++++++++++++-- passbook/stages/user_delete/models.py | 15 +++++++++++++-- passbook/stages/user_login/models.py | 15 +++++++++++++-- passbook/stages/user_logout/models.py | 15 +++++++++++++-- passbook/stages/user_write/models.py | 15 +++++++++++++-- 19 files changed, 194 insertions(+), 37 deletions(-) diff --git a/passbook/stages/captcha/models.py b/passbook/stages/captcha/models.py index db52e4722c..584a5ca41d 100644 --- a/passbook/stages/captcha/models.py +++ b/passbook/stages/captcha/models.py @@ -1,6 +1,10 @@ """passbook captcha stage""" +from typing import Type + from django.db import models +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import Stage @@ -19,8 +23,15 @@ class CaptchaStage(Stage): ) ) - type = "passbook.stages.captcha.stage.CaptchaStage" - form = "passbook.stages.captcha.forms.CaptchaStageForm" + def type(self) -> Type[View]: + from passbook.stages.captcha.stage import CaptchaStageView + + return CaptchaStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.captcha.forms import CaptchaStageForm + + return CaptchaStageForm def __str__(self): return f"Captcha Stage {self.name}" diff --git a/passbook/stages/captcha/stage.py b/passbook/stages/captcha/stage.py index 69e789ac36..f758506e7d 100644 --- a/passbook/stages/captcha/stage.py +++ b/passbook/stages/captcha/stage.py @@ -6,7 +6,7 @@ from passbook.flows.stage import StageView from passbook.stages.captcha.forms import CaptchaForm -class CaptchaStage(FormView, StageView): +class CaptchaStageView(FormView, StageView): """Simple captcha checker, logic is handeled in django-captcha module""" form_class = CaptchaForm diff --git a/passbook/stages/consent/models.py b/passbook/stages/consent/models.py index 3132474c59..5c36793917 100644 --- a/passbook/stages/consent/models.py +++ b/passbook/stages/consent/models.py @@ -1,5 +1,9 @@ """passbook consent stage""" +from typing import Type + +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import Stage @@ -7,8 +11,15 @@ from passbook.flows.models import Stage class ConsentStage(Stage): """Prompt the user for confirmation.""" - type = "passbook.stages.consent.stage.ConsentStage" - form = "passbook.stages.consent.forms.ConsentStageForm" + def type(self) -> Type[View]: + from passbook.stages.consent.stage import ConsentStageView + + return ConsentStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.consent.forms import ConsentStageForm + + return ConsentStageForm def __str__(self): return f"Consent Stage {self.name}" diff --git a/passbook/stages/consent/stage.py b/passbook/stages/consent/stage.py index 3a1fa14a21..9ad58fde2a 100644 --- a/passbook/stages/consent/stage.py +++ b/passbook/stages/consent/stage.py @@ -9,7 +9,7 @@ from passbook.stages.consent.forms import ConsentForm PLAN_CONTEXT_CONSENT_TEMPLATE = "consent_template" -class ConsentStage(FormView, StageView): +class ConsentStageView(FormView, StageView): """Simple consent checker.""" form_class = ConsentForm diff --git a/passbook/stages/dummy/models.py b/passbook/stages/dummy/models.py index 3dfb1d8914..14d77ba6a9 100644 --- a/passbook/stages/dummy/models.py +++ b/passbook/stages/dummy/models.py @@ -1,5 +1,9 @@ """dummy stage models""" +from typing import Type + +from django.forms import ModelForm from django.utils.translation import gettext as _ +from django.views import View from passbook.flows.models import Stage @@ -9,8 +13,15 @@ class DummyStage(Stage): __debug_only__ = True - type = "passbook.stages.dummy.stage.DummyStage" - form = "passbook.stages.dummy.forms.DummyStageForm" + def type(self) -> Type[View]: + from passbook.stages.dummy.stage import DummyStageView + + return DummyStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.dummy.forms import DummyStageForm + + return DummyStageForm def __str__(self): return f"Dummy Stage {self.name}" diff --git a/passbook/stages/dummy/stage.py b/passbook/stages/dummy/stage.py index 07f3dacff9..bb0620cef1 100644 --- a/passbook/stages/dummy/stage.py +++ b/passbook/stages/dummy/stage.py @@ -6,7 +6,7 @@ from django.http import HttpRequest from passbook.flows.stage import StageView -class DummyStage(StageView): +class DummyStageView(StageView): """Dummy stage for testing with multiple stages""" def post(self, request: HttpRequest): diff --git a/passbook/stages/email/models.py b/passbook/stages/email/models.py index 6508704b3f..3c575f692e 100644 --- a/passbook/stages/email/models.py +++ b/passbook/stages/email/models.py @@ -1,8 +1,12 @@ """email stage models""" +from typing import Type + from django.core.mail import get_connection from django.core.mail.backends.base import BaseEmailBackend from django.db import models +from django.forms import ModelForm from django.utils.translation import gettext as _ +from django.views import View from passbook.flows.models import Stage @@ -40,8 +44,15 @@ class EmailStage(Stage): choices=EmailTemplates.choices, default=EmailTemplates.PASSWORD_RESET ) - type = "passbook.stages.email.stage.EmailStageView" - form = "passbook.stages.email.forms.EmailStageForm" + def type(self) -> Type[View]: + from passbook.stages.email.stage import EmailStageView + + return EmailStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.email.forms import EmailStageForm + + return EmailStageForm @property def backend(self) -> BaseEmailBackend: diff --git a/passbook/stages/identification/models.py b/passbook/stages/identification/models.py index bc5c4ceccf..86963d931d 100644 --- a/passbook/stages/identification/models.py +++ b/passbook/stages/identification/models.py @@ -1,7 +1,11 @@ """identification stage models""" +from typing import Type + from django.contrib.postgres.fields import ArrayField from django.db import models +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import Flow, Stage @@ -52,8 +56,15 @@ class IdentificationStage(Stage): ), ) - type = "passbook.stages.identification.stage.IdentificationStageView" - form = "passbook.stages.identification.forms.IdentificationStageForm" + def type(self) -> Type[View]: + from passbook.stages.identification.stage import IdentificationStageView + + return IdentificationStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.identification.forms import IdentificationStageForm + + return IdentificationStageForm def __str__(self): return f"Identification Stage {self.name}" diff --git a/passbook/stages/invitation/models.py b/passbook/stages/invitation/models.py index 5b9024aeca..db7e47011a 100644 --- a/passbook/stages/invitation/models.py +++ b/passbook/stages/invitation/models.py @@ -1,9 +1,12 @@ """invitation stage models""" +from typing import Type from uuid import uuid4 from django.contrib.postgres.fields import JSONField from django.db import models +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.core.models import User from passbook.flows.models import Stage @@ -24,8 +27,15 @@ class InvitationStage(Stage): ), ) - type = "passbook.stages.invitation.stage.InvitationStageView" - form = "passbook.stages.invitation.forms.InvitationStageForm" + def type(self) -> Type[View]: + from passbook.stages.invitation.stage import InvitationStageView + + return InvitationStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.invitation.forms import InvitationStageForm + + return InvitationStageForm def __str__(self): return f"Invitation Stage {self.name}" diff --git a/passbook/stages/otp_static/models.py b/passbook/stages/otp_static/models.py index 0d6b9a7a07..7005fed8c1 100644 --- a/passbook/stages/otp_static/models.py +++ b/passbook/stages/otp_static/models.py @@ -1,9 +1,11 @@ """OTP Static models""" -from typing import Optional +from typing import Optional, Type from django.db import models +from django.forms import ModelForm from django.shortcuts import reverse from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.core.types import UIUserSettings from passbook.flows.models import Stage @@ -14,8 +16,15 @@ class OTPStaticStage(Stage): token_count = models.IntegerField(default=6) - type = "passbook.stages.otp_static.stage.OTPStaticStageView" - form = "passbook.stages.otp_static.forms.OTPStaticStageForm" + def type(self) -> Type[View]: + from passbook.stages.otp_static.stage import OTPStaticStageView + + return OTPStaticStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.otp_static.forms import OTPStaticStageForm + + return OTPStaticStageForm @property def ui_user_settings(self) -> Optional[UIUserSettings]: diff --git a/passbook/stages/otp_time/models.py b/passbook/stages/otp_time/models.py index 73b6840e5e..7b9460cc56 100644 --- a/passbook/stages/otp_time/models.py +++ b/passbook/stages/otp_time/models.py @@ -1,9 +1,11 @@ """OTP Time-based models""" -from typing import Optional +from typing import Optional, Type from django.db import models +from django.forms import ModelForm from django.shortcuts import reverse from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.core.types import UIUserSettings from passbook.flows.models import Stage @@ -21,8 +23,15 @@ class OTPTimeStage(Stage): digits = models.IntegerField(choices=TOTPDigits.choices) - type = "passbook.stages.otp_time.stage.OTPTimeStageView" - form = "passbook.stages.otp_time.forms.OTPTimeStageForm" + def type(self) -> Type[View]: + from passbook.stages.otp_time.stage import OTPTimeStageView + + return OTPTimeStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.otp_time.forms import OTPTimeStageForm + + return OTPTimeStageForm @property def ui_user_settings(self) -> Optional[UIUserSettings]: diff --git a/passbook/stages/otp_validate/models.py b/passbook/stages/otp_validate/models.py index 4015aa3652..f89735025b 100644 --- a/passbook/stages/otp_validate/models.py +++ b/passbook/stages/otp_validate/models.py @@ -1,6 +1,10 @@ """OTP Validation Stage""" +from typing import Type + from django.db import models +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import NotConfiguredAction, Stage @@ -12,8 +16,15 @@ class OTPValidateStage(Stage): choices=NotConfiguredAction.choices, default=NotConfiguredAction.SKIP ) - type = "passbook.stages.otp_validate.stage.OTPValidateStageView" - form = "passbook.stages.otp_validate.forms.OTPValidateStageForm" + def type(self) -> Type[View]: + from passbook.stages.otp_validate.stage import OTPValidateStageView + + return OTPValidateStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.otp_validate.forms import OTPValidateStageForm + + return OTPValidateStageForm def __str__(self) -> str: return f"OTP Validation Stage {self.name}" diff --git a/passbook/stages/password/models.py b/passbook/stages/password/models.py index 24275916f9..c9d7fce3c8 100644 --- a/passbook/stages/password/models.py +++ b/passbook/stages/password/models.py @@ -1,11 +1,13 @@ """password stage models""" -from typing import Optional +from typing import Optional, Type from django.contrib.postgres.fields import ArrayField from django.db import models +from django.forms import ModelForm from django.shortcuts import reverse from django.utils.http import urlencode from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.core.types import UIUserSettings from passbook.flows.models import Flow, Stage @@ -33,8 +35,15 @@ class PasswordStage(Stage): ), ) - type = "passbook.stages.password.stage.PasswordStage" - form = "passbook.stages.password.forms.PasswordStageForm" + def type(self) -> Type[View]: + from passbook.stages.password.stage import PasswordStageView + + return PasswordStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.password.forms import PasswordStageForm + + return PasswordStageForm @property def ui_user_settings(self) -> Optional[UIUserSettings]: diff --git a/passbook/stages/password/stage.py b/passbook/stages/password/stage.py index 8dd708f252..9a48fb3c0f 100644 --- a/passbook/stages/password/stage.py +++ b/passbook/stages/password/stage.py @@ -46,7 +46,7 @@ def authenticate( ) -class PasswordStage(FormView, StageView): +class PasswordStageView(FormView, StageView): """Authentication stage which authenticates against django's AuthBackend""" form_class = PasswordForm diff --git a/passbook/stages/prompt/models.py b/passbook/stages/prompt/models.py index 9c44c0ed5e..d641f7405d 100644 --- a/passbook/stages/prompt/models.py +++ b/passbook/stages/prompt/models.py @@ -1,9 +1,12 @@ """prompt models""" +from typing import Type from uuid import uuid4 from django import forms from django.db import models +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import Stage from passbook.policies.models import PolicyBindingModel @@ -117,8 +120,15 @@ class PromptStage(PolicyBindingModel, Stage): fields = models.ManyToManyField(Prompt) - type = "passbook.stages.prompt.stage.PromptStageView" - form = "passbook.stages.prompt.forms.PromptStageForm" + def type(self) -> Type[View]: + from passbook.stages.prompt.stage import PromptStageView + + return PromptStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.prompt.forms import PromptStageForm + + return PromptStageForm def __str__(self): return f"Prompt Stage {self.name}" diff --git a/passbook/stages/user_delete/models.py b/passbook/stages/user_delete/models.py index 1e9483ad3e..667673c72e 100644 --- a/passbook/stages/user_delete/models.py +++ b/passbook/stages/user_delete/models.py @@ -1,5 +1,9 @@ """delete stage models""" +from typing import Type + +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import Stage @@ -8,8 +12,15 @@ class UserDeleteStage(Stage): """Deletes the currently pending user without confirmation. Use with caution.""" - type = "passbook.stages.user_delete.stage.UserDeleteStageView" - form = "passbook.stages.user_delete.forms.UserDeleteStageForm" + def type(self) -> Type[View]: + from passbook.stages.user_delete.stage import UserDeleteStageView + + return UserDeleteStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.user_delete.forms import UserDeleteStageForm + + return UserDeleteStageForm def __str__(self): return f"User Delete Stage {self.name}" diff --git a/passbook/stages/user_login/models.py b/passbook/stages/user_login/models.py index 08497983f4..96c86661ea 100644 --- a/passbook/stages/user_login/models.py +++ b/passbook/stages/user_login/models.py @@ -1,6 +1,10 @@ """login stage models""" +from typing import Type + from django.db import models +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import Stage @@ -16,8 +20,15 @@ class UserLoginStage(Stage): ), ) - type = "passbook.stages.user_login.stage.UserLoginStageView" - form = "passbook.stages.user_login.forms.UserLoginStageForm" + def type(self) -> Type[View]: + from passbook.stages.user_login.stage import UserLoginStageView + + return UserLoginStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.user_login.forms import UserLoginStageForm + + return UserLoginStageForm def __str__(self): return f"User Login Stage {self.name}" diff --git a/passbook/stages/user_logout/models.py b/passbook/stages/user_logout/models.py index 51833bfe19..d85bf22524 100644 --- a/passbook/stages/user_logout/models.py +++ b/passbook/stages/user_logout/models.py @@ -1,5 +1,9 @@ """logout stage models""" +from typing import Type + +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import Stage @@ -7,8 +11,15 @@ from passbook.flows.models import Stage class UserLogoutStage(Stage): """Resets the users current session.""" - type = "passbook.stages.user_logout.stage.UserLogoutStageView" - form = "passbook.stages.user_logout.forms.UserLogoutStageForm" + def type(self) -> Type[View]: + from passbook.stages.user_logout.stage import UserLogoutStageView + + return UserLogoutStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.user_logout.forms import UserLogoutStageForm + + return UserLogoutStageForm def __str__(self): return f"User Logout Stage {self.name}" diff --git a/passbook/stages/user_write/models.py b/passbook/stages/user_write/models.py index 140b5623de..bc7635b6d9 100644 --- a/passbook/stages/user_write/models.py +++ b/passbook/stages/user_write/models.py @@ -1,5 +1,9 @@ """write stage models""" +from typing import Type + +from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ +from django.views import View from passbook.flows.models import Stage @@ -8,8 +12,15 @@ class UserWriteStage(Stage): """Writes currently pending data into the pending user, or if no user exists, creates a new user with the data.""" - type = "passbook.stages.user_write.stage.UserWriteStageView" - form = "passbook.stages.user_write.forms.UserWriteStageForm" + def type(self) -> Type[View]: + from passbook.stages.user_write.stage import UserWriteStageView + + return UserWriteStageView + + def form(self) -> Type[ModelForm]: + from passbook.stages.user_write.forms import UserWriteStageForm + + return UserWriteStageForm def __str__(self): return f"User Write Stage {self.name}"