✨(backend) support email anonymization on user
Add a new property 'email_anonymized' to the User model, to allow tracking a user's email without any personal data. In fact, we're dealing with professional data, thus it shouldn't be subject to the GDPR, however I prefer taking extra care when working with potentially first and last names.
This commit is contained in:
committed by
aleb_the_flash
parent
a992aa8898
commit
fc232759fb
@@ -163,6 +163,13 @@ class User(AbstractBaseUser, BaseModel, auth_models.PermissionsMixin):
|
|||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def email_anonymized(self):
|
||||||
|
"""Anonymize the email address by replacing the local part with asterisks."""
|
||||||
|
if not self.email:
|
||||||
|
return ""
|
||||||
|
return f"***@{self.email.split('@')[1]}"
|
||||||
|
|
||||||
|
|
||||||
class Resource(BaseModel):
|
class Resource(BaseModel):
|
||||||
"""Model to define access control"""
|
"""Model to define access control"""
|
||||||
|
|||||||
@@ -44,3 +44,12 @@ def test_models_users_send_mail_main_missing():
|
|||||||
user.email_user("my subject", "my message")
|
user.email_user("my subject", "my message")
|
||||||
|
|
||||||
assert str(excinfo.value) == "User has no email address."
|
assert str(excinfo.value) == "User has no email address."
|
||||||
|
|
||||||
|
|
||||||
|
def test_models_users_email_anonymized():
|
||||||
|
"""The user's email should be anonymized if it exists."""
|
||||||
|
user = factories.UserFactory(email="john.doe@world.com")
|
||||||
|
assert user.email_anonymized == "***@world.com"
|
||||||
|
|
||||||
|
user = factories.UserFactory(email=None)
|
||||||
|
assert user.email_anonymized == ""
|
||||||
|
|||||||
Reference in New Issue
Block a user