generated from ocadotechnology/codeforlife-template-backend
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: otp flow * fix: new cfl package * merge from main * fix: filter auth factors by user * http get * fix: return otp secret * fix: check if exists * quick save * too-many-public-methods * Merge branch 'main' into portal-frontend-70 * Merge branch 'main' into portal-frontend-70 * fix: list filters * simplify query Co-Authored-By: Florian Aucomte <[email protected]>
- Loading branch information
1 parent
d51394c
commit 611cd6e
Showing
8 changed files
with
182 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
© Ocado Group | ||
Created on 20/01/2025 at 16:25:55(+00:00). | ||
""" | ||
|
||
from .auth_factor import AuthFactorFilterSet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
© Ocado Group | ||
Created on 20/01/2025 at 16:26:47(+00:00). | ||
""" | ||
|
||
from codeforlife.filters import FilterSet # isort: skip | ||
from codeforlife.user.models import AuthFactor # isort: skip | ||
from django_filters import ( # type: ignore[import-untyped] # isort: skip | ||
rest_framework as filters, | ||
) | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class AuthFactorFilterSet(FilterSet): | ||
user = filters.NumberFilter("user") | ||
type = filters.ChoiceFilter(choices=AuthFactor.Type.choices) | ||
|
||
class Meta: | ||
model = AuthFactor | ||
fields = ["user", "type"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
© Ocado Group | ||
Created on 20/01/2025 at 18:52:16(+00:00). | ||
""" | ||
|
||
from codeforlife.permissions import IsAuthenticated | ||
from codeforlife.user.models import AuthFactor, User | ||
|
||
|
||
class HasAuthFactor(IsAuthenticated): | ||
"""Request's user must have a auth factor enabled.""" | ||
|
||
def __init__(self, t: AuthFactor.Type): | ||
super().__init__() | ||
|
||
self.t = t | ||
|
||
def __eq__(self, other): | ||
return isinstance(other, self.__class__) and self.t == other.t | ||
|
||
def has_permission(self, request, view): | ||
user = request.user | ||
return ( | ||
super().has_permission(request, view) | ||
and isinstance(user, User) | ||
and user.auth_factors.filter(type=self.t).exists() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters