Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymize user #307

Merged
merged 14 commits into from
Feb 22, 2024
4 changes: 2 additions & 2 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pypi"
# Before adding a new package, check it's not listed under [packages] at
# https://github.com/ocadotechnology/codeforlife-package-python/blob/{ref}/Pipfile
# Replace "{ref}" in the above URL with the ref set below.
codeforlife = {ref = "v0.13.9", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
codeforlife = {ref = "v0.13.10", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
# TODO: check if we need the below packages
whitenoise = "==6.5.0"
django-pipeline = "==2.0.8"
Expand All @@ -34,7 +34,7 @@ google-cloud-container = "==2.3.0"
# Before adding a new package, check it's not listed under [dev-packages] at
# https://github.com/ocadotechnology/codeforlife-package-python/blob/{ref}/Pipfile
# Replace "{ref}" in the above URL with the ref set below.
codeforlife = {ref = "v0.13.9", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
codeforlife = {ref = "v0.13.10", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
# TODO: check if we need the below packages
django-selenium-clean = "==0.3.3"
django-test-migrations = "==1.2.0"
Expand Down
226 changes: 113 additions & 113 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions backend/api/serializers/auth_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Meta:
# pylint: disable-next=missing-function-docstring
def validate_type(self, value: str):
if AuthFactor.objects.filter(
user=self.request_user, type=value
user=self.request.auth_user, type=value
).exists():
raise serializers.ValidationError(
"You already have this authentication factor enabled.",
Expand All @@ -34,7 +34,7 @@ def validate_type(self, value: str):
return value

def create(self, validated_data):
user = self.request_user
user = self.request.auth_user
if not user.userprofile.otp_secret:
user.userprofile.otp_secret = pyotp.random_base32()
user.userprofile.save()
Expand All @@ -51,6 +51,6 @@ def to_representation(self, instance):
):
representation[
"totp_provisioning_uri"
] = self.request_user.totp_provisioning_uri
] = self.request.auth_user.totp_provisioning_uri

return representation
6 changes: 3 additions & 3 deletions backend/api/serializers/klass.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def validate_teacher(self, value: int):
code="does_not_exist",
)

user = self.request_school_teacher_user
user = self.request.school_teacher_user
if not queryset.filter(school=user.teacher.school_id).exists():
raise serializers.ValidationError(
"This teacher is not in your school.",
Expand All @@ -60,7 +60,7 @@ def validate_teacher(self, value: int):
# pylint: disable-next=missing-function-docstring
def validate_name(self, value: str):
if Class.objects.filter(
teacher__school=self.request_school_teacher_user.teacher.school,
teacher__school=self.request.school_teacher_user.teacher.school,
name=value,
).exists():
raise serializers.ValidationError(
Expand Down Expand Up @@ -90,7 +90,7 @@ def create(self, validated_data):
"teacher_id": (
validated_data["teacher"]["id"]
if "teacher" in validated_data
else self.request_school_teacher_user.teacher.id
else self.request.school_teacher_user.teacher.id
),
"classmates_data_viewable": validated_data[
"classmates_data_viewable"
Expand Down
2 changes: 1 addition & 1 deletion backend/api/serializers/school_teacher_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Meta:
}

def create(self, validated_data):
user = self.request_admin_school_teacher_user
user = self.request.admin_school_teacher_user

token = get_random_string(length=32)
validated_data["token"] = make_password(token)
Expand Down
2 changes: 1 addition & 1 deletion backend/api/serializers/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Meta(_StudentSerializer.Meta):
# pylint: disable-next=missing-function-docstring
def validate_klass(self, value: str):
# Only teachers can manage students.
teacher = self.request_school_teacher_user.teacher
teacher = self.request.school_teacher_user.teacher

try:
klass = Class.objects.get(access_code=value)
Expand Down
2 changes: 1 addition & 1 deletion backend/api/serializers/teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Meta(_TeacherSerializer.Meta):
def validate_is_admin(self, value: bool):
instance = t.cast(t.Optional[User], self.parent.instance)
if instance:
user = self.request_school_teacher_user
user = self.request.school_teacher_user
if user.pk == instance.pk:
raise serializers.ValidationError(
"Cannot update own permissions.",
Expand Down
2 changes: 1 addition & 1 deletion backend/api/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def to_representation(self, instance: User):
# Return student's auto-generated password.
if (
representation["student"] is not None
and self.request_user.teacher is not None
and self.request.auth_user.teacher is not None
):
# pylint: disable-next=protected-access
password = instance._password
Expand Down
Loading
Loading