Repository: liberapay/liberapay.com

Issue:
Patrons page incorrectly claims that I'm not a member of any team
I have been looking at this new feature (#2088) this morning and I've been surprised after activating the functionality to get this display: 
![liberapay-mecenes-equipe-erreur](https://user-images.githubusercontent.com/8705846/145674456-37e84f52-fa97-4e8f-b575-46d95f7272b8.png)

The part which surprised me is the _"Teams -> You are not a member of any team"_, because this account is a member of 3 teams.

Hence, I thought something was broken. After thinking about it, maybe this is because there is currently no donator who have activated the "public" system, then they can't be displayed here. Am I right thinking so @Changaco ? If so, I would suggest the possibility in such a case to have a sentence on the following line: "You're member of X team(s), but there is actually not any donor who is making a **public** donation. When a donor will make its donation to be **public**, then it'll be displayed here.".




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
@@ -1012,7 +1012,7 @@ def generate_income_notifications(self):
             personal, personal_npatrons = by_team.pop(None, nothing)
             teams = p.get_teams()
             team_ids = set(t.id for t in teams) | set(by_team.keys())
-            team_names = {t.id: t.name for t in teams}
+            team_names = {t.id: t.username for t in teams}
             get_username = lambda i: team_names.get(i) or self.db.one(
                 "SELECT username FROM participants WHERE id = %s", (i,)
             )
diff --git a/liberapay/models/participant.py b/liberapay/models/participant.py
--- a/liberapay/models/participant.py
+++ b/liberapay/models/participant.py
@@ -2023,13 +2023,9 @@ def get_teams(self):
         """Return a list of teams this user is a member of.
         """
         return self.db.all("""
-            SELECT take.team AS id, team.username AS name, team.avatar_url
-                 , ( SELECT count(*)
-                       FROM current_takes take2
-                      WHERE take2.team = take.team
-                   ) AS nmembers
+            SELECT team_p
               FROM current_takes take
-              JOIN participants team ON team.id = take.team
+              JOIN participants team_p ON team_p.id = take.team
              WHERE take.member = %s
         """, (self.id,))
 


Test patch:
diff --git a/tests/py/test_donating.py b/tests/py/test_donating.py
--- a/tests/py/test_donating.py
+++ b/tests/py/test_donating.py
@@ -32,3 +32,24 @@ def test_donation_form_v2(self):
         assert tip.amount == USD('1.00')
         assert tip.renewal_mode == 2
         assert tip.visibility == 3
+
+    def test_donation_form_v2_does_not_overwrite_visibility(self):
+        creator = self.make_participant('creator', accepted_currencies=None)
+        self.add_payment_account(creator, 'stripe')
+        donor = self.make_participant('donor')
+        donor.set_tip_to(creator, USD('10.00'), renewal_mode=1, visibility=3)
+        r = self.client.PxST(
+            '/creator/tip',
+            {
+                'currency': 'USD',
+                'selected_amount': '1.00',
+                'renewal_mode': '2',
+            },
+            auth_as=donor,
+        )
+        assert r.code == 302
+        assert r.headers[b'Location'].startswith(b'/donor/giving/')
+        tip = donor.get_tip_to(creator)
+        assert tip.amount == USD('1.00')
+        assert tip.renewal_mode == 2
+        assert tip.visibility == 3
diff --git a/tests/py/test_teams.py b/tests/py/test_teams.py
--- a/tests/py/test_teams.py
+++ b/tests/py/test_teams.py
@@ -20,8 +20,8 @@ def test_member_of(self):
     def test_get_teams_for_member(self):
         b_team = self.make_participant('B-Team', kind='group')
         b_team.add_member(self.bob)
-        actual = self.alice.get_teams().pop().nmembers
-        assert actual == 1
+        actual = self.alice.get_teams()
+        assert actual == [self.a_team]
 
     def test_preclude_adding_stub_participant(self):
         stub_participant = self.make_stub()