Skip to content

Commit

Permalink
Unlink anonymized user from siaes
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilouf committed Dec 26, 2024
1 parent 16e9e32 commit b1e8915
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lemarche/users/management/commands/anonymize_old_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils import timezone

from lemarche.conversations.models import TemplateTransactional
from lemarche.siaes.models import SiaeUser
from lemarche.users.models import User


Expand Down Expand Up @@ -75,6 +76,8 @@ def anonymize_old_users(self, expiry_date: timezone.datetime, dry_run: bool):
# Random string is to avoid chances of impersonation by admins https://code.djangoproject.com/ticket/20079
password=Concat(Value(UNUSABLE_PASSWORD_PREFIX), RandomUUID()),
)
# remove anonymized users in Siaes
SiaeUser.objects.filter(user__is_anonymized=True).delete()

self.stdout.write(f"Utilisateurs anonymisés avec succès ({users_to_update_count} traités)")

Expand Down
6 changes: 6 additions & 0 deletions lemarche/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ def setUp(self):

self.std_out = StringIO() # to read output from executed management commands

siae_1 = SiaeFactory()
siae_2 = SiaeFactory()

UserFactory(first_name="active_user", last_login=frozen_now)
UserFactory(
last_login=self.frozen_last_year,
Expand All @@ -196,6 +199,7 @@ def setUp(self):
phone="06 15 15 15 15",
api_key="123456789",
api_key_last_updated=frozen_now,
siaes=[siae_1],
)
UserFactory(
last_login=self.frozen_last_year,
Expand All @@ -206,6 +210,7 @@ def setUp(self):
phone="06 15 15 15 15",
api_key="0000000000",
api_key_last_updated=frozen_now,
siaes=[siae_1, siae_2],
)
UserFactory(
last_login=self.frozen_warning_date,
Expand Down Expand Up @@ -252,6 +257,7 @@ def test_anonymize_command(self):
self.assertFalse(anonymized_user.first_name)
self.assertFalse(anonymized_user.last_name)
self.assertFalse(anonymized_user.phone)
self.assertFalse(anonymized_user.siaes.all())

self.assertIsNone(anonymized_user.api_key)
self.assertIsNone(anonymized_user.api_key_last_updated)
Expand Down

0 comments on commit b1e8915

Please sign in to comment.