:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(onboarding): disambiguate welcome inviter sharing invitee name (#129820)
Rafael Audibertcb939bbce624
diff --git a/posthog/api/test/test_welcome.py b/posthog/api/test/test_welcome.pyindex a7d3e9d40b95..6987668b6496 100644--- a/posthog/api/test/test_welcome.py+++ b/posthog/api/test/test_welcome.py@@ -3,6 +3,7 @@ from posthog.test.base import APIBaseTestfrom django.core.cache import cachefrom django.utils import timezone+from parameterized import parameterizedfrom rest_framework import statusfrom posthog.models import Organization, User@@ -39,17 +40,31 @@ class TestWelcomeEndpoint(APIBaseTest):# Always falls back to at least one suggested step.self.assertGreaterEqual(len(data["suggested_next_steps"]), 1)- def test_inviter_returned_from_invited_by_on_membership(self):- """Primary inviter path: persisted on the membership when the invite was accepted."""- founder = User.objects.create_and_join(self.organization, "[email protected]", None, "Founder")+ @parameterized.expand(+ [+ ("different_first_name", "Founder", "", "Alex", "", "Founder"),+ ("no_first_name_uses_email_local_part", "", "", "Alex", "", "founder"),+ ("same_first_name_uses_full_name", "Alex", "Lee", "alex", "Kim", "Alex Lee"),+ ("same_full_name_uses_email", "Alex", "Lee", "Alex", "Lee", "[email protected]"),+ ("same_first_name_no_last_name_uses_email", "Alex", "", "Alex", "", "[email protected]"),+ ]+ )+ def test_inviter_returned_from_invited_by_on_membership(+ self, _name, inviter_first, inviter_last, invitee_first, invitee_last, expected_name+ ):+ founder = User.objects.create_and_join(+ self.organization, "[email protected]", None, inviter_first, last_name=inviter_last+ )+ self.user.first_name = invitee_first+ self.user.last_name = invitee_last+ self.user.save(update_fields=["first_name", "last_name"])membership = OrganizationMembership.objects.get(user=self.user, organization=self.organization)membership.invited_by = foundermembership.save(update_fields=["invited_by"])response = self.client.get("/api/organizations/@current/welcome/current/")data = response.json()- self.assertIsNotNone(data["inviter"])- self.assertEqual(data["inviter"]["email"], founder.email)+ self.assertEqual(data["inviter"], {"name": expected_name, "email": founder.email})def test_inviter_falls_back_to_lingering_invite_row(self):"""Fallback for pre-1102 memberships or legacy paths that didn't populate invited_by."""diff --git a/posthog/api/welcome.py b/posthog/api/welcome.pyindex 4daf448893dc..f4bc74ae7c84 100644--- a/posthog/api/welcome.py+++ b/posthog/api/welcome.py@@ -351,11 +351,24 @@ def _get_inviter(user: User, organization: Organization) -> dict[str, str] | Nonif inviter is None:return Nonereturn {- "name": inviter.first_name or (inviter.email.split("@", 1)[0] if inviter.email else "A teammate"),+ "name": _inviter_display_name(inviter, user),"email": inviter.email,}+def _inviter_display_name(inviter: User, invitee: User) -> str:+ name = inviter.first_name or (inviter.email.split("@", 1)[0] if inviter.email else "A teammate")+ if not invitee.first_name or name.strip().casefold() != invitee.first_name.strip().casefold():+ return name+ # The dialog reads "<inviter> invited you. Welcome, <invitee>!", so a shared first name looks+ # like the user invited themselves. Widen to the full name, or the email when that collides too.+ full_name = f"{inviter.first_name} {inviter.last_name}".strip()+ invitee_full_name = f"{invitee.first_name} {invitee.last_name}".strip()+ if inviter.last_name and full_name.casefold() != invitee_full_name.casefold():+ return full_name+ return inviter.email or name++def _get_team_members(organization: Organization) -> list[dict[str, Any]]:now = timezone.now()today_threshold = now - timedelta(hours=24)