-
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.
* add foreign key id fields * add permissions * support checking admin teachers * replace permissions * remove unused requirements and fix test discovery * fix unit tests * add module docstrings * pylint disable * create unit tests * feedback
- Loading branch information
Showing
39 changed files
with
783 additions
and
990 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,7 @@ | ||
""" | ||
© Ocado Group | ||
Created on 14/12/2023 at 14:04:57(+00:00). | ||
""" | ||
|
||
from .is_cron_request_from_google import IsCronRequestFromGoogle | ||
from .is_self import IsSelf |
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,26 @@ | ||
""" | ||
© Ocado Group | ||
Created on 12/12/2023 at 15:08:08(+00:00). | ||
""" | ||
|
||
from rest_framework.permissions import BasePermission | ||
from rest_framework.request import Request | ||
from rest_framework.views import APIView | ||
|
||
|
||
class IsSelf(BasePermission): | ||
"""Request's user must be the selected user.""" | ||
|
||
def __init__(self, keyword: str = "pk"): | ||
"""Initialize permission. | ||
Args: | ||
keyword: The key for the url kwargs that contains the user's primary | ||
key. | ||
""" | ||
|
||
super().__init__() | ||
self.keyword = keyword | ||
|
||
def has_permission(self, request: Request, view: APIView): | ||
return request.user.pk == view.kwargs[self.keyword] |
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 |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import typing as t | ||
|
||
from django.contrib.auth.backends import BaseBackend | ||
from django.http.request import HttpRequest | ||
|
||
from ....request import WSGIRequest | ||
from ...models import User | ||
|
||
|
||
class EmailAndPasswordBackend(BaseBackend): | ||
"""Authenticates if the password belongs to the anon user's email.""" | ||
|
||
def authenticate( | ||
self, | ||
request: WSGIRequest, | ||
request: t.Optional[HttpRequest], | ||
email: t.Optional[str] = None, | ||
password: t.Optional[str] = None, | ||
**kwargs | ||
): | ||
if email is None or password is None: | ||
return | ||
return None | ||
|
||
try: | ||
user = User.objects.get(email=email) | ||
if user.check_password(password): | ||
return user | ||
except User.DoesNotExist: | ||
return | ||
return None | ||
|
||
return None | ||
|
||
def get_user(self, user_id: int): | ||
try: | ||
return User.objects.get(id=user_id) | ||
except User.DoesNotExist: | ||
return | ||
return None |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ | |
"pk": 1, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "John", | ||
"last_name": "Doe", | ||
"email": "[email protected]", | ||
"password": "password", | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=", | ||
"teacher": 1 | ||
} | ||
}, | ||
|
@@ -16,10 +17,11 @@ | |
"pk": 2, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "Jane", | ||
"last_name": "Doe", | ||
"email": "[email protected]", | ||
"password": "password", | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=", | ||
"teacher": 2 | ||
} | ||
}, | ||
|
@@ -28,8 +30,9 @@ | |
"pk": 3, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "SpongeBob", | ||
"password": "password", | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=", | ||
"student": 1 | ||
} | ||
}, | ||
|
@@ -38,8 +41,9 @@ | |
"pk": 4, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "Patrick", | ||
"password": "password", | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=", | ||
"student": 2 | ||
} | ||
}, | ||
|
@@ -48,10 +52,11 @@ | |
"pk": 5, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "Indiana", | ||
"last_name": "Jones", | ||
"email": "[email protected]", | ||
"password": "password" | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=" | ||
} | ||
} | ||
] |
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
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
Oops, something went wrong.