From a4c0fb9e75654a3aa68d22e651cf143ba78e309b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 30 Jun 2020 10:42:27 +0200 Subject: [PATCH] otp_time: fix linting --- passbook/stages/otp_static/__init__.py | 0 passbook/stages/otp_static/apps.py | 8 ++++++++ passbook/stages/otp_time/apps.py | 2 ++ passbook/stages/otp_time/forms.py | 4 ++++ passbook/stages/otp_time/models.py | 14 ++++++++------ passbook/stages/otp_time/settings.py | 2 ++ passbook/stages/otp_time/stage.py | 2 +- passbook/stages/otp_time/urls.py | 5 +++-- passbook/stages/otp_time/views.py | 22 +++++++++++++--------- 9 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 passbook/stages/otp_static/__init__.py create mode 100644 passbook/stages/otp_static/apps.py diff --git a/passbook/stages/otp_static/__init__.py b/passbook/stages/otp_static/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/stages/otp_static/apps.py b/passbook/stages/otp_static/apps.py new file mode 100644 index 000000000..fe31c592e --- /dev/null +++ b/passbook/stages/otp_static/apps.py @@ -0,0 +1,8 @@ +from django.apps import AppConfig + + +class PassbookStageOTPStaticConfig(AppConfig): + + name = "passbook.stages.otp_static" + label = "passbook_stages_otp_static" + verbose_name = "passbook OTP.Static" diff --git a/passbook/stages/otp_time/apps.py b/passbook/stages/otp_time/apps.py index 854be8ab8..c4421055d 100644 --- a/passbook/stages/otp_time/apps.py +++ b/passbook/stages/otp_time/apps.py @@ -1,7 +1,9 @@ +"""OTP Time""" from django.apps import AppConfig class PassbookStageOTPTimeConfig(AppConfig): + """OTP time App config""" name = "passbook.stages.otp_time" label = "passbook_stages_otp_time" diff --git a/passbook/stages/otp_time/forms.py b/passbook/stages/otp_time/forms.py index 490ac569f..5f590d773 100644 --- a/passbook/stages/otp_time/forms.py +++ b/passbook/stages/otp_time/forms.py @@ -1,3 +1,4 @@ +"""OTP Time forms""" from django import forms from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ @@ -15,6 +16,7 @@ class PictureWidget(forms.widgets.Widget): class SetupForm(forms.Form): + """Form to setup Time-based OTP""" title = _("Set up OTP") device: Device = None @@ -40,6 +42,8 @@ class SetupForm(forms.Form): class OTPTimeStageForm(forms.ModelForm): + """OTP Time-based Stage setup form""" + class Meta: model = OTPTimeStage diff --git a/passbook/stages/otp_time/models.py b/passbook/stages/otp_time/models.py index 21d85d9ea..5d4c14b16 100644 --- a/passbook/stages/otp_time/models.py +++ b/passbook/stages/otp_time/models.py @@ -1,13 +1,16 @@ +"""OTP Time-based models""" from typing import Optional + from django.db import models +from django.shortcuts import reverse from django.utils.translation import gettext_lazy as _ from passbook.core.types import UIUserSettings -from passbook.flows.models import NotConfiguredAction, Stage -from django.template.context import RequestContext +from passbook.flows.models import Stage class TOTPDigits(models.IntegerChoices): + """OTP Time Digits""" SIX = 6, _("6 digits, widely compatible") EIGHT = 8, _("8 digits, not compatible with apps like Google Authenticator") @@ -21,12 +24,11 @@ class OTPTimeStage(Stage): type = "passbook.stages.otp_time.stage.OTPTimeStageView" form = "passbook.stages.otp_time.forms.OTPTimeStageForm" - @staticmethod - def ui_user_settings(context: RequestContext) -> Optional[UIUserSettings]: + @property + def ui_user_settings(self) -> Optional[UIUserSettings]: return UIUserSettings( name="Time-based OTP", - icon="pficon-locked", - view_name="passbook_stages_otp_time:user-settings", + url=reverse("passbook_stages_otp_time:user-settings"), ) def __str__(self) -> str: diff --git a/passbook/stages/otp_time/settings.py b/passbook/stages/otp_time/settings.py index cf6be3f9b..74f973300 100644 --- a/passbook/stages/otp_time/settings.py +++ b/passbook/stages/otp_time/settings.py @@ -1,3 +1,5 @@ +"""OTP Time""" + INSTALLED_APPS = [ "django_otp.plugins.otp_totp", ] diff --git a/passbook/stages/otp_time/stage.py b/passbook/stages/otp_time/stage.py index 648760eb8..a8bea5fd7 100644 --- a/passbook/stages/otp_time/stage.py +++ b/passbook/stages/otp_time/stage.py @@ -1,6 +1,6 @@ -from typing import Any, Dict from base64 import b32encode from binascii import unhexlify +from typing import Any, Dict from django.contrib import messages from django.http import HttpRequest, HttpResponse diff --git a/passbook/stages/otp_time/urls.py b/passbook/stages/otp_time/urls.py index 2b52a82c4..6aa07bc5a 100644 --- a/passbook/stages/otp_time/urls.py +++ b/passbook/stages/otp_time/urls.py @@ -1,8 +1,9 @@ +"""OTP Time urls""" from django.urls import path -from passbook.stages.otp_time.views import UserSettingsView, DisableView +from passbook.stages.otp_time.views import DisableView, UserSettingsView urlpatterns = [ path("settings", UserSettingsView.as_view(), name="user-settings"), - path("disable", DisableView.as_view(), name="disable") + path("disable", DisableView.as_view(), name="disable"), ] diff --git a/passbook/stages/otp_time/views.py b/passbook/stages/otp_time/views.py index 893d20d6e..f801978c3 100644 --- a/passbook/stages/otp_time/views.py +++ b/passbook/stages/otp_time/views.py @@ -1,15 +1,17 @@ +"""otp time-based view""" +from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpRequest, HttpResponse -from django.views import View -from django.views.generic import FormView, TemplateView -from django_otp.plugins.otp_totp.models import TOTPDevice -from django.contrib import messages -from passbook.audit.models import Event, EventAction from django.shortcuts import redirect +from django.views import View +from django.views.generic import TemplateView +from django_otp.plugins.otp_totp.models import TOTPDevice -from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan -from passbook.flows.views import SESSION_KEY_PLAN -from passbook.stages.otp_time.models import OTPTimeStage +from passbook.audit.models import Event, EventAction + +# from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan +# from passbook.flows.views import SESSION_KEY_PLAN +# from passbook.stages.otp_time.models import OTPTimeStage class UserSettingsView(LoginRequiredMixin, TemplateView): @@ -34,5 +36,7 @@ class DisableView(LoginRequiredMixin, View): totp.delete() messages.success(request, "Successfully disabled Time-based OTP") # Create event with email notification - Event.new(EventAction.CUSTOM, message="User disabled Time-based OTP.").from_http(request) + Event.new( + EventAction.CUSTOM, message="User disabled Time-based OTP." + ).from_http(request) return redirect("passbook_stages_otp:otp-user-settings")