Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions testproject/tests/test_add_mfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser

from flaky import flaky
from rest_framework.status import HTTP_200_OK, HTTP_400_BAD_REQUEST
Expand All @@ -12,7 +11,7 @@
from trench.command.create_secret import create_secret_command


User: AbstractUser = get_user_model()
User = get_user_model()


@pytest.mark.django_db
Expand Down
3 changes: 1 addition & 2 deletions trench/backends/application.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser

import logging

Expand All @@ -12,7 +11,7 @@
from trench.settings import trench_settings


User: AbstractUser = get_user_model()
User = get_user_model()


class ApplicationMessageDispatcher(AbstractMessageDispatcher):
Expand Down
3 changes: 1 addition & 2 deletions trench/command/authenticate_second_factor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser

from typing import Type

Expand All @@ -11,7 +10,7 @@
from trench.utils import get_mfa_model, user_token_generator


User: AbstractUser = get_user_model()
User = get_user_model()


class AuthenticateSecondFactorCommand:
Expand Down
2 changes: 1 addition & 1 deletion trench/command/authenticate_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from trench.exceptions import UnauthenticatedError


User: AbstractUser = get_user_model()
User = get_user_model()


class AuthenticateUserCommand:
Expand Down
6 changes: 3 additions & 3 deletions trench/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DispatchResponse(Response):

class SuccessfulDispatchResponse(DispatchResponse):
def __init__(
self, details: str, status: str = HTTP_200_OK, *args, **kwargs
self, details: str, status: int = HTTP_200_OK, *args, **kwargs
) -> None:
super().__init__(
data={self._FIELD_DETAILS: details}, status=status, *args, **kwargs
Expand All @@ -23,7 +23,7 @@ def __init__(

class FailedDispatchResponse(DispatchResponse):
def __init__(
self, details: str, status: str = HTTP_422_UNPROCESSABLE_ENTITY, *args, **kwargs
self, details: str, status: int = HTTP_422_UNPROCESSABLE_ENTITY, *args, **kwargs
) -> None:
super().__init__(
data={self._FIELD_DETAILS: details}, status=status, *args, **kwargs
Expand All @@ -36,7 +36,7 @@ class ErrorResponse(Response):
def __init__(
self,
error: MFAValidationError,
status: str = HTTP_400_BAD_REQUEST,
status: int = HTTP_400_BAD_REQUEST,
*args,
**kwargs
) -> None:
Expand Down
3 changes: 1 addition & 2 deletions trench/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser
from django.db.models import Model

from abc import abstractmethod
Expand All @@ -23,7 +22,7 @@
from trench.utils import available_method_choices, get_mfa_model


User: AbstractUser = get_user_model()
User = get_user_model()


class RequestBodyValidator(Serializer):
Expand Down
3 changes: 1 addition & 2 deletions trench/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.apps import apps
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils.crypto import constant_time_compare, salted_hmac
from django.utils.http import base36_to_int, int_to_base36
Expand All @@ -14,7 +13,7 @@
from trench.settings import VERBOSE_NAME, trench_settings


User: AbstractUser = get_user_model()
User = get_user_model()


class UserTokenGenerator(PasswordResetTokenGenerator):
Expand Down
12 changes: 4 additions & 8 deletions trench/views/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser
from django.db.models import QuerySet
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -47,7 +46,7 @@
from trench.utils import available_method_choices, get_mfa_model, user_token_generator


User: AbstractUser = get_user_model()
User = get_user_model()


class MFAStepMixin(APIView, ABC):
Expand Down Expand Up @@ -132,8 +131,7 @@ def post(request: Request, method: str) -> Response:
serializer = MFAMethodActivationConfirmationValidator(
mfa_method_name=method, user=request.user, data=request.data
)
if not serializer.is_valid():
return Response(status=HTTP_400_BAD_REQUEST, data=serializer.errors)
serializer.is_valid(raise_exception=True)
try:
backup_codes = activate_mfa_method_command(
user_id=request.user.id,
Expand All @@ -153,8 +151,7 @@ def post(request: Request, method: str) -> Response:
serializer = MFAMethodDeactivationValidator(
mfa_method_name=method, user=request.user, data=request.data
)
if not serializer.is_valid():
return Response(status=HTTP_400_BAD_REQUEST, data=serializer.errors)
serializer.is_valid(raise_exception=True)
try:
deactivate_mfa_method_command(
mfa_method_name=method, user_id=request.user.id
Expand All @@ -174,8 +171,7 @@ def post(request: Request, method: str) -> Response:
serializer = MFAMethodBackupCodesGenerationValidator(
mfa_method_name=method, user=request.user, data=request.data
)
if not serializer.is_valid():
return Response(status=HTTP_400_BAD_REQUEST, data=serializer.errors)
serializer.is_valid(raise_exception=True)
try:
backup_codes = regenerate_backup_codes_for_mfa_method_command(
user_id=request.user.id,
Expand Down