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.
* Invite teacher endpoints and tests * Merge branch 'development' into invite_teacher * Merge branch 'development' into invite_teacher * Some cleanup * Merge development * igy * isort * Run code check and tests on every push * pair programming * fix basename * can successfully accept invite * house keeping * rename tests * ignore protected access * Tests * Imports * Conflicts * Feedback * Upgrade PP * Removing PR trigger * All branches * Feedback pt.2 * Update docstring format * Feedback again * Feedback part 1 bajillion * Remvove strict check * Black * Rename invitations * Update PP Co-Authored-By: SKairinos <[email protected]>
- Loading branch information
1 parent
552fbfe
commit 9939972
Showing
18 changed files
with
638 additions
and
55 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: Main | ||
|
||
on: | ||
pull_request: | ||
push: | ||
paths-ignore: | ||
- "**/*.md" | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,5 +108,47 @@ | |
"access_code": "ZZ222", | ||
"teacher": 7 | ||
} | ||
}, | ||
{ | ||
"model": "common.schoolteacherinvitation", | ||
"pk": 1, | ||
"fields": { | ||
"token": "pbkdf2_sha256$260000$hbsAadmrRo744BTM6NofUb$ePs/7vi6sSzOPpiWxNhXMZnNnE7aXOpzIhxrAa/rdiU=", | ||
"school": 2, | ||
"from_teacher": 7, | ||
"invited_teacher_first_name": "Invited", | ||
"invited_teacher_last_name": "Teacher", | ||
"invited_teacher_email": "[email protected]", | ||
"invited_teacher_is_admin": false, | ||
"expiry": "2024-02-09 20:26:08.298402+00:00" | ||
} | ||
}, | ||
{ | ||
"model": "common.schoolteacherinvitation", | ||
"pk": 2, | ||
"fields": { | ||
"token": "pbkdf2_sha256$260000$hbsAadmrRo744BTM6NofUb$ePs/7vi6sSzOPpiWxNhXMZnNnE7aXOpzIhxrAa/rdiU=", | ||
"school": 2, | ||
"from_teacher": 7, | ||
"invited_teacher_first_name": "Invited", | ||
"invited_teacher_last_name": "Teacher", | ||
"invited_teacher_email": "[email protected]", | ||
"invited_teacher_is_admin": false, | ||
"expiry": "9999-02-09 20:26:08.298402+00:00" | ||
} | ||
}, | ||
{ | ||
"model": "common.schoolteacherinvitation", | ||
"pk": 3, | ||
"fields": { | ||
"token": "pbkdf2_sha256$260000$hbsAadmrRo744BTM6NofUb$ePs/7vi6sSzOPpiWxNhXMZnNnE7aXOpzIhxrAa/rdiU=", | ||
"school": 2, | ||
"from_teacher": 7, | ||
"invited_teacher_first_name": "Invited", | ||
"invited_teacher_last_name": "Teacher", | ||
"invited_teacher_email": "[email protected]", | ||
"invited_teacher_is_admin": false, | ||
"expiry": "9999-02-09 20:26:08.298402+00:00" | ||
} | ||
} | ||
] | ||
] |
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 06/02/2024 at 15:13:00(+00:00). | ||
""" | ||
|
||
from common.models import SchoolTeacherInvitation |
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,57 @@ | ||
""" | ||
© Ocado Group | ||
Created on 09/02/2024 at 16:14:00(+00:00). | ||
""" | ||
|
||
from datetime import timedelta | ||
|
||
from codeforlife.serializers import ModelSerializer | ||
from django.contrib.auth.hashers import make_password | ||
from django.utils import timezone | ||
from django.utils.crypto import get_random_string | ||
from rest_framework import serializers | ||
|
||
from ..models import SchoolTeacherInvitation | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring,too-many-ancestors | ||
class SchoolTeacherInvitationSerializer( | ||
ModelSerializer[SchoolTeacherInvitation] | ||
): | ||
first_name = serializers.CharField(source="invited_teacher_first_name") | ||
last_name = serializers.CharField(source="invited_teacher_last_name") | ||
email = serializers.EmailField(source="invited_teacher_email") | ||
is_admin = serializers.BooleanField(source="invited_teacher_is_admin") | ||
|
||
class Meta: | ||
model = SchoolTeacherInvitation | ||
fields = [ | ||
"id", | ||
"first_name", | ||
"last_name", | ||
"email", | ||
"is_admin", | ||
"expiry", | ||
] | ||
extra_kwargs = { | ||
"id": {"read_only": True}, | ||
"expiry": {"read_only": True}, | ||
} | ||
|
||
def create(self, validated_data): | ||
user = self.request_admin_school_teacher_user | ||
|
||
token = get_random_string(length=32) | ||
validated_data["token"] = make_password(token) | ||
validated_data["school"] = user.teacher.school | ||
validated_data["from_teacher"] = user.teacher | ||
validated_data["expiry"] = timezone.now() + timedelta(days=30) | ||
|
||
invitation = super().create(validated_data) | ||
invitation._token = token | ||
return invitation | ||
|
||
def update(self, instance, validated_data): | ||
instance.expiry = timezone.now() + timedelta(days=30) | ||
instance.save() | ||
return instance |
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,22 @@ | ||
""" | ||
© Ocado Group | ||
Created on 09/02/2024 at 17:02:00(+00:00). | ||
All signals for the SchoolTeacherInvitation model. | ||
""" | ||
|
||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
from ..models import SchoolTeacherInvitation | ||
|
||
|
||
# pylint: disable=unused-argument | ||
@receiver(post_save, sender=SchoolTeacherInvitation) | ||
def school_teacher_invitation__post_save( | ||
sender, instance: SchoolTeacherInvitation, *args, **kwargs | ||
): | ||
"""Send invitation email to invited teacher.""" | ||
|
||
instance._token # TODO: send email to invited teacher with differing | ||
# content based on whether the email is already linked to an account or not. |
Oops, something went wrong.