From f111604b704632ecf2121c8dcbbd0002d6a447af Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 10 May 2020 16:20:44 +0200 Subject: [PATCH] stages/login: -> stages/user_login: rename login to user_login for user_create stage --- passbook/api/v2/urls.py | 4 ++-- .../flows/migrations/0002_default_flows.py | 10 ++++---- passbook/root/settings.py | 2 +- passbook/stages/login/api.py | 24 ------------------- passbook/stages/login/apps.py | 10 -------- passbook/stages/login/forms.py | 16 ------------- passbook/stages/login/models.py | 19 --------------- .../stages/{login => user_login}/__init__.py | 0 passbook/stages/user_login/api.py | 24 +++++++++++++++++++ passbook/stages/user_login/apps.py | 10 ++++++++ passbook/stages/user_login/forms.py | 16 +++++++++++++ .../migrations/0001_initial.py | 8 +++---- .../migrations/__init__.py | 0 passbook/stages/user_login/models.py | 19 +++++++++++++++ .../stages/{login => user_login}/stage.py | 2 +- .../stages/{login => user_login}/tests.py | 6 ++--- 16 files changed, 85 insertions(+), 85 deletions(-) delete mode 100644 passbook/stages/login/api.py delete mode 100644 passbook/stages/login/apps.py delete mode 100644 passbook/stages/login/forms.py delete mode 100644 passbook/stages/login/models.py rename passbook/stages/{login => user_login}/__init__.py (100%) create mode 100644 passbook/stages/user_login/api.py create mode 100644 passbook/stages/user_login/apps.py create mode 100644 passbook/stages/user_login/forms.py rename passbook/stages/{login => user_login}/migrations/0001_initial.py (80%) rename passbook/stages/{login => user_login}/migrations/__init__.py (100%) create mode 100644 passbook/stages/user_login/models.py rename passbook/stages/{login => user_login}/stage.py (97%) rename passbook/stages/{login => user_login}/tests.py (94%) diff --git a/passbook/api/v2/urls.py b/passbook/api/v2/urls.py index 2adb3788d..b9fd4e23c 100644 --- a/passbook/api/v2/urls.py +++ b/passbook/api/v2/urls.py @@ -34,10 +34,10 @@ from passbook.sources.oauth.api import OAuthSourceViewSet from passbook.stages.captcha.api import CaptchaStageViewSet from passbook.stages.email.api import EmailStageViewSet from passbook.stages.identification.api import IdentificationStageViewSet -from passbook.stages.login.api import LoginStageViewSet from passbook.stages.otp.api import OTPStageViewSet from passbook.stages.password.api import PasswordStageViewSet from passbook.stages.prompt.api import PromptStageViewSet, PromptViewSet +from passbook.stages.user_login.api import UserLoginStageViewSet LOGGER = get_logger() router = routers.DefaultRouter() @@ -83,7 +83,7 @@ router.register("stages/email", EmailStageViewSet) router.register("stages/otp", OTPStageViewSet) router.register("stages/password", PasswordStageViewSet) router.register("stages/identification", IdentificationStageViewSet) -router.register("stages/login", LoginStageViewSet) +router.register("stages/user_login", UserLoginStageViewSet) router.register("stages/prompt", PromptStageViewSet) router.register("stages/prompt/prompts", PromptViewSet) diff --git a/passbook/flows/migrations/0002_default_flows.py b/passbook/flows/migrations/0002_default_flows.py index d42b8ded6..2db2f3af4 100644 --- a/passbook/flows/migrations/0002_default_flows.py +++ b/passbook/flows/migrations/0002_default_flows.py @@ -12,7 +12,7 @@ def create_default_flow(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): Flow = apps.get_model("passbook_flows", "Flow") FlowStageBinding = apps.get_model("passbook_flows", "FlowStageBinding") PasswordStage = apps.get_model("passbook_stages_password", "PasswordStage") - LoginStage = apps.get_model("passbook_stages_login", "LoginStage") + UserLoginStage = apps.get_model("passbook_stages_user_login", "UserLoginStage") IdentificationStage = apps.get_model( "passbook_stages_identification", "IdentificationStage" ) @@ -34,12 +34,12 @@ def create_default_flow(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): name="password", backends=["django.contrib.auth.backends.ModelBackend"], ) - if not LoginStage.objects.using(db_alias).exists(): - LoginStage.objects.using(db_alias).create(name="authentication") + if not UserLoginStage.objects.using(db_alias).exists(): + UserLoginStage.objects.using(db_alias).create(name="authentication") ident_stage = IdentificationStage.objects.using(db_alias).first() pw_stage = PasswordStage.objects.using(db_alias).first() - login_stage = LoginStage.objects.using(db_alias).first() + login_stage = UserLoginStage.objects.using(db_alias).first() flow = Flow.objects.using(db_alias).create( name="default-authentication-flow", slug="default-authentication-flow", @@ -60,7 +60,7 @@ class Migration(migrations.Migration): dependencies = [ ("passbook_flows", "0001_initial"), - ("passbook_stages_login", "0001_initial"), + ("passbook_stages_user_login", "0001_initial"), ("passbook_stages_password", "0001_initial"), ("passbook_stages_identification", "0001_initial"), ] diff --git a/passbook/root/settings.py b/passbook/root/settings.py index 9c970cbd9..c0405bd42 100644 --- a/passbook/root/settings.py +++ b/passbook/root/settings.py @@ -104,10 +104,10 @@ INSTALLED_APPS = [ "passbook.sources.saml.apps.PassbookSourceSAMLConfig", "passbook.stages.captcha.apps.PassbookStageCaptchaConfig", "passbook.stages.dummy.apps.PassbookStageDummyConfig", - "passbook.stages.login.apps.PassbookStageLoginConfig", "passbook.stages.email.apps.PassbookStageEmailConfig", "passbook.stages.prompt.apps.PassbookStagPromptConfig", "passbook.stages.identification.apps.PassbookStageIdentificationConfig", + "passbook.stages.user_login.apps.PassbookStageUserLoginConfig", "passbook.stages.otp.apps.PassbookStageOTPConfig", "passbook.stages.password.apps.PassbookStagePasswordConfig", "passbook.static.apps.PassbookStaticConfig", diff --git a/passbook/stages/login/api.py b/passbook/stages/login/api.py deleted file mode 100644 index eb28d9042..000000000 --- a/passbook/stages/login/api.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Login Stage API Views""" -from rest_framework.serializers import ModelSerializer -from rest_framework.viewsets import ModelViewSet - -from passbook.stages.login.models import LoginStage - - -class LoginStageSerializer(ModelSerializer): - """LoginStage Serializer""" - - class Meta: - - model = LoginStage - fields = [ - "pk", - "name", - ] - - -class LoginStageViewSet(ModelViewSet): - """LoginStage Viewset""" - - queryset = LoginStage.objects.all() - serializer_class = LoginStageSerializer diff --git a/passbook/stages/login/apps.py b/passbook/stages/login/apps.py deleted file mode 100644 index 83ec4e638..000000000 --- a/passbook/stages/login/apps.py +++ /dev/null @@ -1,10 +0,0 @@ -"""passbook login stage app config""" -from django.apps import AppConfig - - -class PassbookStageLoginConfig(AppConfig): - """passbook login stage config""" - - name = "passbook.stages.login" - label = "passbook_stages_login" - verbose_name = "passbook Stages.Login" diff --git a/passbook/stages/login/forms.py b/passbook/stages/login/forms.py deleted file mode 100644 index 5dc8d6ee5..000000000 --- a/passbook/stages/login/forms.py +++ /dev/null @@ -1,16 +0,0 @@ -"""passbook flows login forms""" -from django import forms - -from passbook.stages.login.models import LoginStage - - -class LoginStageForm(forms.ModelForm): - """Form to create/edit LoginStage instances""" - - class Meta: - - model = LoginStage - fields = ["name"] - widgets = { - "name": forms.TextInput(), - } diff --git a/passbook/stages/login/models.py b/passbook/stages/login/models.py deleted file mode 100644 index b48f0566e..000000000 --- a/passbook/stages/login/models.py +++ /dev/null @@ -1,19 +0,0 @@ -"""login stage models""" -from django.utils.translation import gettext_lazy as _ - -from passbook.flows.models import Stage - - -class LoginStage(Stage): - """Login stage, allows a user to identify themselves to authenticate.""" - - type = "passbook.stages.login.stage.LoginStageView" - form = "passbook.stages.login.forms.LoginStageForm" - - def __str__(self): - return f"Login Stage {self.name}" - - class Meta: - - verbose_name = _("Login Stage") - verbose_name_plural = _("Login Stages") diff --git a/passbook/stages/login/__init__.py b/passbook/stages/user_login/__init__.py similarity index 100% rename from passbook/stages/login/__init__.py rename to passbook/stages/user_login/__init__.py diff --git a/passbook/stages/user_login/api.py b/passbook/stages/user_login/api.py new file mode 100644 index 000000000..19188172e --- /dev/null +++ b/passbook/stages/user_login/api.py @@ -0,0 +1,24 @@ +"""Login Stage API Views""" +from rest_framework.serializers import ModelSerializer +from rest_framework.viewsets import ModelViewSet + +from passbook.stages.user_login.models import UserLoginStage + + +class UserLoginStageSerializer(ModelSerializer): + """UserLoginStage Serializer""" + + class Meta: + + model = UserLoginStage + fields = [ + "pk", + "name", + ] + + +class UserLoginStageViewSet(ModelViewSet): + """UserLoginStage Viewset""" + + queryset = UserLoginStage.objects.all() + serializer_class = UserLoginStageSerializer diff --git a/passbook/stages/user_login/apps.py b/passbook/stages/user_login/apps.py new file mode 100644 index 000000000..a032dfd72 --- /dev/null +++ b/passbook/stages/user_login/apps.py @@ -0,0 +1,10 @@ +"""passbook login stage app config""" +from django.apps import AppConfig + + +class PassbookStageUserLoginConfig(AppConfig): + """passbook login stage config""" + + name = "passbook.stages.user_login" + label = "passbook_stages_user_login" + verbose_name = "passbook Stages.User Login" diff --git a/passbook/stages/user_login/forms.py b/passbook/stages/user_login/forms.py new file mode 100644 index 000000000..e5f26fb71 --- /dev/null +++ b/passbook/stages/user_login/forms.py @@ -0,0 +1,16 @@ +"""passbook flows login forms""" +from django import forms + +from passbook.stages.user_login.models import UserLoginStage + + +class UserLoginStageForm(forms.ModelForm): + """Form to create/edit UserLoginStage instances""" + + class Meta: + + model = UserLoginStage + fields = ["name"] + widgets = { + "name": forms.TextInput(), + } diff --git a/passbook/stages/login/migrations/0001_initial.py b/passbook/stages/user_login/migrations/0001_initial.py similarity index 80% rename from passbook/stages/login/migrations/0001_initial.py rename to passbook/stages/user_login/migrations/0001_initial.py index 52e6060d8..5341ba28c 100644 --- a/passbook/stages/login/migrations/0001_initial.py +++ b/passbook/stages/user_login/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.3 on 2020-05-09 20:26 +# Generated by Django 3.0.5 on 2020-05-10 14:03 import django.db.models.deletion from django.db import migrations, models @@ -14,7 +14,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name="LoginStage", + name="UserLoginStage", fields=[ ( "stage_ptr", @@ -29,8 +29,8 @@ class Migration(migrations.Migration): ), ], options={ - "verbose_name": "Login Stage", - "verbose_name_plural": "Login Stages", + "verbose_name": "User Login Stage", + "verbose_name_plural": "User Login Stages", }, bases=("passbook_flows.stage",), ), diff --git a/passbook/stages/login/migrations/__init__.py b/passbook/stages/user_login/migrations/__init__.py similarity index 100% rename from passbook/stages/login/migrations/__init__.py rename to passbook/stages/user_login/migrations/__init__.py diff --git a/passbook/stages/user_login/models.py b/passbook/stages/user_login/models.py new file mode 100644 index 000000000..18a5bf4aa --- /dev/null +++ b/passbook/stages/user_login/models.py @@ -0,0 +1,19 @@ +"""login stage models""" +from django.utils.translation import gettext_lazy as _ + +from passbook.flows.models import Stage + + +class UserLoginStage(Stage): + """Login stage, allows a user to identify themselves to authenticate.""" + + type = "passbook.stages.user_login.stage.UserLoginStageView" + form = "passbook.stages.user_login.forms.UserLoginStageForm" + + def __str__(self): + return f"User Login Stage {self.name}" + + class Meta: + + verbose_name = _("User Login Stage") + verbose_name_plural = _("User Login Stages") diff --git a/passbook/stages/login/stage.py b/passbook/stages/user_login/stage.py similarity index 97% rename from passbook/stages/login/stage.py rename to passbook/stages/user_login/stage.py index 1e43c163f..6b3c85969 100644 --- a/passbook/stages/login/stage.py +++ b/passbook/stages/user_login/stage.py @@ -12,7 +12,7 @@ from passbook.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND LOGGER = get_logger() -class LoginStageView(AuthenticationStage): +class UserLoginStageView(AuthenticationStage): """Finalise Authentication flow by logging the user in""" def get(self, request: HttpRequest) -> HttpResponse: diff --git a/passbook/stages/login/tests.py b/passbook/stages/user_login/tests.py similarity index 94% rename from passbook/stages/login/tests.py rename to passbook/stages/user_login/tests.py index e15078567..93b77f85e 100644 --- a/passbook/stages/login/tests.py +++ b/passbook/stages/user_login/tests.py @@ -6,11 +6,11 @@ from passbook.core.models import User from passbook.flows.models import Flow, FlowDesignation, FlowStageBinding from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan from passbook.flows.views import SESSION_KEY_PLAN -from passbook.stages.login.models import LoginStage from passbook.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND +from passbook.stages.user_login.models import UserLoginStage -class TestLoginStage(TestCase): +class TestUserLoginStage(TestCase): """Login tests""" def setUp(self): @@ -23,7 +23,7 @@ class TestLoginStage(TestCase): slug="test-login", designation=FlowDesignation.AUTHENTICATION, ) - self.stage = LoginStage.objects.create(name="login") + self.stage = UserLoginStage.objects.create(name="login") FlowStageBinding.objects.create(flow=self.flow, stage=self.stage, order=2) def test_valid_password(self):