Browse Source

fix(github-growth): exclude empty owner emails in missing members API (#54593)

Cathy Teng 1 year ago
parent
commit
2e531620d5

+ 1 - 1
src/sentry/api/endpoints/organization_missing_org_members.py

@@ -63,7 +63,7 @@ class OrganizationMissingMembersEndpoint(OrganizationEndpoint):
         # if a member has user_email=None, then they have yet to accept an invite
         org_owners = organization.get_members_with_org_roles(
             roles=[roles.get_top_dog().id]
-        ).exclude(user_email=None)
+        ).exclude(Q(user_email=None) | Q(user_email=""))
 
         def _get_email_domain(email: str) -> str:
             return Address(addr_spec=email).domain

+ 16 - 7
tests/sentry/api/test_organization_missing_members.py

@@ -2,7 +2,6 @@ from datetime import timedelta
 
 from django.utils import timezone
 
-from sentry.models.organizationmember import OrganizationMember
 from sentry.testutils.cases import APITestCase
 from sentry.testutils.silo import region_silo_test
 
@@ -56,9 +55,6 @@ class OrganizationMissingMembersTestCase(APITestCase):
 
     def test_simple__shared_domain(self):
         # only returns users with example.com emails (shared domain)
-        OrganizationMember.objects.filter(
-            organization_id=self.organization.id, role="owner"
-        ).update(user_email="owner@example.com")
 
         response = self.get_success_response(self.organization.slug)
         assert response.data[0]["integration"] == "github"
@@ -114,9 +110,6 @@ class OrganizationMissingMembersTestCase(APITestCase):
             user=user,
             role="owner",
         )
-        OrganizationMember.objects.filter(
-            organization_id=self.organization.id, role="owner", user_id=user.id
-        ).update(user_email="owner@exampletwo.com")
 
         response = self.get_success_response(self.organization.slug)
 
@@ -127,6 +120,22 @@ class OrganizationMissingMembersTestCase(APITestCase):
             {"email": "a@exampletwo.com", "externalId": "not", "commitCount": 1},
         ]
 
+    def test_owners_no_user_email(self):
+        user = self.create_user(email="")
+        self.create_member(
+            organization=self.organization,
+            user=user,
+            role="owner",
+        )
+
+        response = self.get_success_response(self.organization.slug)
+
+        assert response.data[0]["integration"] == "github"
+        assert response.data[0]["users"] == [
+            {"email": "c@example.com", "externalId": "c", "commitCount": 2},
+            {"email": "d@example.com", "externalId": "d", "commitCount": 1},
+        ]
+
     def test_query_on_author_email_and_external_id(self):
         # self.nonmember_commit_author1 matches on email
         # the below matches on external id