Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cc207b4

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

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

‎mailauth/contrib/user/models.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,13 @@ def anonymize(self, commit=True):
113113
if commit:
114114
self.save()
115115
"""
116+
signals.anonymize.send(sender=self.__class__, instance=self)
116117
self.email = None
117118
self.first_name = ""
118119
self.last_name = ""
119120
update_fields = ["email", "first_name", "last_name"]
120121
if commit:
121122
self.save(update_fields=update_fields)
122-
signals.anonymize.send(
123-
sender=self.__class__, instance=self, update_fields=tuple(update_fields)
124-
)
125123
return update_fields
126124

127125

‎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

‎tests/contrib/auth/test_signals.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ def test_anonymize(user):
1616
signal=anonymize,
1717
sender=user.__class__,
1818
instance=user,
19-
update_fields=("email", "first_name", "last_name"),
2019
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /