Repository: liberapay/liberapay.com

Issue:
Notify users who need to fill in their identity
Users with incoming donations that can't be carried out because they haven't filled the identity form.



Discussion:

Resolving patch:
diff --git a/liberapay/billing/payday.py b/liberapay/billing/payday.py
--- a/liberapay/billing/payday.py
+++ b/liberapay/billing/payday.py
@@ -544,6 +544,24 @@ def notify_participants(self):
                 by_team=by_team,
             )
 
+        # Identity-required notifications
+        participants = self.db.all("""
+            SELECT p.*::participants
+              FROM participants p
+             WHERE mangopay_user_id IS NULL
+               AND (p.goal IS NULL OR p.goal >= 0)
+               AND EXISTS (
+                     SELECT 1
+                       FROM current_tips t
+                       JOIN participants p2 ON p2.id = t.tipper
+                      WHERE t.tippee = p.id
+                        AND t.amount > 0
+                        AND p2.balance > t.amount
+                   )
+        """)
+        for p in participants:
+            p.notify('identity_required', force_email=True)
+
         # Low-balance notifications
         participants = self.db.all("""
             SELECT p.*::participants
diff --git a/liberapay/models/participant.py b/liberapay/models/participant.py
--- a/liberapay/models/participant.py
+++ b/liberapay/models/participant.py
@@ -726,10 +726,10 @@ def set_email_lang(self, accept_lang):
     # Notifications
     # =============
 
-    def notify(self, event, web=True, **context):
+    def notify(self, event, force_email=False, web=True, **context):
         if web:
             self.add_notification(event, **context)
-        if self.email_notif_bits & EVENTS.get(event).bit:
+        if force_email or self.email_notif_bits & EVENTS.get(event).bit:
             self.queue_email(event, **context)
 
     def add_notification(self, event, **context):


Test patch:
diff --git a/tests/py/test_billing_payday.py b/tests/py/test_billing_payday.py
--- a/tests/py/test_billing_payday.py
+++ b/tests/py/test_billing_payday.py
@@ -382,6 +382,10 @@ def test_it_notifies_participants(self):
         team.set_take_for(self.david, D('0.23'), team)
         self.client.POST('/homer/emails/notifications.json', auth_as=self.homer,
                          data={'fields': 'income', 'income': ''}, xhr=True)
+        kalel = self.make_participant(
+            'kalel', mangopay_user_id=None, email='kalel@example.org',
+        )
+        self.janet.set_tip_to(kalel, '0.10')
         Payday.start().run()
         david = self.david.refetch()
         assert david.balance == D('4.73')
@@ -389,9 +393,11 @@ def test_it_notifies_participants(self):
         assert janet.balance == D('1.77')
         assert janet.giving == D('0.23')
         emails = self.get_emails()
-        assert len(emails) == 2
+        assert len(emails) == 3
         assert emails[0]['to'][0]['email'] == self.david.email
         assert '4.73' in emails[0]['subject']
-        assert emails[1]['to'][0]['email'] == self.janet.email
-        assert 'top up' in emails[1]['subject']
-        assert '1.77' in emails[1]['text']
+        assert emails[1]['to'][0]['email'] == kalel.email
+        assert 'identity form' in emails[1]['text']
+        assert emails[2]['to'][0]['email'] == self.janet.email
+        assert 'top up' in emails[2]['subject']
+        assert '1.77' in emails[2]['text']