Skip to content

Commit

Permalink
fix: add new props for new user
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Feb 5, 2024
1 parent 8afb1bb commit e665c90
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions codeforlife/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
from rest_framework.serializers import BaseSerializer as _BaseSerializer

from ..request import Request
from ..user.models import User
from ..user.models import ( # TODO: add IndependentUser
NonSchoolTeacherUser,
SchoolTeacherUser,
StudentUser,
TeacherUser,
User,
)


# pylint: disable-next=abstract-method
Expand All @@ -28,15 +34,63 @@ def request(self):
@property
def request_user(self):
"""
The user that made the request. Assumes the user has authenticated.
The user that made the request.
Assumes the user has authenticated.
"""

return t.cast(User, self.request.user)

@property
def request_teacher_user(self):
"""
The teacher-user that made the request.
Assumes the user has authenticated.
"""

return t.cast(TeacherUser, self.request.user)

@property
def request_school_teacher_user(self):
"""
The school-teacher-user that made the request.
Assumes the user has authenticated.
"""

return t.cast(SchoolTeacherUser, self.request.user)

@property
def request_non_school_teacher_user(self):
"""
The non-school-teacher-user that made the request.
Assumes the user has authenticated.
"""

return t.cast(NonSchoolTeacherUser, self.request.user)

@property
def request_student_user(self):
"""
The student-user that made the request.
Assumes the user has authenticated.
"""

return t.cast(StudentUser, self.request.user)

# TODO: uncomment when moving to new data models.
# @property
# def request_indy_user(self):
# """
# The independent-user that made the request.
# Assumes the user has authenticated.
# """

# return t.cast(IndependentUser, self.request.user)

@property
def request_anon_user(self):
"""
The user that made the request. Assumes the user has not authenticated.
The user that made the request.
Assumes the user has not authenticated.
"""

return t.cast(AnonymousUser, self.request.user)
Expand Down

0 comments on commit e665c90

Please sign in to comment.