stages/*: remove path-based import from all stages

This commit is contained in:
Jens Langhammer 2020-07-20 16:23:30 +02:00
parent 6fa825e372
commit a3d92ebc0a
19 changed files with 194 additions and 37 deletions

View File

@ -1,6 +1,10 @@
"""passbook captcha stage""" """passbook captcha stage"""
from typing import Type
from django.db import models from django.db import models
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -19,8 +23,15 @@ class CaptchaStage(Stage):
) )
) )
type = "passbook.stages.captcha.stage.CaptchaStage" def type(self) -> Type[View]:
form = "passbook.stages.captcha.forms.CaptchaStageForm" 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): def __str__(self):
return f"Captcha Stage {self.name}" return f"Captcha Stage {self.name}"

View File

@ -6,7 +6,7 @@ from passbook.flows.stage import StageView
from passbook.stages.captcha.forms import CaptchaForm 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""" """Simple captcha checker, logic is handeled in django-captcha module"""
form_class = CaptchaForm form_class = CaptchaForm

View File

@ -1,5 +1,9 @@
"""passbook consent stage""" """passbook consent stage"""
from typing import Type
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -7,8 +11,15 @@ from passbook.flows.models import Stage
class ConsentStage(Stage): class ConsentStage(Stage):
"""Prompt the user for confirmation.""" """Prompt the user for confirmation."""
type = "passbook.stages.consent.stage.ConsentStage" def type(self) -> Type[View]:
form = "passbook.stages.consent.forms.ConsentStageForm" 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): def __str__(self):
return f"Consent Stage {self.name}" return f"Consent Stage {self.name}"

View File

@ -9,7 +9,7 @@ from passbook.stages.consent.forms import ConsentForm
PLAN_CONTEXT_CONSENT_TEMPLATE = "consent_template" PLAN_CONTEXT_CONSENT_TEMPLATE = "consent_template"
class ConsentStage(FormView, StageView): class ConsentStageView(FormView, StageView):
"""Simple consent checker.""" """Simple consent checker."""
form_class = ConsentForm form_class = ConsentForm

View File

@ -1,5 +1,9 @@
"""dummy stage models""" """dummy stage models"""
from typing import Type
from django.forms import ModelForm
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views import View
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -9,8 +13,15 @@ class DummyStage(Stage):
__debug_only__ = True __debug_only__ = True
type = "passbook.stages.dummy.stage.DummyStage" def type(self) -> Type[View]:
form = "passbook.stages.dummy.forms.DummyStageForm" 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): def __str__(self):
return f"Dummy Stage {self.name}" return f"Dummy Stage {self.name}"

View File

@ -6,7 +6,7 @@ from django.http import HttpRequest
from passbook.flows.stage import StageView from passbook.flows.stage import StageView
class DummyStage(StageView): class DummyStageView(StageView):
"""Dummy stage for testing with multiple stages""" """Dummy stage for testing with multiple stages"""
def post(self, request: HttpRequest): def post(self, request: HttpRequest):

View File

@ -1,8 +1,12 @@
"""email stage models""" """email stage models"""
from typing import Type
from django.core.mail import get_connection from django.core.mail import get_connection
from django.core.mail.backends.base import BaseEmailBackend from django.core.mail.backends.base import BaseEmailBackend
from django.db import models from django.db import models
from django.forms import ModelForm
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views import View
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -40,8 +44,15 @@ class EmailStage(Stage):
choices=EmailTemplates.choices, default=EmailTemplates.PASSWORD_RESET choices=EmailTemplates.choices, default=EmailTemplates.PASSWORD_RESET
) )
type = "passbook.stages.email.stage.EmailStageView" def type(self) -> Type[View]:
form = "passbook.stages.email.forms.EmailStageForm" from passbook.stages.email.stage import EmailStageView
return EmailStageView
def form(self) -> Type[ModelForm]:
from passbook.stages.email.forms import EmailStageForm
return EmailStageForm
@property @property
def backend(self) -> BaseEmailBackend: def backend(self) -> BaseEmailBackend:

View File

@ -1,7 +1,11 @@
"""identification stage models""" """identification stage models"""
from typing import Type
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields import ArrayField
from django.db import models from django.db import models
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import Flow, Stage from passbook.flows.models import Flow, Stage
@ -52,8 +56,15 @@ class IdentificationStage(Stage):
), ),
) )
type = "passbook.stages.identification.stage.IdentificationStageView" def type(self) -> Type[View]:
form = "passbook.stages.identification.forms.IdentificationStageForm" 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): def __str__(self):
return f"Identification Stage {self.name}" return f"Identification Stage {self.name}"

View File

@ -1,9 +1,12 @@
"""invitation stage models""" """invitation stage models"""
from typing import Type
from uuid import uuid4 from uuid import uuid4
from django.contrib.postgres.fields import JSONField from django.contrib.postgres.fields import JSONField
from django.db import models from django.db import models
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.core.models import User from passbook.core.models import User
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -24,8 +27,15 @@ class InvitationStage(Stage):
), ),
) )
type = "passbook.stages.invitation.stage.InvitationStageView" def type(self) -> Type[View]:
form = "passbook.stages.invitation.forms.InvitationStageForm" 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): def __str__(self):
return f"Invitation Stage {self.name}" return f"Invitation Stage {self.name}"

View File

@ -1,9 +1,11 @@
"""OTP Static models""" """OTP Static models"""
from typing import Optional from typing import Optional, Type
from django.db import models from django.db import models
from django.forms import ModelForm
from django.shortcuts import reverse from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.core.types import UIUserSettings from passbook.core.types import UIUserSettings
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -14,8 +16,15 @@ class OTPStaticStage(Stage):
token_count = models.IntegerField(default=6) token_count = models.IntegerField(default=6)
type = "passbook.stages.otp_static.stage.OTPStaticStageView" def type(self) -> Type[View]:
form = "passbook.stages.otp_static.forms.OTPStaticStageForm" 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 @property
def ui_user_settings(self) -> Optional[UIUserSettings]: def ui_user_settings(self) -> Optional[UIUserSettings]:

View File

@ -1,9 +1,11 @@
"""OTP Time-based models""" """OTP Time-based models"""
from typing import Optional from typing import Optional, Type
from django.db import models from django.db import models
from django.forms import ModelForm
from django.shortcuts import reverse from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.core.types import UIUserSettings from passbook.core.types import UIUserSettings
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -21,8 +23,15 @@ class OTPTimeStage(Stage):
digits = models.IntegerField(choices=TOTPDigits.choices) digits = models.IntegerField(choices=TOTPDigits.choices)
type = "passbook.stages.otp_time.stage.OTPTimeStageView" def type(self) -> Type[View]:
form = "passbook.stages.otp_time.forms.OTPTimeStageForm" 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 @property
def ui_user_settings(self) -> Optional[UIUserSettings]: def ui_user_settings(self) -> Optional[UIUserSettings]:

View File

@ -1,6 +1,10 @@
"""OTP Validation Stage""" """OTP Validation Stage"""
from typing import Type
from django.db import models from django.db import models
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import NotConfiguredAction, Stage from passbook.flows.models import NotConfiguredAction, Stage
@ -12,8 +16,15 @@ class OTPValidateStage(Stage):
choices=NotConfiguredAction.choices, default=NotConfiguredAction.SKIP choices=NotConfiguredAction.choices, default=NotConfiguredAction.SKIP
) )
type = "passbook.stages.otp_validate.stage.OTPValidateStageView" def type(self) -> Type[View]:
form = "passbook.stages.otp_validate.forms.OTPValidateStageForm" 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: def __str__(self) -> str:
return f"OTP Validation Stage {self.name}" return f"OTP Validation Stage {self.name}"

View File

@ -1,11 +1,13 @@
"""password stage models""" """password stage models"""
from typing import Optional from typing import Optional, Type
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields import ArrayField
from django.db import models from django.db import models
from django.forms import ModelForm
from django.shortcuts import reverse from django.shortcuts import reverse
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.core.types import UIUserSettings from passbook.core.types import UIUserSettings
from passbook.flows.models import Flow, Stage from passbook.flows.models import Flow, Stage
@ -33,8 +35,15 @@ class PasswordStage(Stage):
), ),
) )
type = "passbook.stages.password.stage.PasswordStage" def type(self) -> Type[View]:
form = "passbook.stages.password.forms.PasswordStageForm" from passbook.stages.password.stage import PasswordStageView
return PasswordStageView
def form(self) -> Type[ModelForm]:
from passbook.stages.password.forms import PasswordStageForm
return PasswordStageForm
@property @property
def ui_user_settings(self) -> Optional[UIUserSettings]: def ui_user_settings(self) -> Optional[UIUserSettings]:

View File

@ -46,7 +46,7 @@ def authenticate(
) )
class PasswordStage(FormView, StageView): class PasswordStageView(FormView, StageView):
"""Authentication stage which authenticates against django's AuthBackend""" """Authentication stage which authenticates against django's AuthBackend"""
form_class = PasswordForm form_class = PasswordForm

View File

@ -1,9 +1,12 @@
"""prompt models""" """prompt models"""
from typing import Type
from uuid import uuid4 from uuid import uuid4
from django import forms from django import forms
from django.db import models from django.db import models
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import Stage from passbook.flows.models import Stage
from passbook.policies.models import PolicyBindingModel from passbook.policies.models import PolicyBindingModel
@ -117,8 +120,15 @@ class PromptStage(PolicyBindingModel, Stage):
fields = models.ManyToManyField(Prompt) fields = models.ManyToManyField(Prompt)
type = "passbook.stages.prompt.stage.PromptStageView" def type(self) -> Type[View]:
form = "passbook.stages.prompt.forms.PromptStageForm" 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): def __str__(self):
return f"Prompt Stage {self.name}" return f"Prompt Stage {self.name}"

View File

@ -1,5 +1,9 @@
"""delete stage models""" """delete stage models"""
from typing import Type
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -8,8 +12,15 @@ class UserDeleteStage(Stage):
"""Deletes the currently pending user without confirmation. """Deletes the currently pending user without confirmation.
Use with caution.""" Use with caution."""
type = "passbook.stages.user_delete.stage.UserDeleteStageView" def type(self) -> Type[View]:
form = "passbook.stages.user_delete.forms.UserDeleteStageForm" 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): def __str__(self):
return f"User Delete Stage {self.name}" return f"User Delete Stage {self.name}"

View File

@ -1,6 +1,10 @@
"""login stage models""" """login stage models"""
from typing import Type
from django.db import models from django.db import models
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -16,8 +20,15 @@ class UserLoginStage(Stage):
), ),
) )
type = "passbook.stages.user_login.stage.UserLoginStageView" def type(self) -> Type[View]:
form = "passbook.stages.user_login.forms.UserLoginStageForm" 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): def __str__(self):
return f"User Login Stage {self.name}" return f"User Login Stage {self.name}"

View File

@ -1,5 +1,9 @@
"""logout stage models""" """logout stage models"""
from typing import Type
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import Stage from passbook.flows.models import Stage
@ -7,8 +11,15 @@ from passbook.flows.models import Stage
class UserLogoutStage(Stage): class UserLogoutStage(Stage):
"""Resets the users current session.""" """Resets the users current session."""
type = "passbook.stages.user_logout.stage.UserLogoutStageView" def type(self) -> Type[View]:
form = "passbook.stages.user_logout.forms.UserLogoutStageForm" 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): def __str__(self):
return f"User Logout Stage {self.name}" return f"User Logout Stage {self.name}"

View File

@ -1,5 +1,9 @@
"""write stage models""" """write stage models"""
from typing import Type
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from passbook.flows.models import Stage 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, """Writes currently pending data into the pending user, or if no user exists,
creates a new user with the data.""" creates a new user with the data."""
type = "passbook.stages.user_write.stage.UserWriteStageView" def type(self) -> Type[View]:
form = "passbook.stages.user_write.forms.UserWriteStageForm" 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): def __str__(self):
return f"User Write Stage {self.name}" return f"User Write Stage {self.name}"