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: check table access when a subscribed insight changes (#111106)

Alex Liderf34746245a24
diff --git a/ee/hogai/tools/test/test_create_insight.py b/ee/hogai/tools/test/test_create_insight.py
index 664200dcd1ff..700c6695dadc 100644
--- a/ee/hogai/tools/test/test_create_insight.py
+++ b/ee/hogai/tools/test/test_create_insight.py
@@ -27,6 +27,7 @@ from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation
from products.product_analytics.backend.facade.models import Insight
+from products.subscriptions.backend.facade.testing import create_subscription
from ee.hogai.chat_agent.schema_generator.nodes import SchemaGenerationException
from ee.hogai.context.context import AssistantContextManager
@@ -213,7 +214,13 @@ class TestCreateInsightTool(ClickhouseTestMixin, NonAtomicBaseTest):
await insight.arefresh_from_db()
self.assertEqual(insight.query, {"kind": "TrendsQuery", "series": []})
- async def test_saved_update_blocks_restricted_query_on_public_share(self):
+ @parameterized.expand(
+ [
+ ("public_share", "publicly shared"),
+ ("subscription", "delivered by a subscription"),
+ ]
+ )
+ async def test_saved_update_blocks_restricted_query_on_exposed_insight(self, exposure: str, expected_reason: str):
tool = await self._create_tool()
original_query = {"kind": "TrendsQuery", "series": []}
insight = await Insight.objects.acreate(team=self.team, query=original_query)
@@ -226,10 +233,13 @@ class TestCreateInsightTool(ClickhouseTestMixin, NonAtomicBaseTest):
self.organization, "[email protected]", "test-password"
)
tool = await self._create_tool()
- await SharingConfiguration.objects.acreate(team=self.team, insight=insight, enabled=True)
+ if exposure == "public_share":
+ await SharingConfiguration.objects.acreate(team=self.team, insight=insight, enabled=True)
+ else:
+ await database_sync_to_async(create_subscription)(team_id=self.team.id, insight_id=insight.id)
- with patch("posthog.api.query_access_check.blocked_access_for_user", return_value=["restricted table"]):
- with self.assertRaisesRegex(MaxToolRetryableError, "publicly shared"):
+ with patch("posthog.api.sharing_publish_gate.blocked_access_for_user", return_value=["restricted table"]):
+ with self.assertRaisesRegex(MaxToolRetryableError, expected_reason):
await tool._save_insight_query(insight, {"kind": "TrendsQuery", "series": [], "interval": "week"})
await insight.arefresh_from_db()
diff --git a/ee/hogai/tools/upsert_dashboard/test/test_tool.py b/ee/hogai/tools/upsert_dashboard/test/test_tool.py
index 8c9723d5af24..f051cbb96913 100644
--- a/ee/hogai/tools/upsert_dashboard/test/test_tool.py
+++ b/ee/hogai/tools/upsert_dashboard/test/test_tool.py
@@ -27,11 +27,13 @@ from posthog.schema import (
from posthog.constants import AvailableFeature
from posthog.models import OrganizationMembership
from posthog.models.sharing_configuration import SharingConfiguration
+from posthog.sync import database_sync_to_async
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile, Text
from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation
from products.product_analytics.backend.facade.models import Insight
+from products.subscriptions.backend.facade.testing import create_subscription
from ee.hogai.artifacts.types import ModelArtifactResult, StateArtifactResult, VisualizationWithSourceResult
from ee.hogai.context.context import AssistantContextManager
@@ -342,6 +344,35 @@ class TestUpsertDashboardTool(BaseTest):
self.assertEqual(len(tiles), 1)
self.assertEqual(tiles[0].insight_id, insight.id)
+ @parameterized.expand([("new_tile",), ("restored_tile",)])
+ @patch(
+ "posthog.api.sharing_publish_gate.blocked_access_for_user",
+ return_value=["restricted_table"],
+ )
+ async def test_update_dashboard_enforces_subscribed_dashboard_access(
+ self, source: str, _mock_blocked: MagicMock
+ ) -> None:
+ self.organization.available_product_features = [
+ {"key": AvailableFeature.ACCESS_CONTROL, "name": AvailableFeature.ACCESS_CONTROL}
+ ]
+ await self.organization.asave()
+ await OrganizationMembership.objects.filter(user=self.user, organization=self.organization).aupdate(
+ level=OrganizationMembership.Level.MEMBER
+ )
+ dashboard = await Dashboard.objects.acreate(team=self.team, name="Dashboard", created_by=self.user)
+ await database_sync_to_async(create_subscription)(team_id=self.team.id, dashboard_id=dashboard.id)
+ restricted = await self._create_insight("Restricted")
+ if source == "restored_tile":
+ await DashboardTile.objects.acreate(dashboard=dashboard, insight=restricted, deleted=True)
+ tool = self._create_tool()
+
+ with self.assertRaisesRegex(MaxToolRetryableError, "delivered by a subscription"):
+ await tool._arun_impl(
+ UpdateDashboardToolArgs(dashboard_id=str(dashboard.id), insight_ids=[restricted.short_id])
+ )
+
+ self.assertEqual(await DashboardTile.objects.filter(dashboard=dashboard, deleted=False).acount(), 0)
+
async def test_update_dashboard_permission_denied_for_restricted_dashboard(self):
dashboard = await Dashboard.objects.acreate(
team=self.team,
diff --git a/ee/hogai/tools/upsert_dashboard/tool.py b/ee/hogai/tools/upsert_dashboard/tool.py
index 40a88f491da1..cbf5af1318fc 100644
--- a/ee/hogai/tools/upsert_dashboard/tool.py
+++ b/ee/hogai/tools/upsert_dashboard/tool.py
@@ -10,7 +10,7 @@ from rest_framework.exceptions import ValidationError
from posthog.schema import DataTableNode, DataVisualizationNode, HogQLQuery, InsightVizNode, QuerySchemaRoot
-from posthog.api.sharing_publish_gate import check_can_add_insight_to_shared_dashboard
+from posthog.api.sharing_publish_gate import check_can_add_insight_to_dashboard
from posthog.event_usage import EventSource, report_user_action
from posthog.sync import database_sync_to_async
from posthog.utils import pluralize
@@ -214,14 +214,17 @@ class UpsertDashboardTool(MaxTool):
insight_ids = action.insight_ids or []
artifacts = await self._get_visualization_artifacts(insight_ids) if insight_ids else []
- dashboard, resolved_insights = await self._update_dashboard_with_tiles(
- dashboard,
- action.name,
- action.description,
- insight_ids,
- artifacts,
- action.layout_mode,
- )
+ try:
+ dashboard, resolved_insights = await self._update_dashboard_with_tiles(
+ dashboard,
+ action.name,
+ action.description,
+ insight_ids,
+ artifacts,
+ action.layout_mode,
+ )
+ except ValidationError as error:
+ raise MaxToolRetryableError(str(error.detail)) from error
await self._report_dashboard_action(dashboard, "dashboard updated")
if artifacts:
@@ -375,7 +378,7 @@ class UpsertDashboardTool(MaxTool):
if created:
created_insights.append((artifact, insight))
- check_can_add_insight_to_shared_dashboard(self._user, dashboard, insight.query, self.user_access_control)
+ check_can_add_insight_to_dashboard(self._user, dashboard, insight.query, self.user_access_control)
tile, created = DashboardTile.objects_including_soft_deleted.get_or_create(
dashboard=dashboard,
@@ -445,6 +448,9 @@ class UpsertDashboardTool(MaxTool):
# 2. Create new tiles or restore soft deleted
for insight_id, insight in zip(insight_ids, resolved_insights):
existing_tile = short_id_to_tile.get(insight_id)
+ becomes_live = existing_tile is None or existing_tile.deleted
+ if becomes_live:
+ check_can_add_insight_to_dashboard(self._user, dashboard, insight.query, self.user_access_control)
if existing_tile:
# Restore if soft deleted
diff --git a/posthog/api/sharing_publish_gate.py b/posthog/api/sharing_publish_gate.py
index 58a41c89d90e..ad2e0c20ba4e 100644
--- a/posthog/api/sharing_publish_gate.py
+++ b/posthog/api/sharing_publish_gate.py
@@ -26,17 +26,72 @@ from products.dashboards.backend.models.dashboard import Dashboard
from products.notebooks.backend.facade.content import extract_inline_query_nodes, extract_referenced_insight_short_ids
from products.notebooks.backend.models import Notebook
from products.product_analytics.backend.facade.models import Insight
+from products.subscriptions.backend.facade.api import (
+ dashboard_has_active_full_subscription,
+ insight_has_active_subscription,
+)
+
+
+def dashboard_shared_or_subscribed(dashboard: Dashboard) -> str | None:
+ """How the dashboard's tiles reach readers who never pass a table-access check: through its
+ public link, or through a subscription that delivers the whole dashboard. None when neither
+ applies, so a tile write needs no access check."""
+ if is_publicly_shared(dashboard):
+ return "publicly shared"
+ if dashboard_has_active_full_subscription(dashboard.id):
+ return "delivered by a subscription"
+ return None
+
+
+def insight_shared_or_subscribed(insight: Insight) -> str | None:
+ """How the insight reaches readers who never pass a table-access check: through a public
+ link (its own, or a shared dashboard or notebook that shows it), or through a subscription
+ that delivers it. None when neither applies, so a query edit needs no access check."""
+ if is_publicly_shared(insight):
+ return "publicly shared"
+ if insight_has_active_subscription(insight.id):
+ return "delivered by a subscription"
+ return None
+
+
+def insight_query_access_error(
+ user: User,
+ insight: Insight,
+ query: Any,
+ user_access_control: UserAccessControl | None = None,
+) -> str | None:
+ """The validation message that stops saving this query on the insight, when the insight is
+ shared or subscribed and the editor can't run the query themselves. None when the save may
+ go ahead: nothing exposes the insight, the org lacks the access control entitlement, or the
+ editor is an org admin."""
+ if not isinstance(query, dict):
+ return None
+ if not insight.team.organization.is_feature_available(AvailableFeature.ACCESS_CONTROL):
+ return None
+ uac = user_access_control or UserAccessControl(user=user, team=insight.team)
+ # org admins have full access, so skip the gate for a faster save
+ if uac.is_organization_admin:
+ return None
+ exposure = insight_shared_or_subscribed(insight)
+ if exposure is None:
+ return None
+ blocked = blocked_access_for_user(user, insight.team, [query])
+ if not blocked:
+ return None
+ blocked_list = ", ".join(f"`{name}`" for name in blocked)
+ return f"Can't save this query: you don't have access to {blocked_list}, and this insight is {exposure}."
-def check_can_add_insight_to_shared_dashboard(
+def check_can_add_insight_to_dashboard(
user: User,
dashboard: Dashboard,
query: Any,
user_access_control: UserAccessControl | None = None,
) -> None:
"""Raise if binding an insight with this query to the dashboard would expose, through the
- dashboard's public link, a query the editor can't run themselves. No-op when the dashboard
- isn't shared, the org lacks the access control entitlement, or the editor is an org admin."""
+ dashboard's public link or a subscription that delivers it in full, a query the editor can't
+ run themselves. No-op when the dashboard reaches no such reader, the org lacks the access
+ control entitlement, or the editor is an org admin."""
if not isinstance(query, dict):
return
if not dashboard.team.organization.is_feature_available(AvailableFeature.ACCESS_CONTROL):
@@ -45,13 +100,14 @@ def check_can_add_insight_to_shared_dashboard(
# org admins have full access, so skip the gate for a faster write
if uac.is_organization_admin:
return
- if not is_publicly_shared(dashboard):
+ exposure = dashboard_shared_or_subscribed(dashboard)
+ if exposure is None:
return
blocked = blocked_access_for_user(user, dashboard.team, [query])
if blocked:
blocked_list = ", ".join(f"`{name}`" for name in blocked)
raise serializers.ValidationError(
- f"Can't add this insight: you don't have access to {blocked_list}, and this dashboard is publicly shared."
+ f"Can't add this insight: you don't have access to {blocked_list}, and this dashboard is {exposure}."
)
diff --git a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
index e31555d3c202..8d1514c94318 100644
--- a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
+++ b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
@@ -117,6 +117,35 @@
'''
# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.100
+ '''
+ SELECT 1 AS "a"
+ FROM "posthog_sharingconfiguration"
+ WHERE ("posthog_sharingconfiguration"."enabled"
+ AND ("posthog_sharingconfiguration"."expires_at" IS NULL
+ OR "posthog_sharingconfiguration"."expires_at" > 'SHARING-EXPIRY-TIMESTAMP'::timestamptz)
+ AND "posthog_sharingconfiguration"."dashboard_id" = 99999
+ AND "posthog_sharingconfiguration"."team_id" = 99999)
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.101
+ '''
+ SELECT 1 AS "a"
+ FROM "posthog_subscription"
+ WHERE (NOT "posthog_subscription"."deleted"
+ AND "posthog_subscription"."enabled"
+ AND "posthog_subscription"."dashboard_id" = 99999
+ AND NOT (EXISTS
+ (SELECT 1 AS "a"
+ FROM "posthog_subscription_dashboard_export_insights" U1
+ INNER JOIN "posthog_dashboarditem" U2 ON (U1."insight_id" = U2."id")
+ WHERE (NOT U2."deleted"
+ AND U1."subscription_id" = ("posthog_subscription"."id"))
+ LIMIT 1)))
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.102
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -214,7 +243,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.101
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.103
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -239,7 +268,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.102
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.104
'''
SELECT "posthog_insightviewed"."id",
"posthog_insightviewed"."team_id",
@@ -257,7 +286,7 @@
UPDATE
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.103
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.105
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -286,7 +315,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.104
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.106
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -315,7 +344,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.105
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.107
'''
SELECT "posthog_insightvariable"."id",
"posthog_insightvariable"."name",
@@ -335,7 +364,7 @@
ORDER BY "posthog_insightvariable"."name" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.106
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.108
'''
SELECT "posthog_teamrevenueanalyticsconfig"."team_id",
"posthog_teamrevenueanalyticsconfig"."filter_test_accounts",
@@ -348,7 +377,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.107
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.109
'''
SELECT "posthog_teammarketinganalyticsconfig"."team_id",
"posthog_teammarketinganalyticsconfig"."attribution_window_days",
@@ -364,7 +393,19 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.108
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.11
+ '''
+ SELECT COUNT(*) AS "__count"
+ FROM "posthog_dashboardtile"
+ INNER JOIN "posthog_dashboard" ON ("posthog_dashboardtile"."dashboard_id" = "posthog_dashboard"."id")
+ WHERE (NOT ("posthog_dashboardtile"."deleted"
+ AND "posthog_dashboardtile"."deleted" IS NOT NULL)
+ AND NOT ("posthog_dashboard"."deleted")
+ AND "posthog_dashboardtile"."dashboard_id" = 99999
+ AND NOT ("posthog_dashboardtile"."insight_id" IS NULL))
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.110
'''
SELECT "customer_analytics_teamcustomeranalyticsconfig"."team_id",
"customer_analytics_teamcustomeranalyticsconfig"."activity_event",
@@ -381,7 +422,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.109
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.111
'''
SELECT "posthog_tag"."name" AS "tag__name"
FROM "posthog_taggeditem"
@@ -390,19 +431,7 @@
AND "posthog_taggeditem"."object_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.11
- '''
- SELECT COUNT(*) AS "__count"
- FROM "posthog_dashboardtile"
- INNER JOIN "posthog_dashboard" ON ("posthog_dashboardtile"."dashboard_id" = "posthog_dashboard"."id")
- WHERE (NOT ("posthog_dashboardtile"."deleted"
- AND "posthog_dashboardtile"."deleted" IS NOT NULL)
- AND NOT ("posthog_dashboard"."deleted")
- AND "posthog_dashboardtile"."dashboard_id" = 99999
- AND NOT ("posthog_dashboardtile"."insight_id" IS NULL))
- '''
-# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.110
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.112
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -448,7 +477,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.111
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.113
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -494,7 +523,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.112
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.114
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -632,7 +661,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.113
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.115
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -687,7 +716,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.114
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.116
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -710,7 +739,7 @@
AND "ee_accesscontrol"."team_id" = 99999))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.115
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.117
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -763,7 +792,7 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.116
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.118
'''
SELECT "ee_role"."organization_id" AS "role__organization_id",
"ee_rolemembership"."role_id" AS "role_id"
@@ -775,7 +804,7 @@
OR "posthog_organizationmembership"."organization_id" = ("ee_role"."organization_id")))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.117
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.119
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -797,7 +826,26 @@
AND "ee_accesscontrol"."role_id" IS NULL)))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.118
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.12
+ '''
+ SELECT "posthog_sharingconfiguration"."id",
+ "posthog_sharingconfiguration"."team_id",
+ "posthog_sharingconfiguration"."dashboard_id",
+ "posthog_sharingconfiguration"."insight_id",
+ "posthog_sharingconfiguration"."recording_id",
+ "posthog_sharingconfiguration"."notebook_id",
+ "posthog_sharingconfiguration"."interviewee_context_id",
+ "posthog_sharingconfiguration"."created_at",
+ "posthog_sharingconfiguration"."enabled",
+ "posthog_sharingconfiguration"."access_token",
+ "posthog_sharingconfiguration"."expires_at",
+ "posthog_sharingconfiguration"."settings",
+ "posthog_sharingconfiguration"."password_required"
+ FROM "posthog_sharingconfiguration"
+ WHERE "posthog_sharingconfiguration"."dashboard_id" = 99999
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.120
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -899,7 +947,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.119
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.121
'''
SELECT "posthog_sharingconfiguration"."id",
"posthog_sharingconfiguration"."team_id",
@@ -922,26 +970,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.12
- '''
- SELECT "posthog_sharingconfiguration"."id",
- "posthog_sharingconfiguration"."team_id",
- "posthog_sharingconfiguration"."dashboard_id",
- "posthog_sharingconfiguration"."insight_id",
- "posthog_sharingconfiguration"."recording_id",
- "posthog_sharingconfiguration"."notebook_id",
- "posthog_sharingconfiguration"."interviewee_context_id",
- "posthog_sharingconfiguration"."created_at",
- "posthog_sharingconfiguration"."enabled",
- "posthog_sharingconfiguration"."access_token",
- "posthog_sharingconfiguration"."expires_at",
- "posthog_sharingconfiguration"."settings",
- "posthog_sharingconfiguration"."password_required"
- FROM "posthog_sharingconfiguration"
- WHERE "posthog_sharingconfiguration"."dashboard_id" = 99999
- '''
-# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.120
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.122
'''
SELECT "posthog_taggeditem"."id",
"posthog_taggeditem"."tag_id",
@@ -962,7 +991,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.121
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.123
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -1060,7 +1089,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.122
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.124
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -1085,7 +1114,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.123
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.125
'''
SELECT "posthog_filesystemshortcut"."id",
"posthog_filesystemshortcut"."team_id",
@@ -1108,7 +1137,7 @@
AND "posthog_filesystemshortcut"."href" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.124
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.126
'''
SELECT "posthog_insightvariable"."id",
"posthog_insightvariable"."name",
@@ -1128,7 +1157,7 @@
ORDER BY "posthog_insightvariable"."name" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.125
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.127
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -1485,7 +1514,7 @@
ORDER BY "posthog_dashboarditem"."order" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.126
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.128
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -1503,7 +1532,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.127
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.129
'''
SELECT "posthog_taggeditem"."id",
"posthog_taggeditem"."tag_id",
@@ -1524,7 +1553,15 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.128
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.13
+ '''
+ SELECT COUNT(*) AS "__count"
+ FROM "posthog_taggeditem"
+ WHERE ("posthog_taggeditem"."content_type_id" = 99999
+ AND "posthog_taggeditem"."object_id" = 99999)
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.130
'''
SELECT "posthog_alertconfiguration"."created_by_id",
"posthog_alertconfiguration"."created_at",
@@ -1609,7 +1646,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.129
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.131
'''
SELECT "posthog_teamrevenueanalyticsconfig"."team_id",
"posthog_teamrevenueanalyticsconfig"."filter_test_accounts",
@@ -1622,15 +1659,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.13
- '''
- SELECT COUNT(*) AS "__count"
- FROM "posthog_taggeditem"
- WHERE ("posthog_taggeditem"."content_type_id" = 99999
- AND "posthog_taggeditem"."object_id" = 99999)
- '''
-# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.130
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.132
'''
SELECT "posthog_teammarketinganalyticsconfig"."team_id",
"posthog_teammarketinganalyticsconfig"."attribution_window_days",
@@ -1646,7 +1675,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.131
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.133
'''
SELECT "customer_analytics_teamcustomeranalyticsconfig"."team_id",
"customer_analytics_teamcustomeranalyticsconfig"."activity_event",
@@ -1663,7 +1692,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.132
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.134
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -1709,7 +1738,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.133
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.135
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -1755,7 +1784,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.134
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.136
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -1893,7 +1922,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.135
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.137
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -1948,7 +1977,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.136
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.138
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -1971,7 +2000,7 @@
AND "ee_accesscontrol"."team_id" = 99999))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.137
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.139
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -2024,7 +2053,23 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.138
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.14
+ '''
+ SELECT "posthog_filesystem"."id" AS "id",
+ "posthog_filesystem"."path" AS "path"
+ FROM "posthog_filesystem"
+ WHERE (("posthog_filesystem"."surface" IS NULL
+ OR "posthog_filesystem"."surface" = 'web')
+ AND "posthog_filesystem"."ref" = '0001'
+ AND "posthog_filesystem"."team_id" = 99999
+ AND "posthog_filesystem"."type" = 'dashboard'
+ AND NOT ("posthog_filesystem"."shortcut"
+ AND "posthog_filesystem"."shortcut" IS NOT NULL))
+ ORDER BY 1 ASC
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.140
'''
SELECT "ee_role"."organization_id" AS "role__organization_id",
"ee_rolemembership"."role_id" AS "role_id"
@@ -2036,7 +2081,7 @@
OR "posthog_organizationmembership"."organization_id" = ("ee_role"."organization_id")))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.139
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.141
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -2058,23 +2103,7 @@
AND "ee_accesscontrol"."role_id" IS NULL)))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.14
- '''
- SELECT "posthog_filesystem"."id" AS "id",
- "posthog_filesystem"."path" AS "path"
- FROM "posthog_filesystem"
- WHERE (("posthog_filesystem"."surface" IS NULL
- OR "posthog_filesystem"."surface" = 'web')
- AND "posthog_filesystem"."ref" = '0001'
- AND "posthog_filesystem"."team_id" = 99999
- AND "posthog_filesystem"."type" = 'dashboard'
- AND NOT ("posthog_filesystem"."shortcut"
- AND "posthog_filesystem"."shortcut" IS NOT NULL))
- ORDER BY 1 ASC
- LIMIT 1
- '''
-# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.140
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.142
'''
SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
@@ -2094,7 +2123,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.141
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.143
'''
SELECT "posthog_dashboard"."id" AS "id",
"posthog_dashboard"."name" AS "name"
@@ -2107,7 +2136,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.142
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.144
'''
SELECT COUNT(*) AS "__count"
FROM "posthog_dashboardtile"
@@ -2120,7 +2149,7 @@
AND "posthog_dashboardtile"."deleted" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.143
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.145
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -2152,7 +2181,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.144
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.146
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -2250,7 +2279,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.145
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.147
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -2296,7 +2325,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.146
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.148
'''
SELECT 1 AS "a"
FROM "posthog_sharingconfiguration"
@@ -2308,7 +2337,40 @@
LIMIT 1
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.147
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.149
+ '''
+ SELECT 1 AS "a"
+ FROM "posthog_subscription"
+ WHERE (NOT "posthog_subscription"."deleted"
+ AND "posthog_subscription"."enabled"
+ AND "posthog_subscription"."dashboard_id" = 99999
+ AND NOT (EXISTS
+ (SELECT 1 AS "a"
+ FROM "posthog_subscription_dashboard_export_insights" U1
+ INNER JOIN "posthog_dashboarditem" U2 ON (U1."insight_id" = U2."id")
+ WHERE (NOT U2."deleted"
+ AND U1."subscription_id" = ("posthog_subscription"."id"))
+ LIMIT 1)))
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.15
+ '''
+ SELECT "posthog_filesystem"."id" AS "id",
+ "posthog_filesystem"."path" AS "path"
+ FROM "posthog_filesystem"
+ WHERE (("posthog_filesystem"."surface" IS NULL
+ OR "posthog_filesystem"."surface" = 'web')
+ AND "posthog_filesystem"."ref" = '0001'
+ AND "posthog_filesystem"."team_id" = 99999
+ AND "posthog_filesystem"."type" = 'dashboard'
+ AND NOT ("posthog_filesystem"."shortcut"
+ AND "posthog_filesystem"."shortcut" IS NOT NULL))
+ ORDER BY 1 ASC
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.150
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -2406,7 +2468,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.148
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.151
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -2431,7 +2493,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.149
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.152
'''
SELECT "posthog_insightviewed"."id",
"posthog_insightviewed"."team_id",
@@ -2449,23 +2511,7 @@
UPDATE
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.15
- '''
- SELECT "posthog_filesystem"."id" AS "id",
- "posthog_filesystem"."path" AS "path"
- FROM "posthog_filesystem"
- WHERE (("posthog_filesystem"."surface" IS NULL
- OR "posthog_filesystem"."surface" = 'web')
- AND "posthog_filesystem"."ref" = '0001'
- AND "posthog_filesystem"."team_id" = 99999
- AND "posthog_filesystem"."type" = 'dashboard'
- AND NOT ("posthog_filesystem"."shortcut"
- AND "posthog_filesystem"."shortcut" IS NOT NULL))
- ORDER BY 1 ASC
- LIMIT 1
- '''
-# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.150
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.153
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -2494,7 +2540,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.151
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.154
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -2523,7 +2569,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.152
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.155
'''
SELECT "posthog_insightvariable"."id",
"posthog_insightvariable"."name",
@@ -2543,7 +2589,7 @@
ORDER BY "posthog_insightvariable"."name" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.153
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.156
'''
SELECT "posthog_teamrevenueanalyticsconfig"."team_id",
"posthog_teamrevenueanalyticsconfig"."filter_test_accounts",
@@ -2556,7 +2602,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.154
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.157
'''
SELECT "posthog_teammarketinganalyticsconfig"."team_id",
"posthog_teammarketinganalyticsconfig"."attribution_window_days",
@@ -2572,7 +2618,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.155
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.158
'''
SELECT "customer_analytics_teamcustomeranalyticsconfig"."team_id",
"customer_analytics_teamcustomeranalyticsconfig"."activity_event",
@@ -2589,7 +2635,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.156
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.159
'''
SELECT "posthog_tag"."name" AS "tag__name"
FROM "posthog_taggeditem"
@@ -2598,7 +2644,23 @@
AND "posthog_taggeditem"."object_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.157
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.16
+ '''
+ SELECT "posthog_filesystem"."id" AS "id",
+ "posthog_filesystem"."path" AS "path"
+ FROM "posthog_filesystem"
+ WHERE (("posthog_filesystem"."surface" IS NULL
+ OR "posthog_filesystem"."surface" = 'web')
+ AND "posthog_filesystem"."ref" = '0001'
+ AND "posthog_filesystem"."team_id" = 99999
+ AND "posthog_filesystem"."type" = 'dashboard'
+ AND NOT ("posthog_filesystem"."shortcut"
+ AND "posthog_filesystem"."shortcut" IS NOT NULL))
+ ORDER BY 1 ASC
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.160
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -2644,7 +2706,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.158
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.161
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -2690,7 +2752,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.159
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.162
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -2828,23 +2890,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.16
- '''
- SELECT "posthog_filesystem"."id" AS "id",
- "posthog_filesystem"."path" AS "path"
- FROM "posthog_filesystem"
- WHERE (("posthog_filesystem"."surface" IS NULL
- OR "posthog_filesystem"."surface" = 'web')
- AND "posthog_filesystem"."ref" = '0001'
- AND "posthog_filesystem"."team_id" = 99999
- AND "posthog_filesystem"."type" = 'dashboard'
- AND NOT ("posthog_filesystem"."shortcut"
- AND "posthog_filesystem"."shortcut" IS NOT NULL))
- ORDER BY 1 ASC
- LIMIT 1
- '''
-# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.160
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.163
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -2899,7 +2945,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.161
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.164
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -2922,7 +2968,7 @@
AND "ee_accesscontrol"."team_id" = 99999))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.162
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.165
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -2975,7 +3021,7 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.163
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.166
'''
SELECT "ee_role"."organization_id" AS "role__organization_id",
"ee_rolemembership"."role_id" AS "role_id"
@@ -2987,7 +3033,7 @@
OR "posthog_organizationmembership"."organization_id" = ("ee_role"."organization_id")))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.164
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.167
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -3009,7 +3055,7 @@
AND "ee_accesscontrol"."role_id" IS NULL)))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.165
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.168
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -3111,7 +3157,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.166
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.169
'''
SELECT "posthog_sharingconfiguration"."id",
"posthog_sharingconfiguration"."team_id",
@@ -3134,7 +3180,26 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.167
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.17
+ '''
+ SELECT "posthog_sharingconfiguration"."id",
+ "posthog_sharingconfiguration"."team_id",
+ "posthog_sharingconfiguration"."dashboard_id",
+ "posthog_sharingconfiguration"."insight_id",
+ "posthog_sharingconfiguration"."recording_id",
+ "posthog_sharingconfiguration"."notebook_id",
+ "posthog_sharingconfiguration"."interviewee_context_id",
+ "posthog_sharingconfiguration"."created_at",
+ "posthog_sharingconfiguration"."enabled",
+ "posthog_sharingconfiguration"."access_token",
+ "posthog_sharingconfiguration"."expires_at",
+ "posthog_sharingconfiguration"."settings",
+ "posthog_sharingconfiguration"."password_required"
+ FROM "posthog_sharingconfiguration"
+ WHERE "posthog_sharingconfiguration"."dashboard_id" = 99999
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.170
'''
SELECT "posthog_taggeditem"."id",
"posthog_taggeditem"."tag_id",
@@ -3155,7 +3220,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.168
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.171
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -3253,7 +3318,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.169
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.172
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -3278,26 +3343,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.17
- '''
- SELECT "posthog_sharingconfiguration"."id",
- "posthog_sharingconfiguration"."team_id",
- "posthog_sharingconfiguration"."dashboard_id",
- "posthog_sharingconfiguration"."insight_id",
- "posthog_sharingconfiguration"."recording_id",
- "posthog_sharingconfiguration"."notebook_id",
- "posthog_sharingconfiguration"."interviewee_context_id",
- "posthog_sharingconfiguration"."created_at",
- "posthog_sharingconfiguration"."enabled",
- "posthog_sharingconfiguration"."access_token",
- "posthog_sharingconfiguration"."expires_at",
- "posthog_sharingconfiguration"."settings",
- "posthog_sharingconfiguration"."password_required"
- FROM "posthog_sharingconfiguration"
- WHERE "posthog_sharingconfiguration"."dashboard_id" = 99999
- '''
-# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.170
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.173
'''
SELECT "posthog_filesystemshortcut"."id",
"posthog_filesystemshortcut"."team_id",
@@ -3320,7 +3366,7 @@
AND "posthog_filesystemshortcut"."href" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.171
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.174
'''
SELECT "posthog_insightvariable"."id",
"posthog_insightvariable"."name",
@@ -3340,7 +3386,7 @@
ORDER BY "posthog_insightvariable"."name" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.172
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.175
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -3697,7 +3743,7 @@
ORDER BY "posthog_dashboarditem"."order" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.173
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.176
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -3715,7 +3761,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.174
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.177
'''
SELECT "posthog_taggeditem"."id",
"posthog_taggeditem"."tag_id",
@@ -3736,7 +3782,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.175
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.178
'''
SELECT "posthog_alertconfiguration"."created_by_id",
"posthog_alertconfiguration"."created_at",
@@ -3821,7 +3867,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.176
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.179
'''
SELECT "posthog_teamrevenueanalyticsconfig"."team_id",
"posthog_teamrevenueanalyticsconfig"."filter_test_accounts",
@@ -3834,7 +3880,27 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.177
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.18
+ '''
+ SELECT "posthog_insightvariable"."id",
+ "posthog_insightvariable"."name",
+ "posthog_insightvariable"."code_name",
+ "posthog_insightvariable"."type",
+ "posthog_insightvariable"."default_value",
+ "posthog_insightvariable"."is_multi"
+ FROM "posthog_insightvariable"
+ INNER JOIN "posthog_team" ON ("posthog_insightvariable"."team_id" = "posthog_team"."id")
+ WHERE ("posthog_insightvariable"."team_id" =
+ (SELECT U0."parent_team_id" AS "parent_team_id"
+ FROM "posthog_team" U0
+ WHERE U0."id" = 99999
+ LIMIT 1)
+ OR ("posthog_team"."parent_team_id" IS NULL
+ AND "posthog_insightvariable"."team_id" = 99999))
+ ORDER BY "posthog_insightvariable"."name" ASC
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.180
'''
SELECT "posthog_teammarketinganalyticsconfig"."team_id",
"posthog_teammarketinganalyticsconfig"."attribution_window_days",
@@ -3850,7 +3916,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.178
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.181
'''
SELECT "customer_analytics_teamcustomeranalyticsconfig"."team_id",
"customer_analytics_teamcustomeranalyticsconfig"."activity_event",
@@ -3867,26 +3933,6 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.18
- '''
- SELECT "posthog_insightvariable"."id",
- "posthog_insightvariable"."name",
- "posthog_insightvariable"."code_name",
- "posthog_insightvariable"."type",
- "posthog_insightvariable"."default_value",
- "posthog_insightvariable"."is_multi"
- FROM "posthog_insightvariable"
- INNER JOIN "posthog_team" ON ("posthog_insightvariable"."team_id" = "posthog_team"."id")
- WHERE ("posthog_insightvariable"."team_id" =
- (SELECT U0."parent_team_id" AS "parent_team_id"
- FROM "posthog_team" U0
- WHERE U0."id" = 99999
- LIMIT 1)
- OR ("posthog_team"."parent_team_id" IS NULL
- AND "posthog_insightvariable"."team_id" = 99999))
- ORDER BY "posthog_insightvariable"."name" ASC
- '''
-# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.19
'''
SELECT "posthog_dashboardtile"."id",
@@ -6216,6 +6262,23 @@
'''
# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.52
+ '''
+ SELECT 1 AS "a"
+ FROM "posthog_subscription"
+ WHERE (NOT "posthog_subscription"."deleted"
+ AND "posthog_subscription"."enabled"
+ AND "posthog_subscription"."dashboard_id" = 99999
+ AND NOT (EXISTS
+ (SELECT 1 AS "a"
+ FROM "posthog_subscription_dashboard_export_insights" U1
+ INNER JOIN "posthog_dashboarditem" U2 ON (U1."insight_id" = U2."id")
+ WHERE (NOT U2."deleted"
+ AND U1."subscription_id" = ("posthog_subscription"."id"))
+ LIMIT 1)))
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.53
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -6313,7 +6376,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.53
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.54
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -6338,7 +6401,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.54
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.55
'''
SELECT "posthog_insightviewed"."id",
"posthog_insightviewed"."team_id",
@@ -6356,7 +6419,7 @@
UPDATE
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.55
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.56
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -6385,7 +6448,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.56
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.57
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -6414,7 +6477,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.57
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.58
'''
SELECT "posthog_insightvariable"."id",
"posthog_insightvariable"."name",
@@ -6434,7 +6497,7 @@
ORDER BY "posthog_insightvariable"."name" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.58
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.59
'''
SELECT "posthog_teamrevenueanalyticsconfig"."team_id",
"posthog_teamrevenueanalyticsconfig"."filter_test_accounts",
@@ -6447,7 +6510,19 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.59
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.6
+ '''
+ SELECT "ee_role"."organization_id" AS "role__organization_id",
+ "ee_rolemembership"."role_id" AS "role_id"
+ FROM "ee_rolemembership"
+ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_rolemembership"."organization_member_id" = "posthog_organizationmembership"."id")
+ INNER JOIN "ee_role" ON ("ee_rolemembership"."role_id" = "ee_role"."id")
+ WHERE ("ee_rolemembership"."user_id" = 99999
+ AND ("ee_rolemembership"."organization_member_id" IS NULL
+ OR "posthog_organizationmembership"."organization_id" = ("ee_role"."organization_id")))
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.60
'''
SELECT "posthog_teammarketinganalyticsconfig"."team_id",
"posthog_teammarketinganalyticsconfig"."attribution_window_days",
@@ -6463,19 +6538,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.6
- '''
- SELECT "ee_role"."organization_id" AS "role__organization_id",
- "ee_rolemembership"."role_id" AS "role_id"
- FROM "ee_rolemembership"
- LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_rolemembership"."organization_member_id" = "posthog_organizationmembership"."id")
- INNER JOIN "ee_role" ON ("ee_rolemembership"."role_id" = "ee_role"."id")
- WHERE ("ee_rolemembership"."user_id" = 99999
- AND ("ee_rolemembership"."organization_member_id" IS NULL
- OR "posthog_organizationmembership"."organization_id" = ("ee_role"."organization_id")))
- '''
-# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.60
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.61
'''
SELECT "customer_analytics_teamcustomeranalyticsconfig"."team_id",
"customer_analytics_teamcustomeranalyticsconfig"."activity_event",
@@ -6492,7 +6555,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.61
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.62
'''
SELECT "customer_analytics_teamcustomeranalyticsconfig"."account_group_type_index" AS "account_group_type_index"
FROM "customer_analytics_teamcustomeranalyticsconfig"
@@ -6501,7 +6564,7 @@
LIMIT 1
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.62
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.63
'''
SELECT "posthog_tag"."name" AS "tag__name"
FROM "posthog_taggeditem"
@@ -6510,7 +6573,7 @@
AND "posthog_taggeditem"."object_id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.63
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.64
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -6556,7 +6619,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.64
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.65
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -6602,7 +6665,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.65
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.66
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -6740,7 +6803,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.66
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.67
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -6795,7 +6858,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.67
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.68
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -6818,7 +6881,7 @@
AND "ee_accesscontrol"."team_id" = 99999))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.68
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.69
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -6871,18 +6934,6 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.69
- '''
- SELECT "ee_role"."organization_id" AS "role__organization_id",
- "ee_rolemembership"."role_id" AS "role_id"
- FROM "ee_rolemembership"
- LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_rolemembership"."organization_member_id" = "posthog_organizationmembership"."id")
- INNER JOIN "ee_role" ON ("ee_rolemembership"."role_id" = "ee_role"."id")
- WHERE ("ee_rolemembership"."user_id" = 99999
- AND ("ee_rolemembership"."organization_member_id" IS NULL
- OR "posthog_organizationmembership"."organization_id" = ("ee_role"."organization_id")))
- '''
-# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.7
'''
SELECT "ee_accesscontrol"."id",
@@ -6906,6 +6957,18 @@
'''
# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.70
+ '''
+ SELECT "ee_role"."organization_id" AS "role__organization_id",
+ "ee_rolemembership"."role_id" AS "role_id"
+ FROM "ee_rolemembership"
+ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_rolemembership"."organization_member_id" = "posthog_organizationmembership"."id")
+ INNER JOIN "ee_role" ON ("ee_rolemembership"."role_id" = "ee_role"."id")
+ WHERE ("ee_rolemembership"."user_id" = 99999
+ AND ("ee_rolemembership"."organization_member_id" IS NULL
+ OR "posthog_organizationmembership"."organization_id" = ("ee_role"."organization_id")))
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.71
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -6927,7 +6990,7 @@
AND "ee_accesscontrol"."role_id" IS NULL)))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.71
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.72
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -7029,7 +7092,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.72
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.73
'''
SELECT "posthog_sharingconfiguration"."id",
"posthog_sharingconfiguration"."team_id",
@@ -7052,7 +7115,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.73
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.74
'''
SELECT "posthog_taggeditem"."id",
"posthog_taggeditem"."tag_id",
@@ -7073,7 +7136,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.74
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.75
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -7171,7 +7234,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.75
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.76
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -7196,7 +7259,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.76
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.77
'''
SELECT "posthog_filesystemshortcut"."id",
"posthog_filesystemshortcut"."team_id",
@@ -7219,7 +7282,7 @@
AND "posthog_filesystemshortcut"."href" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.77
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.78
'''
SELECT "posthog_insightvariable"."id",
"posthog_insightvariable"."name",
@@ -7239,7 +7302,7 @@
ORDER BY "posthog_insightvariable"."name" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.78
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.79
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -7596,24 +7659,6 @@
ORDER BY "posthog_dashboarditem"."order" ASC
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.79
- '''
- SELECT "posthog_dashboardtile"."id",
- "posthog_dashboardtile"."dashboard_id",
- "posthog_dashboardtile"."insight_id",
- "posthog_dashboardtile"."deleted"
- FROM "posthog_dashboardtile"
- INNER JOIN "posthog_dashboard" ON ("posthog_dashboardtile"."dashboard_id" = "posthog_dashboard"."id")
- WHERE (NOT ("posthog_dashboardtile"."deleted"
- AND "posthog_dashboardtile"."deleted" IS NOT NULL)
- AND NOT ("posthog_dashboard"."deleted")
- AND "posthog_dashboardtile"."insight_id" IN (1,
- 2,
- 3,
- 4,
- 5 /* ... */))
- '''
-# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.8
'''
SELECT COUNT(*) AS "__count"
@@ -7631,6 +7676,24 @@
'''
# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.80
+ '''
+ SELECT "posthog_dashboardtile"."id",
+ "posthog_dashboardtile"."dashboard_id",
+ "posthog_dashboardtile"."insight_id",
+ "posthog_dashboardtile"."deleted"
+ FROM "posthog_dashboardtile"
+ INNER JOIN "posthog_dashboard" ON ("posthog_dashboardtile"."dashboard_id" = "posthog_dashboard"."id")
+ WHERE (NOT ("posthog_dashboardtile"."deleted"
+ AND "posthog_dashboardtile"."deleted" IS NOT NULL)
+ AND NOT ("posthog_dashboard"."deleted")
+ AND "posthog_dashboardtile"."insight_id" IN (1,
+ 2,
+ 3,
+ 4,
+ 5 /* ... */))
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.81
'''
SELECT "posthog_taggeditem"."id",
"posthog_taggeditem"."tag_id",
@@ -7651,7 +7714,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.81
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.82
'''
SELECT "posthog_alertconfiguration"."created_by_id",
"posthog_alertconfiguration"."created_at",
@@ -7736,7 +7799,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.82
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.83
'''
SELECT "posthog_teamrevenueanalyticsconfig"."team_id",
"posthog_teamrevenueanalyticsconfig"."filter_test_accounts",
@@ -7749,7 +7812,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.83
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.84
'''
SELECT "posthog_teammarketinganalyticsconfig"."team_id",
"posthog_teammarketinganalyticsconfig"."attribution_window_days",
@@ -7765,7 +7828,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.84
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.85
'''
SELECT "customer_analytics_teamcustomeranalyticsconfig"."team_id",
"customer_analytics_teamcustomeranalyticsconfig"."activity_event",
@@ -7782,7 +7845,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.85
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.86
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -7828,7 +7891,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.86
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.87
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -7874,7 +7937,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.87
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.88
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -8012,7 +8075,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.88
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.89
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -8067,29 +8130,6 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.89
- '''
- SELECT "ee_accesscontrol"."id",
- "ee_accesscontrol"."team_id",
- "ee_accesscontrol"."access_level",
- "ee_accesscontrol"."resource",
- "ee_accesscontrol"."resource_id",
- "ee_accesscontrol"."organization_member_id",
- "ee_accesscontrol"."role_id",
- "ee_accesscontrol"."created_by_id",
- "ee_accesscontrol"."created_at",
- "ee_accesscontrol"."updated_at"
- FROM "ee_accesscontrol"
- LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id")
- WHERE (("ee_accesscontrol"."organization_member_id" IS NULL
- AND "ee_accesscontrol"."role_id" IS NULL
- AND "ee_accesscontrol"."team_id" = 99999)
- OR ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
- AND "posthog_organizationmembership"."user_id" = 99999
- AND "ee_accesscontrol"."role_id" IS NULL
- AND "ee_accesscontrol"."team_id" = 99999))
- '''
-# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.9
'''
SELECT "posthog_team"."id",
@@ -8189,6 +8229,29 @@
'''
# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.90
+ '''
+ SELECT "ee_accesscontrol"."id",
+ "ee_accesscontrol"."team_id",
+ "ee_accesscontrol"."access_level",
+ "ee_accesscontrol"."resource",
+ "ee_accesscontrol"."resource_id",
+ "ee_accesscontrol"."organization_member_id",
+ "ee_accesscontrol"."role_id",
+ "ee_accesscontrol"."created_by_id",
+ "ee_accesscontrol"."created_at",
+ "ee_accesscontrol"."updated_at"
+ FROM "ee_accesscontrol"
+ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id")
+ WHERE (("ee_accesscontrol"."organization_member_id" IS NULL
+ AND "ee_accesscontrol"."role_id" IS NULL
+ AND "ee_accesscontrol"."team_id" = 99999)
+ OR ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
+ AND "posthog_organizationmembership"."user_id" = 99999
+ AND "ee_accesscontrol"."role_id" IS NULL
+ AND "ee_accesscontrol"."team_id" = 99999))
+ '''
+# ---
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.91
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -8241,7 +8304,7 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.91
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.92
'''
SELECT "ee_role"."organization_id" AS "role__organization_id",
"ee_rolemembership"."role_id" AS "role_id"
@@ -8253,7 +8316,7 @@
OR "posthog_organizationmembership"."organization_id" = ("ee_role"."organization_id")))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.92
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.93
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -8275,7 +8338,7 @@
AND "ee_accesscontrol"."role_id" IS NULL)))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.93
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.94
'''
SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
@@ -8295,7 +8358,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.94
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.95
'''
SELECT "posthog_dashboard"."id" AS "id",
"posthog_dashboard"."name" AS "name"
@@ -8308,7 +8371,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.95
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.96
'''
SELECT COUNT(*) AS "__count"
FROM "posthog_dashboardtile"
@@ -8321,7 +8384,7 @@
AND "posthog_dashboardtile"."deleted" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.96
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.97
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -8353,7 +8416,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.97
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.98
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -8451,7 +8514,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.98
+# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.99
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -8497,18 +8560,6 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.99
- '''
- SELECT 1 AS "a"
- FROM "posthog_sharingconfiguration"
- WHERE ("posthog_sharingconfiguration"."enabled"
- AND ("posthog_sharingconfiguration"."expires_at" IS NULL
- OR "posthog_sharingconfiguration"."expires_at" > 'SHARING-EXPIRY-TIMESTAMP'::timestamptz)
- AND "posthog_sharingconfiguration"."dashboard_id" = 99999
- AND "posthog_sharingconfiguration"."team_id" = 99999)
- LIMIT 1
- '''
-# ---
# name: TestDashboard.test_listing_dashboards_is_not_nplus1
'''
SELECT "posthog_user"."id",
diff --git a/posthog/api/test/test_sharing.py b/posthog/api/test/test_sharing.py
index 352d0494024b..0c32f2beab0b 100644
--- a/posthog/api/test/test_sharing.py
+++ b/posthog/api/test/test_sharing.py
@@ -2522,8 +2522,22 @@ class TestSaveTimeAccessBlock(APIBaseTest):
assert response.status_code == status.HTTP_400_BAD_REQUEST, response.content
assert "governed_view" in str(response.json())
- @parameterized.expand([("direct",), ("dashboard",), ("notebook",)])
- def test_query_update_blocked_when_insight_is_publicly_shared(self, coverage: str):
+ @parameterized.expand(
+ [
+ ("direct", "this insight is publicly shared"),
+ ("dashboard", "this insight is publicly shared"),
+ ("notebook", "this insight is publicly shared"),
+ ("subscription", "delivered by a subscription"),
+ ("dashboard_subscription", "delivered by a subscription"),
+ # Restoring the dashboard resumes delivery without a subscription write.
+ ("deleted_dashboard_subscription", "delivered by a subscription"),
+ # A selection whose insights are all deleted delivers every live tile.
+ ("dashboard_subscription_with_deleted_selection", "delivered by a subscription"),
+ # Deleting the dashboard hides its tiles; restoring it brings them back without a gate.
+ ("dashboard_subscription_with_hidden_tile", "delivered by a subscription"),
+ ]
+ )
+ def test_query_update_blocked_when_insight_is_shared_or_delivered(self, coverage: str, expected_reason: str):
self._deny_editor()
if coverage == "direct":
SharingConfiguration.objects.create(team=self.team, insight=self.insight, enabled=True)
@@ -2531,6 +2545,25 @@ class TestSaveTimeAccessBlock(APIBaseTest):
dashboard = Dashboard.objects.create(team=self.team, created_by=self.user)
DashboardTile.objects.create(dashboard=dashboard, insight=self.insight)
SharingConfiguration.objects.create(team=self.team, dashboard=dashboard, enabled=True)
+ elif coverage == "subscription":
+ create_subscription(team_id=self.team.id, insight_id=self.insight.id)
+ elif coverage in ("dashboard_subscription", "deleted_dashboard_subscription"):
+ dashboard = Dashboard.objects.create(
+ team=self.team, created_by=self.user, deleted=coverage == "deleted_dashboard_subscription"
+ )
+ DashboardTile.objects.create(dashboard=dashboard, insight=self.insight)
+ create_subscription(team_id=self.team.id, dashboard_id=dashboard.id)
+ elif coverage == "dashboard_subscription_with_hidden_tile":
+ dashboard = Dashboard.objects.create(team=self.team, created_by=self.user)
+ DashboardTile.objects.create(dashboard=dashboard, insight=self.insight, deleted=True)
+ create_subscription(team_id=self.team.id, dashboard_id=dashboard.id)
+ elif coverage == "dashboard_subscription_with_deleted_selection":
+ dashboard = Dashboard.objects.create(team=self.team, created_by=self.user)
+ DashboardTile.objects.create(dashboard=dashboard, insight=self.insight)
+ deleted_insight = Insight.objects.create(team=self.team, created_by=self.user, deleted=True)
+ create_subscription(
+ team_id=self.team.id, dashboard_id=dashboard.id, dashboard_export_insight_ids=[deleted_insight.id]
+ )
else:
notebook = Notebook.objects.create(
team=self.team,
@@ -2553,16 +2586,25 @@ class TestSaveTimeAccessBlock(APIBaseTest):
response = self._patch_insight_query()
assert response.status_code == status.HTTP_400_BAD_REQUEST, response.content
- assert "publicly shared" in str(response.json())
+ assert expected_reason in str(response.json())
self.insight.refresh_from_db()
assert self.insight.query == {
"kind": "DataTableNode",
"source": {"kind": "HogQLQuery", "query": "SELECT 1 AS one"},
}
- @parameterized.expand([("no_share",), ("deleted_tile",)])
- def test_query_update_allowed_when_not_shared(self, coverage: str):
+ @parameterized.expand(
+ [
+ ("no_share", {}),
+ ("deleted_tile", {}),
+ ("disabled_subscription", {"enabled": False}),
+ ("deleted_subscription", {"deleted": True}),
+ ]
+ )
+ def test_query_update_allowed_when_not_shared(self, coverage: str, subscription_fields: dict):
self._deny_editor()
+ if subscription_fields:
+ create_subscription(team_id=self.team.id, insight_id=self.insight.id, **subscription_fields)
if coverage == "deleted_tile":
dashboard = Dashboard.objects.create(team=self.team, created_by=self.user)
# The shared dashboard also carries a live tile for another insight. A share lookup
@@ -2581,6 +2623,25 @@ class TestSaveTimeAccessBlock(APIBaseTest):
assert response.status_code == status.HTTP_200_OK, response.content
+ def test_restoring_shared_dashboard_blocked_when_a_hidden_insight_changed(self):
+ self._deny_editor()
+ dashboard = Dashboard.objects.create(team=self.team, created_by=self.user)
+ DashboardTile.objects.create(dashboard=dashboard, insight=self.insight)
+ SharingConfiguration.objects.create(team=self.team, dashboard=dashboard, enabled=True)
+ dashboard_url = f"/api/projects/{self.team.id}/dashboards/{dashboard.id}"
+ assert self.client.patch(dashboard_url, {"deleted": True}).status_code == status.HTTP_200_OK
+
+ # The tiles are hidden with the dashboard, so the insight is not shared at this moment.
+ assert self._patch_insight_query().status_code == status.HTTP_200_OK
+
+ response = self.client.patch(dashboard_url, {"deleted": False})
+
+ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.content
+ assert "publicly shared" in str(response.json())
+ dashboard.refresh_from_db()
+ assert dashboard.deleted is True
+ assert not DashboardTile.objects.filter(dashboard=dashboard, insight=self.insight).exists()
+
@parameterized.expand([("stored_query",), ("query_in_same_patch",)])
def test_adding_insight_to_shared_dashboard_blocked(self, coverage: str):
self._deny_editor()
@@ -2607,6 +2668,41 @@ class TestSaveTimeAccessBlock(APIBaseTest):
"source": {"kind": "HogQLQuery", "query": "SELECT 1 AS one"},
}
+ @parameterized.expand(
+ [
+ ("whole_dashboard", status.HTTP_400_BAD_REQUEST),
+ ("insight_selection", status.HTTP_200_OK),
+ ]
+ )
+ def test_adding_insight_to_dashboard_with_subscription(self, coverage: str, expected_status: int):
+ self._deny_editor()
+ self.insight.query = self._DENIED_QUERY
+ self.insight.save()
+ dashboard = Dashboard.objects.create(team=self.team, created_by=self.user)
+ selected_insight_ids: list[int] = []
+ if coverage == "insight_selection":
+ selected_insight = Insight.objects.create(
+ team=self.team,
+ query={"kind": "DataTableNode", "source": {"kind": "HogQLQuery", "query": "SELECT 2 AS two"}},
+ created_by=self.user,
+ )
+ DashboardTile.objects.create(dashboard=dashboard, insight=selected_insight)
+ selected_insight_ids.append(selected_insight.id)
+ create_subscription(
+ team_id=self.team.id, dashboard_id=dashboard.id, dashboard_export_insight_ids=selected_insight_ids
+ )
+
+ response = self.client.patch(
+ f"/api/projects/{self.team.id}/insights/{self.insight.id}/", {"dashboards": [dashboard.id]}
+ )
+
+ assert response.status_code == expected_status, response.content
+ if expected_status == status.HTTP_400_BAD_REQUEST:
+ assert "delivered by a subscription" in str(response.json())
+ assert DashboardTile.objects.filter(dashboard=dashboard, insight=self.insight).exists() == (
+ expected_status == status.HTTP_200_OK
+ )
+
def test_adding_insight_to_unshared_dashboard_allowed(self):
self._deny_editor()
self.insight.query = self._DENIED_QUERY
diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.py
index 30e92026a585..d422316bc5f7 100644
--- a/products/dashboards/backend/api/dashboard.py
+++ b/products/dashboards/backend/api/dashboard.py
@@ -54,18 +54,20 @@ from posthog.api.mixins import ValidatedRequest, validated_request
from posthog.api.monitoring import Feature, monitor
from posthog.api.openapi_parameters import make_filters_override_param, make_variables_override_param
from posthog.api.property_filter_access_gate import table_blocking_property_filters
+from posthog.api.query_access_check import blocked_access_for_user
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import SearchMatchTypeSerializerMixin, UserBasicSerializer
from posthog.api.sharing_publish_gate import (
- check_can_add_insight_to_shared_dashboard,
+ check_can_add_insight_to_dashboard,
dashboard_filter_leaves,
+ dashboard_shared_or_subscribed,
is_publicly_shared,
)
from posthog.api.streaming import sse_streaming_response
from posthog.api.tagged_item import TaggedItemSerializerMixin, TaggedItemViewSetMixin
from posthog.api.utils import action
from posthog.clickhouse.client.async_task_chain import task_chain_context
-from posthog.constants import GENERATED_DASHBOARD_PREFIX
+from posthog.constants import GENERATED_DASHBOARD_PREFIX, AvailableFeature
from posthog.dataclasses import frozen
from posthog.event_usage import EventSource, get_event_source, report_user_action
from posthog.exceptions_capture import capture_exception
@@ -2115,6 +2117,9 @@ class DashboardSerializer(DashboardMetadataSerializer):
being_undeleted = instance.deleted and "deleted" in validated_data and not validated_data["deleted"]
if being_undeleted:
+ self._check_restored_tiles_access(
+ instance, cast(User, self.context["request"].user), self.context["view"].user_access_control
+ )
self._undo_delete_related_tiles(instance)
being_deleted = not instance.deleted and validated_data.get("deleted", False)
@@ -2477,7 +2482,7 @@ class DashboardSerializer(DashboardMetadataSerializer):
# Un-deleting a tile re-exposes its insight on the dashboard's public link.
insight = existing.insight
if became_live and insight is not None:
- check_can_add_insight_to_shared_dashboard(user, instance, insight.query)
+ check_can_add_insight_to_dashboard(user, instance, insight.query)
marking_changed = any(
getattr(existing, field) != tile_defaults[field]
@@ -2703,6 +2708,35 @@ class DashboardSerializer(DashboardMetadataSerializer):
DashboardTile.objects_including_soft_deleted.filter(dashboard__id=instance.id).update(deleted=True)
+ @staticmethod
+ def _check_restored_tiles_access(instance: Dashboard, user: User, user_access_control: UserAccessControl) -> None:
+ """A dashboard restore brings every tile back without a tile write, so the check that
+ gates a single tile restore runs here, once over every insight the restore shows again.
+ An insight can be edited while its dashboard is deleted, so its query may have changed
+ since. The exposure is decided once and the queries compile against one schema, so a
+ restore costs one check rather than one per tile."""
+ if not instance.team.organization.is_feature_available(AvailableFeature.ACCESS_CONTROL):
+ return
+ if user_access_control.is_organization_admin:
+ return
+ exposure = dashboard_shared_or_subscribed(instance)
+ if exposure is None:
+ return
+ queries = [
+ query
+ for query in Insight.objects_including_soft_deleted.filter(
+ dashboard_tiles__dashboard_id=instance.id, dashboard_tiles__deleted=True
+ )
+ .distinct()
+ .values_list("query", flat=True)
+ if isinstance(query, dict)
+ ]
+ if blocked := blocked_access_for_user(user, instance.team, queries):
+ blocked_list = ", ".join(f"`{name}`" for name in blocked)
+ raise serializers.ValidationError(
+ f"Can't restore this dashboard: you don't have access to {blocked_list}, and this dashboard is {exposure}."
+ )
+
@staticmethod
def _undo_delete_related_tiles(instance: Dashboard) -> None:
DashboardTile.objects_including_soft_deleted.filter(dashboard__id=instance.id).update(deleted=False)
@@ -3338,7 +3372,7 @@ class DashboardsViewSet(
DashboardSerializer._check_widget_tile_product_access(tile.widget, user_access_control)
if tile.insight is not None:
# The destination's public link must not expose a query the editor can't run.
- check_can_add_insight_to_shared_dashboard(
+ check_can_add_insight_to_dashboard(
cast(User, request.user), to_dashboard_obj, tile.insight.query, self.user_access_control
)
try:
@@ -3418,7 +3452,7 @@ class DashboardsViewSet(
raise exceptions.ValidationError("This insight is already on the destination dashboard.")
# The destination's public link must not expose a query the editor can't run.
- check_can_add_insight_to_shared_dashboard(
+ check_can_add_insight_to_dashboard(
cast(User, request.user), destination, tile.insight.query, user_access_control
)
elif tile.text is not None:
diff --git a/products/dashboards/backend/facade/api.py b/products/dashboards/backend/facade/api.py
index 4e0079c324fb..ca97f5b65eb6 100644
--- a/products/dashboards/backend/facade/api.py
+++ b/products/dashboards/backend/facade/api.py
@@ -21,7 +21,7 @@ from django.utils.timezone import now
from pydantic.dataclasses import dataclass
from rest_framework import serializers
-from posthog.api.sharing_publish_gate import check_can_add_insight_to_shared_dashboard
+from posthog.api.sharing_publish_gate import check_can_add_insight_to_dashboard
from posthog.helpers.dashboard_templates import create_from_template
from posthog.models.user import User
from posthog.models.user_home_settings import UserHomeSettings
@@ -405,8 +405,8 @@ def plan_insight_tile_placement(
dashboard, "editor"
):
raise CannotAddToDashboard(dashboard.id)
- # The dashboard's public link must not expose a query the editor can't run.
- check_can_add_insight_to_shared_dashboard(user, dashboard, query, user_access_control)
+ # The dashboard's public link or subscription must not expose a query the editor can't run.
+ check_can_add_insight_to_dashboard(user, dashboard, query, user_access_control)
return InsightTilePlacement(dashboards)
@@ -456,8 +456,8 @@ def update_insight_dashboard_membership(
):
raise CannotAddToDashboard(dashboard.id)
- # The dashboard's public link must not expose a query the editor can't run.
- check_can_add_insight_to_shared_dashboard(user, dashboard, query, user_access_control)
+ # The dashboard's public link or subscription must not expose a query the editor can't run.
+ check_can_add_insight_to_dashboard(user, dashboard, query, user_access_control)
tile, _ = DashboardTile.objects_including_soft_deleted.get_or_create(insight=insight, dashboard=dashboard)
if tile.deleted:
diff --git a/products/product_analytics/backend/facade/api.py b/products/product_analytics/backend/facade/api.py
index 3bcc30aee2c2..865b404a465a 100644
--- a/products/product_analytics/backend/facade/api.py
+++ b/products/product_analytics/backend/facade/api.py
@@ -19,7 +19,6 @@ from uuid import UUID
from django.db import transaction
from django.db.models import QuerySet
-from posthog.constants import AvailableFeature
from posthog.models import Team, User
from products.access_control.backend.facade.user_access_control import UserAccessControl
@@ -231,8 +230,7 @@ def user_can_view_insight(*, team: Team, user: User, insight_id: int) -> bool:
def save_saved_insight_query(
*, team: Team, user: User, insight_id: int, expected_query: dict[str, Any], query: dict[str, Any]
) -> str | None:
- from posthog.api.query_access_check import blocked_access_for_user # noqa: PLC0415, I001 — avoids HogQL import cycle
- from posthog.api.sharing_publish_gate import is_publicly_shared # noqa: PLC0415, I001 — avoids HogQL import cycle
+ from posthog.api.sharing_publish_gate import insight_query_access_error # noqa: PLC0415, I001 — avoids HogQL import cycle
with transaction.atomic():
insight = Insight.objects.select_for_update().filter(team=team, pk=insight_id, deleted=False).first()
@@ -245,15 +243,8 @@ def save_saved_insight_query(
"insight", "editor"
) or not access_control.check_access_level_for_object(insight, "editor"):
return "You no longer have permission to edit this insight."
- if (
- insight.team.organization.is_feature_available(AvailableFeature.ACCESS_CONTROL)
- and not access_control.is_organization_admin
- and is_publicly_shared(insight)
- ):
- blocked = blocked_access_for_user(user, insight.team, [query])
- if blocked:
- blocked_list = ", ".join(f"`{name}`" for name in blocked)
- return f"Can't save this query: you don't have access to {blocked_list}, and this insight is publicly shared."
+ if error := insight_query_access_error(user, insight, query, access_control):
+ return error
insight.query = query
insight.saved = True
insight.last_modified_by = user
diff --git a/products/product_analytics/backend/presentation/insight.py b/products/product_analytics/backend/presentation/insight.py
index 59d1950ef88b..485c8d3d98f1 100644
--- a/products/product_analytics/backend/presentation/insight.py
+++ b/products/product_analytics/backend/presentation/insight.py
@@ -44,10 +44,9 @@ from posthog.api.forbid_destroy_model import ForbidDestroyModel
from posthog.api.mixins import ValidatedRequest, validated_request
from posthog.api.monitoring import Feature, monitor
from posthog.api.openapi_parameters import make_filters_override_param, make_variables_override_param
-from posthog.api.query_access_check import blocked_access_for_user
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import SearchMatchTypeSerializerMixin, UserBasicSerializer
-from posthog.api.sharing_publish_gate import is_publicly_shared
+from posthog.api.sharing_publish_gate import insight_query_access_error
from posthog.api.tagged_item import TaggedItemSerializerMixin, TaggedItemViewSetMixin
from posthog.api.utils import action
from posthog.auth import (
@@ -60,7 +59,7 @@ from posthog.caching.insight_result import InsightResult
from posthog.clickhouse.cancel import cancel_query_on_cluster
from posthog.clickhouse.client.limit import ConcurrencyLimitExceeded
from posthog.clickhouse.query_tagging import AccessMethod, get_query_tag_value, tag_queries, tags_context
-from posthog.constants import INSIGHT, AvailableFeature
+from posthog.constants import INSIGHT
from posthog.errors import CHQueryErrorQueryWasCancelled, ExposedCHQueryError, QueryErrorCategory, classify_query_error
from posthog.event_usage import EventSource, get_event_source, get_request_analytics_properties, report_user_action
from posthog.exceptions import ClickHouseAtCapacity
@@ -886,25 +885,15 @@ class InsightSerializer(InsightBasicSerializer):
instance.last_modified_at = now()
instance.last_modified_by = self.context["request"].user
- # Shared links execute without access checks, so an edit that adds a table
- # the editor can't run must not reach a publicly shared surface.
- # Unshared insights save without any access query.
+ # Shared links and subscription deliveries run without access checks, so an edit that adds
+ # a table the editor can't run must not reach them. Other insights save without any access query.
new_query = validated_data.get("query")
- if (
- isinstance(new_query, dict)
- and new_query != instance.query
- and instance.team.organization.is_feature_available(AvailableFeature.ACCESS_CONTROL)
- # org admins have full access, so skip the gate for a faster save
- and not (self.user_access_control and self.user_access_control.is_organization_admin)
- and is_publicly_shared(instance)
+ if new_query != instance.query and (
+ error := insight_query_access_error(
+ self.context["request"].user, instance, new_query, self.user_access_control
+ )
):
- blocked = blocked_access_for_user(self.context["request"].user, instance.team, [new_query])
- if blocked:
- blocked_list = ", ".join(f"`{name}`" for name in blocked)
- raise serializers.ValidationError(
- f"Can't save this query: you don't have access to {blocked_list}, "
- "and this insight is publicly shared."
- )
+ raise serializers.ValidationError(error)
with transaction.atomic():
if validated_data.get("deleted", False):
diff --git a/products/subscriptions/backend/facade/api.py b/products/subscriptions/backend/facade/api.py
index 6bf31cff75eb..60c2f7afd5f7 100644
--- a/products/subscriptions/backend/facade/api.py
+++ b/products/subscriptions/backend/facade/api.py
@@ -53,9 +53,11 @@ __all__ = [
"TEAMS_WEBHOOK_URL_MASKED_ERROR",
"ai_query_plan_status",
"blocked_access_for_subscription",
+ "dashboard_has_active_full_subscription",
"dashboard_ids_with_subscriptions",
"delete_insight_subscriptions",
"failed_delivery_counts",
+ "insight_has_active_subscription",
"insight_ids_with_subscriptions",
"render_shared_insight_image",
"sanitize_prompt",
@@ -137,6 +139,16 @@ def dashboard_ids_with_subscriptions(dashboard_ids: Collection[int]) -> set[int]
)
+def insight_has_active_subscription(insight_id: int) -> bool:
+ """Whether an enabled subscription delivers this insight, directly or as a dashboard tile."""
+ return queries.insight_has_active_subscription(insight_id)
+
+
+def dashboard_has_active_full_subscription(dashboard_id: int) -> bool:
+ """Whether an enabled subscription delivers every insight on this dashboard."""
+ return queries.dashboard_has_active_full_subscription(dashboard_id)
+
+
def should_check_table_access(*, team_id: int, subscription_id: int | None, attrs: dict[str, Any]) -> bool:
"""Whether a subscription write must pass the table-access check: a create, a change to what
is delivered or to who receives it, or a write that enables or restores the subscription."""
diff --git a/products/subscriptions/backend/logic/queries.py b/products/subscriptions/backend/logic/queries.py
index ba999886e2ef..d229db7d71e1 100644
--- a/products/subscriptions/backend/logic/queries.py
+++ b/products/subscriptions/backend/logic/queries.py
@@ -1,7 +1,7 @@
from collections.abc import Collection
from datetime import datetime
-from django.db.models import Count, Max
+from django.db.models import Count, Max, QuerySet
from products.subscriptions.backend.facade.contracts import FailedDeliveryCount
from products.subscriptions.backend.models.subscription import Subscription, SubscriptionDelivery
@@ -33,3 +33,52 @@ def failed_delivery_counts(*, team_id: int, since: datetime, limit: int) -> list
def subscription_ids_in_team(*, team_id: int, subscription_ids: Collection[int]) -> set[int]:
return set(Subscription.objects.filter(team_id=team_id, id__in=subscription_ids).values_list("id", flat=True))
+
+
+def _active_subscriptions() -> QuerySet[Subscription]:
+ # Callers pass the id of an artifact they already scoped to their team, and ids are unique, so
+ # the lookup needs no team filter.
+ # nosemgrep: idor-lookup-without-team
+ return Subscription.objects.filter(deleted=False, enabled=True)
+
+
+def insight_has_active_subscription(insight_id: int) -> bool:
+ """Decide if an enabled subscription delivers this insight.
+
+ A subscription delivers the insight in three cases: it targets the insight, its dashboard
+ selection names the insight, or it has no live selected insight and the insight is a tile of
+ its dashboard. A deleted tile counts, and so does a tile of a deleted dashboard: a restore of
+ the tile or the dashboard starts delivery again without a subscription write, so the insight
+ edit check must stay in place while the tile is hidden.
+
+ A disabled or deleted subscription does not count. Enabling or restoring it runs the
+ subscription save check on the requester.
+ """
+ active = _active_subscriptions()
+ if active.filter(insight_id=insight_id).exists():
+ return True
+ if active.filter(dashboard_export_insights=insight_id).exists():
+ return True
+ return (
+ active.filter(dashboard__tiles__insight_id=insight_id)
+ .exclude(dashboard_export_insights__deleted=False)
+ .exists()
+ )
+
+
+def dashboard_has_active_full_subscription(dashboard_id: int) -> bool:
+ """Decide if an enabled subscription delivers every insight on this dashboard. Such a
+ subscription also delivers an insight that is added after the subscription was saved.
+
+ A subscription with a live insight in its selection does not count, because it does not
+ deliver a tile outside its selection. A selection whose insights are all deleted counts as no
+ selection, because the delivery then exports every live tile. A disabled or deleted
+ subscription does not count. Enabling or restoring it runs the subscription save check on the
+ requester.
+ """
+ return (
+ _active_subscriptions()
+ .filter(dashboard_id=dashboard_id)
+ .exclude(dashboard_export_insights__deleted=False)
+ .exists()
+ )
diff --git a/products/subscriptions/backend/logic/subscription_query_access.py b/products/subscriptions/backend/logic/subscription_query_access.py
index 57c174665177..09cc10fd337b 100644
--- a/products/subscriptions/backend/logic/subscription_query_access.py
+++ b/products/subscriptions/backend/logic/subscription_query_access.py
@@ -62,22 +62,26 @@ def should_check_table_access(*, team_id: int, subscription_id: int | None, attr
def delivered_queries(instance: Subscription | None, attrs: dict[str, Any]) -> list[dict[str, Any]]:
"""The saved queries of the insights a delivery exports once this write is applied.
- The selection matches `_resolve_exportable_insights` in the delivery activities: the selected
- insights that are still live tiles of the dashboard, every live tile when there is no
- selection, or the single insight of an insight subscription.
+ The selection follows `_resolve_exportable_insights` in the delivery activities: the selected
+ insights of the dashboard, every live tile when there is no selection, or the single insight
+ of an insight subscription. A selected insight counts even while its tile is soft-deleted: a
+ tile restore brings it back into the delivery without a subscription write, so the check
+ covers it now rather than never.
"""
dashboard = attrs["dashboard"] if "dashboard" in attrs else (instance.dashboard if instance else None)
if dashboard is not None:
if dashboard.deleted:
return []
- live_tiles = dashboard.tiles.filter(insight__isnull=False, insight__deleted=False)
if "dashboard_export_insights" in attrs:
selected_ids = list(attrs["dashboard_export_insights"])
else:
selected_ids = list(instance.dashboard_export_insights.values_list("id", flat=True)) if instance else []
if selected_ids:
- live_tiles = live_tiles.filter(insight_id__in=selected_ids)
- return [query for query in live_tiles.values_list("insight__query", flat=True) if isinstance(query, dict)]
+ tiles = dashboard.tiles(manager="objects_including_soft_deleted").filter(insight_id__in=selected_ids)
+ else:
+ tiles = dashboard.tiles.all()
+ queries = tiles.filter(insight__isnull=False, insight__deleted=False).values_list("insight__query", flat=True)
+ return [query for query in queries if isinstance(query, dict)]
insight = attrs["insight"] if "insight" in attrs else (instance.insight if instance else None)
if insight is not None and not insight.deleted and isinstance(insight.query, dict):
diff --git a/products/subscriptions/backend/tests/test_subscription.py b/products/subscriptions/backend/tests/test_subscription.py
index 6bb835289956..e692c72369cf 100644
--- a/products/subscriptions/backend/tests/test_subscription.py
+++ b/products/subscriptions/backend/tests/test_subscription.py
@@ -4846,6 +4846,24 @@ class TestSubscriptionObjectAccessControl(APILicensedTest):
assert response.status_code == status.HTTP_201_CREATED, response.json()
+ def test_update_recipients_is_rejected_when_a_selected_tile_is_hidden(self):
+ insight = self._insight_over_a_governed_view()
+ dashboard = self._dashboard_with_tiles(insight)
+ subscription = self._subscription_for(dashboard=dashboard)
+ subscription.dashboard_export_insights.add(insight)
+ # A hidden tile leaves the delivery; a tile restore brings it back without a subscription write.
+ DashboardTile.objects.filter(dashboard=dashboard, insight=insight).update(deleted=True)
+ self._deny_warehouse_tables()
+
+ with patch(WAREHOUSE_ACCESS_CONTROL_FLAG, return_value=True):
+ response = self.client.patch(
+ f"/api/projects/{self.team.id}/subscriptions/{subscription.id}",
+ {"target_value": "[email protected]"},
+ )
+
+ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()
+ assert "governed_view" in response.json()["detail"]
+
@parameterized.expand(
[
("a new recipient", {}, {"target_value": "[email protected]"}, status.HTTP_400_BAD_REQUEST),