[damned-lies] Also clean accounts that never logged in



commit 1a04b85cb344b625db6764b754adffa39c2c82d9
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Jan 8 17:39:04 2022 +0100

    Also clean accounts that never logged in

 people/models.py | 3 ++-
 people/tests.py  | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/people/models.py b/people/models.py
index e814e70a..d72414dc 100644
--- a/people/models.py
+++ b/people/models.py
@@ -73,7 +73,8 @@ class Person(User):
         ).annotate(
             num_states=models.Count('state')
         ).filter(
-            last_login__lt=(timezone.now() - timedelta(days=730))
+            models.Q(last_login__lt=(timezone.now() - timedelta(days=730))) |
+            models.Q(last_login__isnull=True, date_joined__lt=(timezone.now() - timedelta(days=180)))
         ).exclude(
             role__role='coordinator'
         ).exclude(
diff --git a/people/tests.py b/people/tests.py
index 39b205f9..bcf56959 100644
--- a/people/tests.py
+++ b/people/tests.py
@@ -182,8 +182,9 @@ class PeopleTestCase(TestCase):
         p4 = self._create_person(seq='4', last_login=timezone.now() - timedelta(days=800))
         StateTranslating.objects.create(branch=branch, domain=domain, language=lang, person=p4)
         self._create_person(seq='5', last_login=timezone.now() - timedelta(days=800))
-        # Test only p5 should be deleted
-        self.assertEqual(Person.objects.all().count(), 5)
+        self._create_person(seq='6', date_joined=timezone.now() - timedelta(days=200), last_login=None)
+        # Test only p5/p6 should be deleted
+        self.assertEqual(Person.objects.all().count(), 6)
         Person.clean_obsolete_accounts()
         self.assertEqual(Person.objects.all().count(), 4)
         self.assertEqual(set(Person.objects.all()), set([p1, p2, p3, p4]))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]