8000 Dispatch signal before user's private data is removed · codingjoe/django-mail-auth@d582eee · GitHub
[go: up one dir, main page]

Skip to content

Commit d582eee

Browse files
committed
Dispatch signal before user's private data is removed
1 parent adec311 commit d582eee

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

mailauth/contrib/user/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ def anonymize(self, commit=True):
113113
if commit:
114114
self.save()
115115
"""
116+
signals.anonymize.send(
117+
sender=self.__class__, instance=self
118+
)
116119
self.email = None
117120
self.first_name = ""
118121
self.last_name = ""
119122
update_fields = ["email", "first_name", "last_name"]
120123
if commit:
121124
self.save(update_fields=update_fields)
122-
signals.anonymize.send(
123-
sender=self.__class__, instance=self, update_fields=tuple(update_fields)
124-
)
125125
return update_fields
126126

127127

mailauth/contrib/user/signals.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"""
55
Signal that is emitted when a user and all their data should be anonymized.
66
7+
The signal is emitted before the private date is delete on the instance,
8+
thus the receiver can still access the data. The receiver should usually
9+
not alter the instance, but only later related data. We recommend overriding
10+
the anonymize method to modify the instance.
11+
712
Usage::
813
914
from django.dispatch import receiver
@@ -12,7 +17,7 @@
1217
1318
1419
@receiver(anonymize, sender=EmailUser)
15-
def anonymize_user(sender, instance, update_fields, **kwargs):
20+
def anonymize_user(sender, instance, **kwargs):
1621
# Do something with related user data
1722
instance.related_model.delete()
1823

0 commit comments

Comments
 (0)
0