Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions mailauth/contrib/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,13 @@ def anonymize(self, commit=True):
if commit:
self.save()
"""
signals.anonymize.send(sender=self.__class__, instance=self)
self.email = None
self.first_name = ""
self.last_name = ""
update_fields = ["email", "first_name", "last_name"]
if commit:
self.save(update_fields=update_fields)
signals.anonymize.send(
sender=self.__class__, instance=self, update_fields=tuple(update_fields)
)
return update_fields


Expand Down
7 changes: 6 additions & 1 deletion mailauth/contrib/user/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"""
Signal that is emitted when a user and all their data should be anonymized.

The signal is emitted before the private date is delete on the instance,
thus the receiver can still access the data. The receiver should usually
not alter the instance, but only later related data. We recommend overriding
the anonymize method to modify the instance.

Usage::

from django.dispatch import receiver
Expand All @@ -12,7 +17,7 @@


@receiver(anonymize, sender=EmailUser)
def anonymize_user(sender, instance, update_fields, **kwargs):
def anonymize_user(sender, instance, **kwargs):
# Do something with related user data
instance.related_model.delete()

Expand Down
1 change: 0 additions & 1 deletion tests/contrib/auth/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ def test_anonymize(user):
signal=anonymize,
sender=user.__class__,
instance=user,
update_fields=("email", "first_name", "last_name"),
)