Skip to content

: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.

fix(slack-app): match user email case-insensitively (#62153)

Vojta Bartošaf3fa595e8c7
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.py
index e759f042df7d..728940a41bd7 100644
--- a/products/slack_app/backend/api.py
+++ b/products/slack_app/backend/api.py
@@ -450,7 +450,7 @@ def resolve_slack_user(
# membership
membership = (
OrganizationMembership.objects.filter(
- organization_id=integration.team.organization_id, user__email=slack_email
+ organization_id=integration.team.organization_id, user__email__iexact=slack_email
)
.select_related("user")
.first()
@@ -1422,7 +1422,7 @@ def _resolve_posthog_user_from_event(
if not org_ids:
return None
membership = (
- OrganizationMembership.objects.filter(organization_id__in=org_ids, user__email=slack_email)
+ OrganizationMembership.objects.filter(organization_id__in=org_ids, user__email__iexact=slack_email)
.select_related("user")
.first()
)
diff --git a/products/slack_app/backend/tests/test_resolve_slack_user.py b/products/slack_app/backend/tests/test_resolve_slack_user.py
index 42ba2dfbc40e..3650899b3011 100644
--- a/products/slack_app/backend/tests/test_resolve_slack_user.py
+++ b/products/slack_app/backend/tests/test_resolve_slack_user.py
@@ -42,6 +42,27 @@ class TestResolveSlackUser:
assert result.user.email == "[email protected]"
assert result.slack_email == "[email protected]"
+ @pytest.mark.parametrize(
+ "slack_email",
+ [
+ pytest.param("[email protected]", id="uppercase_local_part"),
+ pytest.param("[email protected]", id="mixed_case_domain"),
+ pytest.param("[email protected]", id="all_uppercase"),
+ ],
+ )
+ @patch("posthog.models.integration.WebClient")
+ def test_matches_email_case_insensitively(self, mock_webclient_class, slack_email):
+ mock_client = MagicMock()
+ mock_webclient_class.return_value = mock_client
+ mock_client.users_info.return_value = {"user": {"profile": {"email": slack_email}}}
+
+ slack = SlackIntegration(self.integration)
+ result = resolve_slack_user(slack, self.integration, "U123", "C001", "1234.5678")
+
+ assert result is not None
+ assert result.user.email == "[email protected]"
+ assert result.slack_email == slack_email
+
@patch("posthog.models.integration.WebClient")
def test_missing_email(self, mock_webclient_class):
mock_client = MagicMock()