Skip to content

Commit

Permalink
house keeping
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Jan 22, 2024
1 parent 6462733 commit 0602d6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 9 additions & 4 deletions backend/api/signals/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

from codeforlife.models.signals.pre_save import previous_values_are_unequal
from codeforlife.user.models import User
from django.db.models.signals import pre_save
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver

# pylint: disable=unused-argument


@receiver(pre_save, sender=User)
def user__pre_save(sender, instance: User, *args, **kwargs):
"""User's pre-save logic."""
def user__pre_save__email(sender, instance: User, *args, **kwargs):
"""Before a user's email field is updated."""

if previous_values_are_unequal(instance, {"email"}):
instance.username = instance.email

# TODO: send verification email

@receiver(post_save, sender=User)
def user__post_save__email(sender, instance: User, *args, **kwargs):
"""After a user's email field is updated."""

# TODO: send verification email
7 changes: 6 additions & 1 deletion backend/api/tests/signals/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ def test_pre_save__email(self):
user.save()
assert user.username == email

# TODO: assert verification email is sent.
def test_post_save__email(self):
"""
Updating the email field sends a verification email.
"""

raise NotImplementedError() # TODO

0 comments on commit 0602d6b

Please sign in to comment.