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

fix: Portal frontend 50 #132

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions codeforlife/user/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,10 @@
# pylint: disable-next=import-outside-toplevel
from .student import Student

# pylint: disable-next=protected-access
# pylint: disable=protected-access
password = StudentUser._get_random_password()
login_id, hashed_login_id = StudentUser._get_random_login_id()

Check warning on line 439 in codeforlife/user/models/user.py

View check run for this annotation

Codecov / codecov/patch

codeforlife/user/models/user.py#L439

Added line #L439 was not covered by tests
# pylint: enable=protected-access

user = super().create_user(
**extra_fields,
Expand All @@ -444,17 +446,18 @@
password=password,
)

# pylint: disable-next=protected-access
user._password = password

Student.objects.create(
class_field=klass,
user=UserProfile.objects.create(user=user),
new_user=user,
# pylint: disable-next=protected-access
login_id=StudentUser._get_random_login_id(),
login_id=hashed_login_id,
)

# pylint: disable=protected-access
user._password = password
user._login_id = login_id

Check warning on line 458 in codeforlife/user/models/user.py

View check run for this annotation

Codecov / codecov/patch

codeforlife/user/models/user.py#L457-L458

Added lines #L457 - L458 were not covered by tests
# pylint: enable=protected-access

# TODO: delete this in new data schema
TotalActivity.objects.update(
student_registrations=F("student_registrations") + 1
Expand All @@ -477,6 +480,9 @@
class StudentUser(User):
"""A user that is a student."""

# TODO: move this is to Student model in new schema.
_login_id: t.Optional[str]

teacher: None
student: "Student"

Expand All @@ -497,22 +503,25 @@
@staticmethod
def _get_random_login_id():
# pylint: disable-next=import-outside-toplevel
from .student import Student
# from .student import Student

login_id = None
while (
login_id is None
or Student.objects.filter(login_id=login_id).exists()
):
login_id = get_random_string(length=64)
# login_id = None
# while (
# login_id is None
# or Student.objects.filter(login_id=login_id).exists()
# ):
# login_id = get_random_string(length=64)

return login_id
# TODO: replace below code with commented out code above.
# pylint: disable-next=import-outside-toplevel
from common.helpers.generators import generate_login_id

Check warning on line 517 in codeforlife/user/models/user.py

View check run for this annotation

Codecov / codecov/patch

codeforlife/user/models/user.py#L517

Added line #L517 was not covered by tests

return generate_login_id()

Check warning on line 519 in codeforlife/user/models/user.py

View check run for this annotation

Codecov / codecov/patch

codeforlife/user/models/user.py#L519

Added line #L519 was not covered by tests

@staticmethod
def get_random_username():
"""Generate a random username that is unique."""
username = None

while (
username is None or User.objects.filter(username=username).exists()
):
Expand All @@ -523,7 +532,7 @@
# pylint: disable-next=arguments-differ
def set_password(self, raw_password: t.Optional[str] = None):
super().set_password(raw_password or self._get_random_password())
self.student.login_id = self._get_random_login_id()
self._login_id, self.student.login_id = self._get_random_login_id()

Check warning on line 535 in codeforlife/user/models/user.py

View check run for this annotation

Codecov / codecov/patch

codeforlife/user/models/user.py#L535

Added line #L535 was not covered by tests


# pylint: disable-next=missing-class-docstring,too-few-public-methods
Expand Down