: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
feat(growth): seed a fixed default product set on user/project connections (#70164)
Rafael Audibert38caef0e16e0
diff --git a/frontend/src/layout/panel-layout/ProjectTree/ProjectTree.tsx b/frontend/src/layout/panel-layout/ProjectTree/ProjectTree.tsxindex 90d02fabd38a..6c7f75e4eedb 100644--- a/frontend/src/layout/panel-layout/ProjectTree/ProjectTree.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/ProjectTree.tsx@@ -3,15 +3,7 @@ import { router } from 'kea-router'import posthog from 'posthog-js'import { RefObject, useCallback, useEffect, useRef, useState } from 'react'-import {- IconCheckbox,- IconChevronRight,- IconEllipsis,- IconFolderPlus,- IconPencil,- IconPlusSmall,- IconStar,-} from '@posthog/icons'+import { IconCheckbox, IconChevronRight, IconEllipsis, IconFolderPlus, IconPlusSmall, IconStar } from '@posthog/icons'import { itemSelectModalLogic } from 'lib/components/FileSystem/ItemSelectModal/itemSelectModalLogic'import { dayjs } from 'lib/dayjs'@@ -37,7 +29,6 @@ import { sceneConfigurations } from 'scenes/scenes'import { teamLogic } from 'scenes/teamLogic'import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'-import { customProductsLogic } from '~/layout/panel-layout/ProjectTree/customProductsLogic'import { projectTreeDataLogic } from '~/layout/panel-layout/ProjectTree/projectTreeDataLogic'import { FileSystemEntry, UserProductListReason } from '~/queries/schema/schema-general'import { UserBasicType } from '~/types'@@ -171,9 +162,6 @@ export function ProjectTree({const treeRef = useRef<LemonTreeRef>(null)const { openItemSelectModal } = useActions(itemSelectModalLogic)- const { customProductsLoading } = useValues(customProductsLogic)- const { seed } = useActions(customProductsLogic)-const [shortcutHelperDismissed, setShortcutHelperDismissed] = useLocalStorage<boolean>(SHORTCUT_DISMISSAL_LOCAL_STORAGE_KEY,false@@ -226,28 +214,6 @@ export function ProjectTree({),})}-- // Only nudge users to add tools when they have none. Once the list has anything in it, keep it clean.- if (root === 'custom-products://' && fullFileSystemFiltered.length === 0) {- treeData.push({- id: 'products/custom-products-helper-category',- name: 'Example custom products',- type: 'category',- displayName: (- <div className={cn('border border-primary text-xs mb-2 font-normal rounded-xs p-2 -mx-1')}>- You can display your preferred tools here. You can configure what items show up in here by- clicking on the{' '}- <IconPencil className="size-3 border border-[var(--color-neutral-500)] rounded-xs" /> icon- above. We'll automatically suggest new tools to this list as you use them.- <br />- <br />- <span className="cursor-pointer underline" onClick={seed}>- {customProductsLoading ? 'Adding...' : 'Add recommended tools?'}- </span>- </div>- ),- })- }}useEffect(() => {diff --git a/frontend/src/layout/panel-layout/ProjectTree/customProductsLogic.tsx b/frontend/src/layout/panel-layout/ProjectTree/customProductsLogic.tsxindex c8f623e1173a..b563ed21dc95 100644--- a/frontend/src/layout/panel-layout/ProjectTree/customProductsLogic.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/customProductsLogic.tsx@@ -1,8 +1,6 @@import { kea, path } from 'kea'import { loaders } from 'kea-loaders'-import { lemonToast } from '@posthog/lemon-ui'-import api from 'lib/api'import { getAppContext } from 'lib/utils/getAppContext'@@ -21,16 +19,6 @@ export const customProductsLogic = kea<customProductsLogicType>([return response.results ?? []},- seed: async (): Promise<UserProductListItem[]> => {- const response = await api.userProductList.seed()-- const { results = [] } = response- if (results.length === 0) {- lemonToast.error('No recommended products found')- }-- return results- },},],})),diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex 789114a2da92..ebbc679afc46 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -2571,9 +2571,6 @@ const api = {async list(): Promise<CountedPaginatedResponse<UserProductListItem>> {return await new ApiRequest().userProductList().get()},- async seed(): Promise<CountedPaginatedResponse<UserProductListItem>> {- return await new ApiRequest().userProductList().withAction('seed').create()- },async bulkUpdate(items: { product_path: string; enabled: boolean }[]): Promise<{ results: UserProductListItem[] }> {diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex bb300ddc7f03..4bb22b120021 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -48552,6 +48552,7 @@},"UserProductListReason": {"enum": [+ "default","onboarding","product_intent","used_by_colleagues",diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex 600961f7e5ff..ab0c6f4d797b 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -8158,6 +8158,7 @@ export interface ProductsData {}export enum UserProductListReason {+ DEFAULT = 'default',ONBOARDING = 'onboarding',PRODUCT_INTENT = 'product_intent',USED_BY_COLLEAGUES = 'used_by_colleagues',diff --git a/posthog/api/file_system/test/test_user_product_list.py b/posthog/api/file_system/test/test_user_product_list.pydeleted file mode 100644index f0155c90aef5..000000000000--- a/posthog/api/file_system/test/test_user_product_list.py+++ /dev/null@@ -1,77 +0,0 @@-from posthog.test.base import APIBaseTest--from rest_framework import status--from posthog.models import Team, User-from posthog.models.file_system.user_product_list import UserProductList---class TestUserProductListAPI(APIBaseTest):- def test_seed_creates_products_from_colleagues_and_other_teams(self):- UserProductList.objects.create(- user=self.user,- team=self.team,- product_path="Product analytics",- enabled=True,- reason=UserProductList.Reason.PRODUCT_INTENT,- )-- colleague = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague", allow_sidebar_suggestions=True- )- colleague.join(organization=self.organization)-- UserProductList.objects.create(user=colleague, team=self.team, product_path="Session replay", enabled=True)- UserProductList.objects.create(user=colleague, team=self.team, product_path="Feature flags", enabled=True)-- other_team = Team.objects.create(organization=self.organization, name="Other Team")- UserProductList.objects.create(user=self.user, team=other_team, product_path="Surveys", enabled=True)-- response = self.client.post(f"/api/environments/{self.team.id}/user_product_list/seed/")-- self.assertEqual(response.status_code, status.HTTP_201_CREATED)- data = response.json()- self.assertIsInstance(data, list)-- product_paths = {item["product_path"] for item in data}- self.assertIn("Product analytics", product_paths)- self.assertIn("Session replay", product_paths)- self.assertIn("Feature flags", product_paths)- self.assertIn("Surveys", product_paths)-- data_by_path = {item["product_path"]: item for item in data}- self.assertEqual(data_by_path["Product analytics"]["reason"], UserProductList.Reason.PRODUCT_INTENT)- self.assertEqual(data_by_path["Session replay"]["reason"], UserProductList.Reason.USED_BY_COLLEAGUES)- self.assertEqual(data_by_path["Feature flags"]["reason"], UserProductList.Reason.USED_BY_COLLEAGUES)- self.assertEqual(data_by_path["Surveys"]["reason"], UserProductList.Reason.USED_ON_SEPARATE_TEAM)-- for item in data:- self.assertTrue(item["enabled"])-- def test_seed_only_returns_enabled_products(self):- UserProductList.objects.create(- user=self.user,- team=self.team,- product_path="Product analytics",- enabled=True,- reason=UserProductList.Reason.PRODUCT_INTENT,- )- UserProductList.objects.create(- user=self.user,- team=self.team,- product_path="Feature flags",- enabled=False,- reason=UserProductList.Reason.USED_BY_COLLEAGUES,- )-- response = self.client.post(f"/api/environments/{self.team.id}/user_product_list/seed/")-- self.assertEqual(response.status_code, status.HTTP_201_CREATED)- data = response.json()- product_paths = {item["product_path"] for item in data}-- self.assertIn("Product analytics", product_paths)- self.assertNotIn("Feature flags", product_paths)-- data_by_path = {item["product_path"]: item for item in data}- self.assertEqual(data_by_path["Product analytics"]["reason"], UserProductList.Reason.PRODUCT_INTENT)diff --git a/posthog/api/file_system/user_product_list.py b/posthog/api/file_system/user_product_list.pyindex c73e3a1faa00..69d3491c8b56 100644--- a/posthog/api/file_system/user_product_list.py+++ b/posthog/api/file_system/user_product_list.py@@ -95,18 +95,3 @@ class UserProductListViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):results.append(serializer.data)return Response({"results": results}, status=status.HTTP_200_OK)-- @action(methods=["POST"], detail=False, url_path="seed")- def seed(self, request: Request, *args: Any, **kwargs: Any) -> Response:- """- Sync products from colleagues and other projects to fill the user's product list for this team.- """- user = cast(User, request.user)- team = self.team-- UserProductList.backfill_from_other_teams(user, team)- UserProductList.sync_from_team_colleagues(user, team, count=5)-- # Return all products the user has enabled in this team, not just the ones we created above- serializer = self.get_serializer(self.safely_get_queryset(self.queryset), many=True)- return Response(serializer.data, status=status.HTTP_201_CREATED)diff --git a/posthog/dags/locations/growth.py b/posthog/dags/locations/growth.pyindex 5334d78acb21..0989548ef127 100644--- a/posthog/dags/locations/growth.py+++ b/posthog/dags/locations/growth.py@@ -15,6 +15,8 @@ jobs = [oauth.oauth_clear_expired_oauth_tokens_job,github_sdk_versions.cache_github_sdk_versions_job,user_product_list.populate_user_product_list_job,+ # Kept unscheduled: connection-time default seeding replaced the monthly colleague+ # sync, but the job stays available for manual runs.user_product_list.sync_colleagues_products_monthly_job,user_product_list.sync_cross_sell_products_monthly_job,team_production_event_activation.detect_first_team_production_event_job,@@ -30,7 +32,6 @@ defs = dagster.Definitions(schedules=[oauth.oauth_clear_expired_oauth_tokens_schedule,github_sdk_versions.cache_github_sdk_versions_schedule,- user_product_list.sync_colleagues_products_monthly_schedule,user_product_list.sync_cross_sell_products_monthly_schedule,team_production_event_activation.detect_first_team_production_event_schedule,product_push_campaigns.product_push_campaigns_schedule,diff --git a/posthog/migrations/1256_userproductlist_default_reason.py b/posthog/migrations/1256_userproductlist_default_reason.pynew file mode 100644index 000000000000..b2b15530066e--- /dev/null+++ b/posthog/migrations/1256_userproductlist_default_reason.py@@ -0,0 +1,31 @@+# Generated by Django 5.2.14 on 2026-07-10 20:42++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1255_wizard_runs_rate_limit_and_provisioned_onboarding_reason"),+ ]++ operations = [+ migrations.AlterField(+ model_name="userproductlist",+ name="reason",+ field=models.CharField(+ choices=[+ ("default", "Default"),+ ("onboarding", "Onboarding"),+ ("product_intent", "Product Intent"),+ ("used_by_colleagues", "Used by Colleagues"),+ ("used_similar_products", "Used Similar Products"),+ ("used_on_separate_team", "Used on Separate Team"),+ ("new_product", "New Product"),+ ("sales_led", "Sales Led"),+ ("onboarding_delegated", "Onboarding Delegated"),+ ],+ max_length=32,+ null=True,+ ),+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex f388cda5ad1e..769a17f863de 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1255_wizard_runs_rate_limit_and_provisioned_onboarding_reason+1256_userproductlist_default_reasondiff --git a/posthog/models/__init__.py b/posthog/models/__init__.pyindex 5f1db954e23f..6248a96a2ca5 100644--- a/posthog/models/__init__.py+++ b/posthog/models/__init__.py@@ -32,6 +32,7 @@ from .file_system.folder_context_generation import FileSystemFolderContextGenerafrom .file_system.folder_instructions import FileSystemFolderInstructionsfrom .file_system.file_system_view_log import FileSystemViewLogfrom .file_system.persisted_folder import PersistedFolder+from .file_system.user_product_list import UserProductListfrom .filters import Filter, RetentionFilterfrom .group import Groupfrom .group_usage_metric import GroupUsageMetric@@ -115,6 +116,7 @@ __all__ = ["FileSystemFolderInstructions","FileSystemViewLog","PersistedFolder",+ "UserProductList","Filter","Group","GroupUsageMetric",diff --git a/posthog/models/file_system/test/test_user_product_list.py b/posthog/models/file_system/test/test_user_product_list.pyindex b89c782045d1..97dc82c56b20 100644--- a/posthog/models/file_system/test/test_user_product_list.py+++ b/posthog/models/file_system/test/test_user_product_list.py@@ -3,7 +3,12 @@ from posthog.test.base import BaseTestfrom posthog.schema import ProductItemCategoryfrom posthog.models import User-from posthog.models.file_system.user_product_list import UserProductList, get_user_product_list_count+from posthog.models.file_system.user_product_list import (+ DEFAULT_PRODUCT_PATHS,+ UserProductList,+ add_default_products_for_user,+ get_user_product_list_count,+)from posthog.products import Productsfrom products.growth.backend.cross_sell_candidate_selector import (@@ -20,233 +25,61 @@ def _get_favored_product_paths() -> set[str]:class TestUserProductList(BaseTest):- def test_sync_filters_out_existing_products_with_precomputed_counts(self):- user = User.objects.create_user(- email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True- )- user.join(organization=self.organization)+ def test_default_product_paths_are_valid_products(self):+ valid_paths = set(Products.get_product_paths())+ assert set(DEFAULT_PRODUCT_PATHS) <= valid_paths- UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)- UserProductList.objects.create(user=user, team=self.team, product_path="Feature flags", enabled=True)+ def test_add_default_products_creates_the_default_set(self):+ user = User.objects.create_user(email="[email protected]", password="password", first_name="User")- hardcoded_counts = [- {"product_path": "Product analytics", "colleague_count": 5},- {"product_path": "Session replay", "colleague_count": 4},- {"product_path": "Feature flags", "colleague_count": 3},- {"product_path": "Surveys", "colleague_count": 2},- ]+ created_items = add_default_products_for_user(user, self.team)- created_items = UserProductList.sync_from_team_colleagues(- user=user, team=self.team, count=2, colleague_product_counts=hardcoded_counts- )-- assert len(created_items) == 2- product_paths = {item.product_path for item in created_items}- assert "Product analytics" not in product_paths- assert "Feature flags" not in product_paths- assert "Session replay" in product_paths- assert "Surveys" in product_paths-- all_user_products = UserProductList.objects.filter(user=user, team=self.team, enabled=True)- assert all_user_products.filter(product_path="Session replay").exists()- assert all_user_products.filter(product_path="Surveys").exists()- assert all_user_products.filter(product_path="Product analytics").exists()- assert all_user_products.filter(product_path="Feature flags").exists()-- for item in created_items:- assert item.reason == UserProductList.Reason.USED_BY_COLLEAGUES- assert item.enabled is True+ assert {item.product_path for item in created_items} == set(DEFAULT_PRODUCT_PATHS)- def test_sync_ranks_by_precomputed_counts(self):- user = User.objects.create_user(- email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True- )- user.join(organization=self.organization)+ rows = UserProductList.objects.filter(user=user, team=self.team)+ assert {row.product_path for row in rows} == set(DEFAULT_PRODUCT_PATHS)+ for row in rows:+ assert row.enabled is True+ assert row.reason == UserProductList.Reason.DEFAULT- hardcoded_counts = [- {"product_path": "Product analytics", "colleague_count": 10},- {"product_path": "Session replay", "colleague_count": 8},- {"product_path": "Feature flags", "colleague_count": 5},- {"product_path": "Surveys", "colleague_count": 3},- {"product_path": "Experiments", "colleague_count": 1},- ]+ def test_add_default_products_leaves_existing_rows_untouched(self):+ user = User.objects.create_user(email="[email protected]", password="password", first_name="User")- created_items = UserProductList.sync_from_team_colleagues(- user=user, team=self.team, count=3, colleague_product_counts=hardcoded_counts+ UserProductList.objects.create(+ user=user,+ team=self.team,+ product_path="Product analytics",+ enabled=False,+ reason=UserProductList.Reason.PRODUCT_INTENT,)- assert len(created_items) == 3- product_paths = [item.product_path for item in created_items]- assert set(product_paths) == {"Product analytics", "Session replay", "Feature flags"}- assert product_paths[0] == "Product analytics"- assert product_paths[1] == "Session replay"- assert product_paths[2] == "Feature flags"+ created_items = add_default_products_for_user(user, self.team)- def test_sync_respects_count_limit(self):- user = User.objects.create_user(- email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True- )- user.join(organization=self.organization)+ assert "Product analytics" not in {item.product_path for item in created_items}+ existing = UserProductList.objects.get(user=user, team=self.team, product_path="Product analytics")+ assert existing.enabled is False+ assert existing.reason == UserProductList.Reason.PRODUCT_INTENT- hardcoded_counts = [- {"product_path": "Product analytics", "colleague_count": 10},- {"product_path": "Session replay", "colleague_count": 8},- {"product_path": "Feature flags", "colleague_count": 5},- {"product_path": "Surveys", "colleague_count": 3},- ]+ add_default_products_for_user(user, self.team)+ assert UserProductList.objects.filter(user=user, team=self.team).count() == len(DEFAULT_PRODUCT_PATHS)- created_items = UserProductList.sync_from_team_colleagues(- user=user, team=self.team, count=2, colleague_product_counts=hardcoded_counts- )+ def test_join_seeds_default_products_for_accessible_teams(self):+ # Guards joins that don't go through an invite (e.g. domain/SSO auto-join):+ # seeding must live in User.join itself, not only in the invite flow.+ user = User.objects.create_user(email="[email protected]", password="password", first_name="Joiner")- assert len(created_items) == 2- product_paths = {item.product_path for item in created_items}- assert product_paths == {"Product analytics", "Session replay"}-- def test_sync_respects_allow_sidebar_suggestions_false(self):- user = User.objects.create_user(- email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=False- )user.join(organization=self.organization)- hardcoded_counts = [- {"product_path": "Product analytics", "colleague_count": 10},- {"product_path": "Session replay", "colleague_count": 8},- ]-- created_items = UserProductList.sync_from_team_colleagues(- user=user, team=self.team, colleague_product_counts=hardcoded_counts- )-- assert len(created_items) == 0-- def test_sync_computes_counts_when_not_provided(self):- colleague1 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague1", allow_sidebar_suggestions=True- )- colleague2 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague2", allow_sidebar_suggestions=True- )- user = User.objects.create_user(- email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True- )-- colleague1.join(organization=self.organization)- colleague2.join(organization=self.organization)- user.join(organization=self.organization)-- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Product analytics", enabled=True)- UserProductList.objects.create(user=colleague2, team=self.team, product_path="Product analytics", enabled=True)- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Session replay", enabled=True)-- created_items = UserProductList.sync_from_team_colleagues(user=user, team=self.team, count=2)-- assert len(created_items) == 2- product_paths = {item.product_path for item in created_items}- assert "Product analytics" in product_paths- assert "Session replay" in product_paths-- def test_sync_does_not_duplicate_existing_products(self):- user = User.objects.create_user(- email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True- )- user.join(organization=self.organization)-- UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)-- hardcoded_counts = [- {"product_path": "Product analytics", "colleague_count": 10},- {"product_path": "Session replay", "colleague_count": 8},- ]-- created_items = UserProductList.sync_from_team_colleagues(- user=user, team=self.team, colleague_product_counts=hardcoded_counts- )-- assert len(created_items) == 1- assert created_items[0].product_path == "Session replay"-- all_user_products = UserProductList.objects.filter(user=user, team=self.team, product_path="Product analytics")- assert all_user_products.count() == 1-- def test_get_user_product_list_count(self):- colleague1 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague1", allow_sidebar_suggestions=True- )- colleague2 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague2", allow_sidebar_suggestions=True- )- colleague3 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague3", allow_sidebar_suggestions=True- )- colleague4 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague4", allow_sidebar_suggestions=True- )-- colleague1.join(organization=self.organization)- colleague2.join(organization=self.organization)- colleague3.join(organization=self.organization)- colleague4.join(organization=self.organization)-- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Product analytics", enabled=True)- UserProductList.objects.create(user=colleague2, team=self.team, product_path="Product analytics", enabled=True)- UserProductList.objects.create(user=colleague3, team=self.team, product_path="Product analytics", enabled=True)- UserProductList.objects.create(user=colleague4, team=self.team, product_path="Product analytics", enabled=True)-- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Session replay", enabled=True)- UserProductList.objects.create(user=colleague2, team=self.team, product_path="Session replay", enabled=True)- UserProductList.objects.create(user=colleague3, team=self.team, product_path="Session replay", enabled=True)-- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Feature flags", enabled=True)- UserProductList.objects.create(user=colleague2, team=self.team, product_path="Feature flags", enabled=True)-- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Surveys", enabled=True)-- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Experiments", enabled=False)-- counts = get_user_product_list_count(self.team)-- assert len(counts) == 4- assert counts[0]["product_path"] == "Product analytics"- assert counts[0]["colleague_count"] == 4- assert counts[1]["product_path"] == "Session replay"- assert counts[1]["colleague_count"] == 3- assert counts[2]["product_path"] == "Feature flags"- assert counts[2]["colleague_count"] == 2- assert counts[3]["product_path"] == "Surveys"- assert counts[3]["colleague_count"] == 1-- def test_get_user_product_list_count_excludes_disabled_products(self):- colleague1 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague1", allow_sidebar_suggestions=True- )- colleague2 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague2", allow_sidebar_suggestions=True- )-- colleague1.join(organization=self.organization)- colleague2.join(organization=self.organization)-- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Product analytics", enabled=True)- UserProductList.objects.create(user=colleague2, team=self.team, product_path="Product analytics", enabled=True)- UserProductList.objects.create(user=colleague1, team=self.team, product_path="Session replay", enabled=False)- UserProductList.objects.create(user=colleague2, team=self.team, product_path="Session replay", enabled=False)-- counts = get_user_product_list_count(self.team)-- assert len(counts) == 1- assert counts[0]["product_path"] == "Product analytics"- assert counts[0]["colleague_count"] == 2-- def test_get_user_product_list_count_handles_empty_team(self):- counts = get_user_product_list_count(self.team)- assert len(counts) == 0+ rows = UserProductList.objects.filter(user=user, team=self.team)+ assert {row.product_path for row in rows} == set(DEFAULT_PRODUCT_PATHS)+ for row in rows:+ assert row.enabled is True+ assert row.reason == UserProductList.Reason.DEFAULTdef test_sync_cross_sell_products_suggests_same_category_or_favored(self):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)@@ -269,7 +102,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)UserProductList.objects.create(user=user, team=self.team, product_path="Dashboards", enabled=True)@@ -289,7 +121,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=False)- user.join(organization=self.organization)UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)@@ -300,7 +131,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)@@ -311,7 +141,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)created_items = UserProductList.sync_cross_sell_products(user=user, team=self.team)@@ -324,7 +153,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)@@ -343,7 +171,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)products_by_category = Products.get_products_by_category()tools_products = products_by_category.get(ProductItemCategory.TOOLS, [])@@ -367,7 +194,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)@@ -385,7 +211,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)products_by_category = Products.get_products_by_category()favored_products = _get_favored_product_paths()@@ -412,7 +237,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)@@ -434,7 +258,6 @@ class TestUserProductList(BaseTest):user = User.objects.create_user(email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True)- user.join(organization=self.organization)# Enable all productsfor product in Products.products():@@ -443,6 +266,112 @@ class TestUserProductList(BaseTest):created_items = UserProductList.sync_cross_sell_products(user=user, team=self.team)assert len(created_items) == 0+ def test_sync_from_team_colleagues_filters_out_existing_products(self):+ user = User.objects.create_user(+ email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True+ )++ UserProductList.objects.create(user=user, team=self.team, product_path="Product analytics", enabled=True)+ UserProductList.objects.create(user=user, team=self.team, product_path="Feature flags", enabled=True)++ hardcoded_counts = [+ {"product_path": "Product analytics", "colleague_count": 5},+ {"product_path": "Session replay", "colleague_count": 4},+ {"product_path": "Feature flags", "colleague_count": 3},+ {"product_path": "Surveys", "colleague_count": 2},+ ]++ created_items = UserProductList.sync_from_team_colleagues(+ user=user, team=self.team, count=2, colleague_product_counts=hardcoded_counts+ )++ assert {item.product_path for item in created_items} == {"Session replay", "Surveys"}+ for item in created_items:+ assert item.reason == UserProductList.Reason.USED_BY_COLLEAGUES+ assert item.enabled is True++ def test_sync_from_team_colleagues_ranks_by_counts_and_respects_limit(self):+ user = User.objects.create_user(+ email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True+ )++ hardcoded_counts = [+ {"product_path": "Product analytics", "colleague_count": 10},+ {"product_path": "Session replay", "colleague_count": 8},+ {"product_path": "Feature flags", "colleague_count": 5},+ {"product_path": "Surveys", "colleague_count": 3},+ {"product_path": "Experiments", "colleague_count": 1},+ ]++ created_items = UserProductList.sync_from_team_colleagues(+ user=user, team=self.team, count=3, colleague_product_counts=hardcoded_counts+ )++ assert [item.product_path for item in created_items] == [+ "Product analytics",+ "Session replay",+ "Feature flags",+ ]++ def test_sync_from_team_colleagues_respects_allow_sidebar_suggestions_false(self):+ user = User.objects.create_user(+ email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=False+ )++ hardcoded_counts = [+ {"product_path": "Product analytics", "colleague_count": 10},+ {"product_path": "Session replay", "colleague_count": 8},+ ]++ created_items = UserProductList.sync_from_team_colleagues(+ user=user, team=self.team, colleague_product_counts=hardcoded_counts+ )++ assert len(created_items) == 0++ def test_sync_from_team_colleagues_computes_counts_when_not_provided(self):+ colleague1 = User.objects.create_user(+ email="[email protected]", password="password", first_name="Colleague1"+ )+ colleague2 = User.objects.create_user(+ email="[email protected]", password="password", first_name="Colleague2"+ )+ user = User.objects.create_user(+ email="[email protected]", password="password", first_name="User", allow_sidebar_suggestions=True+ )++ UserProductList.objects.create(user=colleague1, team=self.team, product_path="Product analytics", enabled=True)+ UserProductList.objects.create(user=colleague2, team=self.team, product_path="Product analytics", enabled=True)+ UserProductList.objects.create(user=colleague1, team=self.team, product_path="Session replay", enabled=True)++ created_items = UserProductList.sync_from_team_colleagues(user=user, team=self.team, count=2)++ assert {item.product_path for item in created_items} == {"Product analytics", "Session replay"}++ def test_get_user_product_list_count_ranks_and_excludes_disabled(self):+ # Counts are team-wide; drop the rows seeded for the fixture user so only+ # the colleagues created below contribute.+ UserProductList.objects.filter(team=self.team).delete()+ colleague1 = User.objects.create_user(+ email="[email protected]", password="password", first_name="Colleague1"+ )+ colleague2 = User.objects.create_user(+ email="[email protected]", password="password", first_name="Colleague2"+ )++ UserProductList.objects.create(user=colleague1, team=self.team, product_path="Product analytics", enabled=True)+ UserProductList.objects.create(user=colleague2, team=self.team, product_path="Product analytics", enabled=True)+ UserProductList.objects.create(user=colleague1, team=self.team, product_path="Feature flags", enabled=True)+ UserProductList.objects.create(user=colleague1, team=self.team, product_path="Session replay", enabled=False)+ UserProductList.objects.create(user=colleague2, team=self.team, product_path="Session replay", enabled=False)++ counts = get_user_product_list_count(self.team)++ assert counts == [+ {"product_path": "Product analytics", "colleague_count": 2},+ {"product_path": "Feature flags", "colleague_count": 1},+ ]+def test_user_product_list_reason_enum_matches_backend(self):from posthog.schema import UserProductListReasondiff --git a/posthog/models/file_system/user_product_list.py b/posthog/models/file_system/user_product_list.pyindex e8331cd53858..be34ba09e0dc 100644--- a/posthog/models/file_system/user_product_list.py+++ b/posthog/models/file_system/user_product_list.py@@ -1,4 +1,4 @@-from typing import TYPE_CHECKING, Any, cast+from typing import TYPE_CHECKING, Any, ClassVar, castfrom django.conf import settingsfrom django.db import models, transaction@@ -15,10 +15,66 @@ from posthog.schema_enums import ProductIntentContext, ProductItemCategory, Prodfrom products.growth.backend.cross_sell_candidate_selector import DEFAULT_IGNORED_CATEGORIES, CrossSellCandidateSelectorif TYPE_CHECKING:+ from posthog.models.organization import Organizationfrom posthog.models.product_intent.product_intent import ProductIntentfrom posthog.models.team import Teamfrom posthog.models.user import User+# The baseline sidebar: every user gets these whenever they gain access to a project.+# Paths must match `path` values in frontend/src/products.json.+DEFAULT_PRODUCT_PATHS = [+ "Product analytics",+ "Dashboards",+ "Web analytics",+ "Error tracking",+ "Session replay",+]+++def add_default_products_for_user(user: "User", team: "Team") -> "list[UserProductList]":+ """+ Add the default set of products to a user's sidebar for a team.++ Called whenever a user/project connection is created (project creation, invite+ acceptance, access grants). Rows the user already has - enabled or intentionally+ disabled - are left untouched.+ """+ existing_paths = set(+ UserProductList.objects.filter(user=user, team=team, product_path__in=DEFAULT_PRODUCT_PATHS).values_list(+ "product_path", flat=True+ )+ )+ missing_paths = [path for path in DEFAULT_PRODUCT_PATHS if path not in existing_paths]+ if not missing_paths:+ return []++ # `ignore_conflicts` + `unique_together` on (team, user, product_path) keep this+ # idempotent under concurrent seeding.+ return UserProductList.objects.bulk_create(+ [+ UserProductList(+ user=user, team=team, product_path=path, enabled=True, reason=UserProductList.Reason.DEFAULT+ )+ for path in missing_paths+ ],+ ignore_conflicts=True,+ )+++def add_default_products_for_accessible_teams(user: "User", organization: "Organization") -> None:+ """+ Add the default products to the user's sidebar for every team in the organization+ they have access to. Called when a user/organization connection is created (invite+ acceptance, domain/SSO auto-join).+ """+ from posthog.rbac.user_access_control import UserAccessControl++ uac = UserAccessControl(user=user, organization_id=str(organization.id))+ accessible_teams = uac.filter_queryset_by_access_level(organization.teams.all(), include_all_if_admin=True)++ for team in accessible_teams:+ add_default_products_for_user(user, team)+def get_user_product_list_count(team: "Team") -> list[dict[str, Any]]:"""@@ -42,6 +98,10 @@ def backfill_user_product_list_for_new_user(user: "User", team: "Team") -> None:"""Backfill UserProductList entries for a new user in a new team based on whatthey have enabled in other teams they belong to.++ Not called from any active flow - connection-time seeding uses+ `add_default_products_for_user` instead - but kept alongside the colleague-sync+ Dagster job in case we bring inheritance-based suggestions back."""UserProductList.backfill_from_other_teams(user, team)UserProductList.sync_from_team_colleagues(user, team, count=3)@@ -53,6 +113,13 @@ class UserProductList(UUIDModel, UpdatedMetaFields):Products are identified by their path from the static products list."""+ # django-stubs normally injects the default `objects` manager during mypy's semantic pass,+ # but this module sits in an import cycle (it imports `user_access_control`/`organization`,+ # which loop back through `posthog.models`). When the plugin analyzes the model mid-cycle it+ # skips the injection, so every `UserProductList.objects` use trips `attr-defined`. Declaring+ # the manager explicitly is order-independent and keeps the type stable regardless of the cycle.+ objects: ClassVar[models.Manager["UserProductList"]]+id = models.UUIDField(primary_key=True, default=uuid7, editable=False)team = models.ForeignKey("Team", on_delete=models.CASCADE)user = models.ForeignKey("User", on_delete=models.CASCADE)@@ -62,6 +129,9 @@ class UserProductList(UUIDModel, UpdatedMetaFields):created_at = models.DateTimeField(auto_now_add=True)class Reason(models.TextChoices):+ # Part of the default product set added whenever a user gains access to a project+ DEFAULT = "default", "Default"+# User chose this product during onboardingONBOARDING = "onboarding", "Onboarding"@@ -251,7 +321,7 @@ class UserProductList(UUIDModel, UpdatedMetaFields):other_teams = Team.objects.filter(organization_id__in=user_organizations).exclude(id=team.id)# Get all product paths the user has enabled in other teams. Skip rows seeded by- # onboarding-delegation — those represent a one-off "explore everything" state for+ # onboarding-delegation - those represent a one-off "explore everything" state for# the delegator and shouldn't propagate when they later join another team.user_product_paths = set(UserProductList.objects.filter(user=user, team__in=other_teams, enabled=True)@@ -330,16 +400,16 @@ class UserProductList(UUIDModel, UpdatedMetaFields):@receiver(post_save, sender="ee.AccessControl")def access_control_created(sender, instance, created, **kwargs):"""- Handle AccessControl creation to backfill UserProductList for users gaining access to a team.+ Handle AccessControl creation to seed UserProductList for users gaining access to a team.- When a user is granted access to a team via AccessControl, we backfill their UserProductList- based on what they have enabled in other teams they belong to.+ When a user is granted access to a team via AccessControl, we add the default set of+ products to their sidebar for that team."""if created and instance.organization_member and instance.resource == "project":user = instance.organization_member.userteam = instance.teamif settings.TEST:- backfill_user_product_list_for_new_user(user, team)+ add_default_products_for_user(user, team)else:- transaction.on_commit(lambda: backfill_user_product_list_for_new_user(user, team))+ transaction.on_commit(lambda: add_default_products_for_user(user, team))diff --git a/posthog/models/organization_invite.py b/posthog/models/organization_invite.pyindex cdc458a82dd3..e43828eafe2f 100644--- a/posthog/models/organization_invite.py+++ b/posthog/models/organization_invite.py@@ -13,7 +13,6 @@ from posthog.constants import INVITE_DAYS_VALIDITYfrom posthog.email import is_email_availablefrom posthog.helpers.email_utils import EmailNormalizer, EmailValidationHelperfrom posthog.models.activity_logging.model_activity import ModelActivityMixin-from posthog.models.file_system.user_product_list import backfill_user_product_list_for_new_userfrom posthog.models.onboarding_delegation import mark_delegators_acceptedfrom posthog.models.organization import OrganizationMembershipfrom posthog.models.team import Team@@ -214,9 +213,6 @@ class OrganizationInvite(ModelActivityMixin, UUIDTModel):mark_delegators_accepted(invite_id=sibling_pk)self.delete()- # Side effects that don't need the membership/invite rows are fine to run after commit.- self._sync_user_product_list_for_accessible_teams(user)-if is_email_available(with_absolute_urls=True):from posthog.tasks.email import send_member_join@@ -233,16 +229,6 @@ class OrganizationInvite(ModelActivityMixin, UUIDTModel):# meaning for anyone who happens to be both a delegate here and a delegator elsewhere.mark_delegators_accepted(invite_id=self.id)- def _sync_user_product_list_for_accessible_teams(self, user: "User") -> None:- """Sync UserProductList for all teams the user has access to."""- from posthog.rbac.user_access_control import UserAccessControl-- uac = UserAccessControl(user=user, organization_id=str(self.organization.id))- accessible_teams = uac.filter_queryset_by_access_level(self.organization.teams.all(), include_all_if_admin=True)-- for team in accessible_teams:- backfill_user_product_list_for_new_user(user, team)-def is_expired(self) -> bool:"""Check if invite is older than INVITE_DAYS_VALIDITY days."""return self.created_at < timezone.now() - timedelta(INVITE_DAYS_VALIDITY)diff --git a/posthog/models/test/test_product_intent.py b/posthog/models/test/test_product_intent.pyindex 5260138d9143..044f7f89bd20 100644--- a/posthog/models/test/test_product_intent.py+++ b/posthog/models/test/test_product_intent.py@@ -36,6 +36,9 @@ from products.workflows.backend.models.hog_flow.hog_flow import HogFlowclass TestProductIntent(BaseTest):def setUp(self):super().setUp()+ # Joining the org seeds the fixed default product set; these tests assert on+ # product-intent-driven rows, so start from a clean slate.+ UserProductList.objects.filter(user=self.user, team=self.team).delete()self.product_intent = ProductIntent.objects.create(team=self.team, product_type=ProductKey.DATA_WAREHOUSE)def test_str_representation(self):diff --git a/posthog/models/test/test_user_product_list_invites.py b/posthog/models/test/test_user_product_list_invites.pyindex d059bec1abfd..42345242f560 100644--- a/posthog/models/test/test_user_product_list_invites.py+++ b/posthog/models/test/test_user_product_list_invites.py@@ -1,415 +1,82 @@from posthog.test.base import BaseTestfrom unittest.mock import patch-from posthog.models import Organization, Team, User-from posthog.models.file_system.user_product_list import UserProductList+from posthog.constants import AvailableFeature+from posthog.models import Team, User+from posthog.models.file_system.user_product_list import DEFAULT_PRODUCT_PATHS, UserProductListfrom posthog.models.organization import OrganizationMembershipfrom posthog.models.organization_invite import OrganizationInvitefrom ee.models.rbac.access_control import AccessControl-class TestUserProductListInvites(BaseTest):- def test_invite_user_syncs_products_from_colleagues(self):- """Test that when a user accepts an invite, they get products from team colleagues"""- # Create existing team members with products- colleague1 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague1"+class TestUserProductListDefaults(BaseTest):+ def _default_paths_for(self, user: User, team: Team) -> set[str]:+ return set(+ UserProductList.objects.filter(+ user=user, team=team, enabled=True, reason=UserProductList.Reason.DEFAULT+ ).values_list("product_path", flat=True))- colleague2 = User.objects.create_user(- email="[email protected]", password="password", first_name="Colleague2"- )- colleague1.join(organization=self.organization)- colleague2.join(organization=self.organization)- # Create products for colleagues- UserProductList.objects.create(user=colleague1, team=self.team, product_path="product_analytics", enabled=True)- UserProductList.objects.create(user=colleague1, team=self.team, product_path="session_replay", enabled=True)- UserProductList.objects.create(user=colleague2, team=self.team, product_path="product_analytics", enabled=True)- UserProductList.objects.create(user=colleague2, team=self.team, product_path="feature_flags", enabled=True)+ def _make_team_private(self, team: Team) -> None:+ # Project-level access controls only apply when the org has the feature.+ self.organization.available_product_features = [+ {"key": AvailableFeature.ADVANCED_PERMISSIONS, "name": AvailableFeature.ADVANCED_PERMISSIONS},+ {"key": AvailableFeature.ACCESS_CONTROL, "name": AvailableFeature.ACCESS_CONTROL},+ ]+ self.organization.save()+ AccessControl.objects.create(team=team, resource="project", resource_id=str(team.id), access_level="none")- # Create new user to invite- new_user = User.objects.create_user(- email="[email protected]", password="password", first_name="New", allow_sidebar_suggestions=True- )+ def test_accepting_invite_adds_default_products_for_private_project_access(self):+ # Mark the team private, so seeding can only come from the invite's access grant,+ # not from the org-wide seeding in User.join.+ self._make_team_private(self.team)+ new_user = User.objects.create_user(email="[email protected]", password="password", first_name="New")- # Create invite with access to the teaminvite = OrganizationInvite.objects.create(organization=self.organization,target_email="[email protected]",private_project_access=[{"id": self.team.id, "level": "member"}],)-- # Use the invite- invite.use(new_user, prevalidated=True)-- # Verify products were synced from colleagues (top 3 most popular)- # product_analytics has 2 colleagues, session_replay and feature_flags have 1 each- user_products = UserProductList.objects.filter(user=new_user, team=self.team, enabled=True)- product_paths = set(user_products.values_list("product_path", flat=True))-- # Should have top 3 products from colleagues- self.assertIn("product_analytics", product_paths)- self.assertIn("session_replay", product_paths)- self.assertIn("feature_flags", product_paths)- self.assertEqual(len(product_paths), 3)-- # Verify reason is set correctly- product_analytics = UserProductList.objects.get(user=new_user, team=self.team, product_path="product_analytics")- self.assertEqual(product_analytics.reason, UserProductList.Reason.USED_BY_COLLEAGUES)-- def test_invite_user_backfills_from_other_teams(self):- """Test that when a user accepts an invite, products are backfilled from their other teams"""- # Create a second organization and team for the user- other_org = Organization.objects.create(name="Other Org")- other_team = Team.objects.create(organization=other_org, name="Other Team")-- # Create user and add them to other organization- user = User.objects.create_user(- email="[email protected]", password="password", first_name="Existing", allow_sidebar_suggestions=True- )- user.join(organization=other_org)-- # Create products for user in other team- UserProductList.objects.create(user=user, team=other_team, product_path="product_analytics", enabled=True)- UserProductList.objects.create(user=user, team=other_team, product_path="session_replay", enabled=True)-- # Create invite to new team in different organization- invite = OrganizationInvite.objects.create(- organization=self.organization,- target_email="[email protected]",- private_project_access=[{"id": self.team.id, "level": "member"}],- )-- # Use the invite- invite.use(user, prevalidated=True)-- # Verify products were backfilled from other teams- user_products = UserProductList.objects.filter(user=user, team=self.team, enabled=True)- product_paths = set(user_products.values_list("product_path", flat=True))-- self.assertIn("product_analytics", product_paths)- self.assertIn("session_replay", product_paths)-- def test_invite_user_combines_colleagues_and_backfill(self):- """Test that invite combines products from colleagues and backfill from other teams"""- # Create user with products in another organization- other_org = Organization.objects.create(name="Other Org")- other_team = Team.objects.create(organization=other_org, name="Other Team")- user = User.objects.create_user(- email="[email protected]", password="password", first_name="Combined", allow_sidebar_suggestions=True- )- user.join(organization=other_org)- UserProductList.objects.create(user=user, team=other_team, product_path="product_analytics", enabled=True)-- # Create colleagues with products- colleague = User.objects.create_user(email="[email protected]", password="password", first_name="Colleague")- colleague.join(organization=self.organization)- UserProductList.objects.create(user=colleague, team=self.team, product_path="session_replay", enabled=True)- UserProductList.objects.create(user=colleague, team=self.team, product_path="feature_flags", enabled=True)-- # Create invite- invite = OrganizationInvite.objects.create(- organization=self.organization,- target_email="[email protected]",- private_project_access=[{"id": self.team.id, "level": "member"}],- )-- # Use the invite- invite.use(user, prevalidated=True)-- # Verify both backfill and colleague sync happened- user_products = UserProductList.objects.filter(user=user, team=self.team, enabled=True)- product_paths = set(user_products.values_list("product_path", flat=True))-- # Should have backfilled product_analytics from other team- self.assertIn("product_analytics", product_paths)- # Should have synced products from colleagues- self.assertGreaterEqual(len(product_paths), 1)-- def test_invite_user_respects_allow_sidebar_suggestions(self):- """Test that users with allow_sidebar_suggestions=False don't get products synced"""- # Create colleagues with products- colleague = User.objects.create_user(email="[email protected]", password="password", first_name="Colleague")- colleague.join(organization=self.organization)- UserProductList.objects.create(user=colleague, team=self.team, product_path="product_analytics", enabled=True)-- # Create user with suggestions disabled- user = User.objects.create_user(- email="[email protected]",- password="password",- first_name="NoSuggestions",- allow_sidebar_suggestions=False,- )-- # Create invite- invite = OrganizationInvite.objects.create(- organization=self.organization,- target_email="[email protected]",- private_project_access=[{"id": self.team.id, "level": "member"}],- )-- # Use the invite- invite.use(user, prevalidated=True)-- # Verify no products were synced from colleagues (sync_from_team_colleagues respects this)- colleague_synced = UserProductList.objects.filter(- user=user, team=self.team, reason=UserProductList.Reason.USED_BY_COLLEAGUES- )- self.assertEqual(colleague_synced.count(), 0)-- def test_invite_user_does_not_duplicate_existing_products(self):- """Test that existing products are not duplicated when syncing"""- # Create user with existing product- user = User.objects.create_user(- email="[email protected]",- password="password",- first_name="Existing",- allow_sidebar_suggestions=True,- )-- # Create product before invite- UserProductList.objects.create(user=user, team=self.team, product_path="product_analytics", enabled=True)-- # Create colleagues with same product- colleague = User.objects.create_user(email="[email protected]", password="password", first_name="Colleague")- colleague.join(organization=self.organization)- UserProductList.objects.create(user=colleague, team=self.team, product_path="product_analytics", enabled=True)-- # Create invite- invite = OrganizationInvite.objects.create(- organization=self.organization,- target_email="[email protected]",- private_project_access=[{"id": self.team.id, "level": "member"}],- )-- # Use the invite- invite.use(user, prevalidated=True)-- # Verify only one product_analytics entry exists- product_count = UserProductList.objects.filter(- user=user, team=self.team, product_path="product_analytics"- ).count()- self.assertEqual(product_count, 1)-- def test_invite_user_ranks_colleagues_by_popularity(self):- """Test that products are ranked by how many colleagues have them"""- # Create multiple colleagues with different product distributions- colleagues = []- for i in range(5):- colleague = User.objects.create_user(- email=f"colleague{i}@posthog.com", password="password", first_name=f"Colleague{i}"- )- colleague.join(organization=self.organization)- colleagues.append(colleague)-- # product_analytics: 5 colleagues (most popular)- for colleague in colleagues:- UserProductList.objects.create(- user=colleague, team=self.team, product_path="product_analytics", enabled=True- )-- # session_replay: 3 colleagues- for colleague in colleagues[:3]:- UserProductList.objects.create(user=colleague, team=self.team, product_path="session_replay", enabled=True)-- # feature_flags: 2 colleagues- for colleague in colleagues[:2]:- UserProductList.objects.create(user=colleague, team=self.team, product_path="feature_flags", enabled=True)-- # experiments: 1 colleague (least popular)- UserProductList.objects.create(user=colleagues[0], team=self.team, product_path="experiments", enabled=True)-- # Create new user- new_user = User.objects.create_user(- email="[email protected]", password="password", first_name="New", allow_sidebar_suggestions=True- )-- # Create invite- invite = OrganizationInvite.objects.create(- organization=self.organization,- target_email="[email protected]",- private_project_access=[],- )-- # Use the invite (count=3, so top 3 should be synced)invite.use(new_user, prevalidated=True)- # Verify top products were synced (product_analytics, session_replay, feature_flags)- user_products = UserProductList.objects.filter(- user=new_user, team=self.team, reason=UserProductList.Reason.USED_BY_COLLEAGUES- )- product_paths = set(user_products.values_list("product_path", flat=True))-- # Should have the most popular products- self.assertIn("product_analytics", product_paths)- self.assertIn("session_replay", product_paths)- self.assertIn("feature_flags", product_paths)- self.assertNotIn("experiments", product_paths)- self.assertLessEqual(len(product_paths), 3) # Should not exceed count=3-+ assert self._default_paths_for(new_user, self.team) == set(DEFAULT_PRODUCT_PATHS)-class TestUserProductListInvitesWithoutPrivateProjectAccess(BaseTest):- def test_invite_user_without_private_project_access_syncs_products(self):- """Test that when a user accepts an invite without private_project_access, they still get products synced"""- # Create existing team members with products- colleague = User.objects.create_user(email="[email protected]", password="password", first_name="Colleague")- colleague.join(organization=self.organization)+ def test_accepting_invite_without_private_project_access_adds_default_products(self):+ new_user = User.objects.create_user(email="[email protected]", password="password", first_name="New")- # Create products for colleague- UserProductList.objects.create(user=colleague, team=self.team, product_path="product_analytics", enabled=True)- UserProductList.objects.create(user=colleague, team=self.team, product_path="session_replay", enabled=True)-- # Create new user to invite- new_user = User.objects.create_user(- email="[email protected]", password="password", first_name="New", allow_sidebar_suggestions=True- )-- # Create invite WITHOUT private_project_accessinvite = OrganizationInvite.objects.create(organization=self.organization,target_email="[email protected]",private_project_access=None,)-- # Use the inviteinvite.use(new_user, prevalidated=True)- # Verify products were synced from colleagues- user_products = UserProductList.objects.filter(user=new_user, team=self.team, enabled=True)- product_paths = set(user_products.values_list("product_path", flat=True))-- self.assertIn("product_analytics", product_paths)- self.assertIn("session_replay", product_paths)-- def test_invite_user_without_private_project_access_backfills_from_other_teams(self):- """Test that invite without private_project_access still backfills from user's other teams"""- # Create a second organization and team for the user- other_org = Organization.objects.create(name="Other Org")- other_team = Team.objects.create(organization=other_org, name="Other Team")-- # Create user and add them to other organization- user = User.objects.create_user(- email="[email protected]", password="password", first_name="Existing", allow_sidebar_suggestions=True- )- user.join(organization=other_org)-- # Create products for user in other team- UserProductList.objects.create(user=user, team=other_team, product_path="product_analytics", enabled=True)-- # Create invite WITHOUT private_project_access- invite = OrganizationInvite.objects.create(- organization=self.organization,- target_email="[email protected]",- private_project_access=None,- )-- # Use the invite- invite.use(user, prevalidated=True)-- # Verify products were backfilled from other teams- user_products = UserProductList.objects.filter(user=user, team=self.team, enabled=True)- product_paths = set(user_products.values_list("product_path", flat=True))-- self.assertIn("product_analytics", product_paths)---class TestUserProductListTeamCreation(BaseTest):- def test_create_team_backfills_from_other_teams(self):- """Test that when a user creates a team, products are backfilled from their other teams"""- # Create user with products in existing team- user = User.objects.create_user(- email="[email protected]", password="password", first_name="Creator", allow_sidebar_suggestions=True- )- user.join(organization=self.organization)-- # Create products in existing team- UserProductList.objects.create(user=user, team=self.team, product_path="product_analytics", enabled=True)- UserProductList.objects.create(user=user, team=self.team, product_path="session_replay", enabled=True)-- # Create new team- new_team = Team.objects.create_with_data(initiating_user=user, organization=self.organization, name="New Team")-- # Verify products were backfilled to new team- user_products = UserProductList.objects.filter(user=user, team=new_team, enabled=True)- product_paths = set(user_products.values_list("product_path", flat=True))+ assert self._default_paths_for(new_user, self.team) == set(DEFAULT_PRODUCT_PATHS)- self.assertIn("product_analytics", product_paths)- self.assertIn("session_replay", product_paths)-- def test_create_team_no_backfill_if_user_has_no_other_products(self):- """Test that backfill doesn't happen if user has no products in other teams"""- # Create user without any products- user = User.objects.create_user(- email="[email protected]", password="password", first_name="NoProducts", allow_sidebar_suggestions=True- )- user.join(organization=self.organization)-- # Create new team- new_team = Team.objects.create_with_data(initiating_user=user, organization=self.organization, name="New Team")-- # Verify no products were backfilled- user_products = UserProductList.objects.filter(user=user, team=new_team)- self.assertEqual(user_products.count(), 0)-- def test_create_team_syncs_products_for_all_users_with_access(self):- """Test that when a new team is created, all org members get products synced"""- # Create existing org members with products in the existing team- member1 = User.objects.create_user(- email="[email protected]", password="password", first_name="Member1", allow_sidebar_suggestions=True- )- member2 = User.objects.create_user(- email="[email protected]", password="password", first_name="Member2", allow_sidebar_suggestions=True- )- member1.join(organization=self.organization)- member2.join(organization=self.organization)-- # Create products for members in existing team- UserProductList.objects.create(user=member1, team=self.team, product_path="product_analytics", enabled=True)- UserProductList.objects.create(user=member2, team=self.team, product_path="session_replay", enabled=True)-- # Create a new team (without specifying initiating_user to test all members sync)- creator = User.objects.create_user(- email="[email protected]", password="password", first_name="Creator", allow_sidebar_suggestions=True- )+ def test_creating_team_adds_default_products_for_all_users_with_access(self):+ member = User.objects.create_user(email="[email protected]", password="password", first_name="Member")+ member.join(organization=self.organization)+ creator = User.objects.create_user(email="[email protected]", password="password", first_name="Creator")creator.join(organization=self.organization)+new_team = Team.objects.create_with_data(initiating_user=creator, organization=self.organization, name="New Team")- # Verify member1's products were backfilled to new team- member1_products = UserProductList.objects.filter(user=member1, team=new_team, enabled=True)- member1_paths = set(member1_products.values_list("product_path", flat=True))- self.assertIn("product_analytics", member1_paths)-- # Verify member2's products were backfilled to new team- member2_products = UserProductList.objects.filter(user=member2, team=new_team, enabled=True)- member2_paths = set(member2_products.values_list("product_path", flat=True))- self.assertIn("session_replay", member2_paths)+ assert self._default_paths_for(creator, new_team) == set(DEFAULT_PRODUCT_PATHS)+ assert self._default_paths_for(member, new_team) == set(DEFAULT_PRODUCT_PATHS)@patch("django.db.transaction.on_commit", lambda fn: fn())- def test_access_control_signal_triggers_backfill(self):- """Test that AccessControl creation signal triggers product sync"""- # Create user with products in another organization- other_org = Organization.objects.create(name="Other Org")- other_team = Team.objects.create(organization=other_org, name="Other Team")- user = User.objects.create_user(- email="[email protected]", password="password", first_name="Signal", allow_sidebar_suggestions=True- )- user.join(organization=other_org)- UserProductList.objects.create(user=user, team=other_team, product_path="product_analytics", enabled=True)-- # Add user to new organization+ def test_access_control_signal_adds_default_products(self):+ # Private team: joining the org must NOT seed it; the explicit access grant must.+ self._make_team_private(self.team)+ user = User.objects.create_user(email="[email protected]", password="password", first_name="Signal")user.join(organization=self.organization)membership = OrganizationMembership.objects.get(organization=self.organization, user=user)- # Create colleagues with products- colleague = User.objects.create_user(email="[email protected]", password="password", first_name="Colleague")- colleague.join(organization=self.organization)- UserProductList.objects.create(user=colleague, team=self.team, product_path="session_replay", enabled=True)- UserProductList.objects.create(user=colleague, team=self.team, product_path="feature_flags", enabled=True)+ assert self._default_paths_for(user, self.team) == set()- # Create AccessControl (this should trigger the signal)AccessControl.objects.create(team=self.team,resource="project",@@ -418,10 +85,4 @@ class TestUserProductListTeamCreation(BaseTest):access_level="member",)- # Verify products were synced via signal- user_products = UserProductList.objects.filter(user=user, team=self.team, enabled=True)- product_paths = set(user_products.values_list("product_path", flat=True))-- # Should have backfilled product_analytics and synced products from colleagues- self.assertIn("product_analytics", product_paths)- self.assertGreaterEqual(len(product_paths), 1)+ assert self._default_paths_for(user, self.team) == set(DEFAULT_PRODUCT_PATHS)diff --git a/posthog/models/user.py b/posthog/models/user.pyindex 168c7461f3cd..fb829fa40902 100644--- a/posthog/models/user.py+++ b/posthog/models/user.py@@ -536,6 +536,14 @@ class User(AbstractUser, UUIDTClassicModel, ModelActivityMixin): # type: ignore},)+ # After role assignment, so role-granted project access is included. Covers joins+ # that don't go through an invite (e.g. domain/SSO auto-join).+ from posthog.models.file_system.user_product_list import ( # noqa: PLC0415 - avoids a circular import+ add_default_products_for_accessible_teams,+ )++ add_default_products_for_accessible_teams(self, organization)+return membership@propertydiff --git a/posthog/schema_enums.py b/posthog/schema_enums.pyindex 3afebc9fb751..cad2e265c483 100644--- a/posthog/schema_enums.py+++ b/posthog/schema_enums.py@@ -3560,6 +3560,7 @@ class UsageMetricFormat(StrEnum):class UserProductListReason(StrEnum):+ DEFAULT = "default"ONBOARDING = "onboarding"PRODUCT_INTENT = "product_intent"USED_BY_COLLEAGUES = "used_by_colleagues"diff --git a/posthog/tasks/tasks.py b/posthog/tasks/tasks.pyindex 16bdd6658bd7..8f4487b6359a 100644--- a/posthog/tasks/tasks.py+++ b/posthog/tasks/tasks.py@@ -1598,7 +1598,7 @@ def sync_user_product_lists_for_new_team(team_id: int) -> None:Sync UserProductList for all users who have access to a new team.Called during project creation to avoid request timeouts for large organizations."""- from posthog.models.file_system.user_product_list import backfill_user_product_list_for_new_user+ from posthog.models.file_system.user_product_list import add_default_products_for_userfrom posthog.models.team import Teamtry:@@ -1615,6 +1615,6 @@ def sync_user_product_lists_for_new_team(team_id: int) -> None:)for user in users:- backfill_user_product_list_for_new_user(user, team)+ add_default_products_for_user(user, team)logger.info("sync_user_product_lists_for_new_team: Completed", team_id=team_id)diff --git a/products/growth/dags/tests/test_user_product_list.py b/products/growth/dags/tests/test_user_product_list.pyindex 0521399c1d89..3ff71256a020 100644--- a/products/growth/dags/tests/test_user_product_list.py+++ b/products/growth/dags/tests/test_user_product_list.py@@ -10,6 +10,14 @@ from posthog.models.file_system.user_product_list import UserProductListfrom products.growth.dags.user_product_list import populate_user_product_list, populate_user_product_list_job[email protected](autouse=True)+def _disable_default_product_seeding():+ # These tests exercise the dagster op in isolation. Joining the org would otherwise+ # seed the fixed default product set and skew the entry counts under test.+ with patch("posthog.models.file_system.user_product_list.add_default_products_for_user"):+ yield++def create_mock_s3_resource():"""Create a mock S3 resource for testing."""mock_s3_resource = MagicMock()diff --git a/products/growth/dags/user_product_list.py b/products/growth/dags/user_product_list.pyindex 5b220ed37a4b..2e384b388a91 100644--- a/products/growth/dags/user_product_list.py+++ b/products/growth/dags/user_product_list.py@@ -367,20 +367,15 @@ def sync_colleagues_products_monthly_job():"""Monthly job that syncs products used by colleagues to each user's product list.For each team, finds the most popular products among colleagues and suggests them to users.++ Not on a schedule: connection-time default seeding replaced it, but the job is kept+ available for manual runs from the Dagster UI."""team_ids = get_all_team_ids_op()results = team_ids.map(sync_colleagues_products_for_team_op)aggregate_colleagues_sync_results_op(results.collect())-sync_colleagues_products_monthly_schedule = dagster.ScheduleDefinition(- job=sync_colleagues_products_monthly_job,- cron_schedule="0 5 15 * *", # 15th day of every month at 5am UTC- execution_timezone="UTC",- name="sync_colleagues_products_monthly_schedule",-)--@dataclass(kw_only=True)class SyncCrossSellProductsResult:team_id: intdiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 3ca62c76f2cd..847165a67bad 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -40543,6 +40543,7 @@ export namespace Schemas {}/**+ * * `default` - Default* * `onboarding` - Onboarding* * `product_intent` - Product Intent* * `used_by_colleagues` - Used by Colleagues@@ -40556,6 +40557,7 @@ export namespace Schemas {export const UserProductListReasonEnum = {+ Default: 'default',Onboarding: 'onboarding',ProductIntent: 'product_intent',UsedByColleagues: 'used_by_colleagues',