Skip to content

Commit

Permalink
Merge pull request #285 from Normal-OJ/fix_modify_mail_and_class
Browse files Browse the repository at this point in the history
feat: add force modify mail and add student to courses
  • Loading branch information
Bogay authored Sep 12, 2024
2 parents b82175a + bb7520d commit 2e3c556
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions mongo/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def batch_signup(
except engine.DoesNotExist:
new_user = cls.get_by_email(u['email'])
if force:
new_user.force_update(u)
new_user.force_update(u, course)
registered_users.append(new_user)
if course is not None:
new_student_nicknames = {
Expand All @@ -103,7 +103,7 @@ def batch_signup(
course.update_student_namelist(new_student_nicknames)
return new_users

def force_update(self, new_user: Dict[str, Any]):
def force_update(self, new_user: Dict[str, Any], course: Optional[Course]):
'''
Force update an existent user in batch update procedure
'''
Expand All @@ -113,6 +113,11 @@ def force_update(self, new_user: Dict[str, Any]):
self.update(role=role)
if (password := new_user.get('password')) is not None:
self.change_password(password)
if (email := new_user.get('email')) is not None:
self.update(email=email,
md5=hashlib.md5(email.encode()).hexdigest())
if course is not None:
self.update(add_to_set__courses=course.id)
self.reload()

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added recover.py
Empty file.

0 comments on commit 2e3c556

Please sign in to comment.