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.

chore: rename the table-access helpers to denied_* names (#122368)

Alex Lider06724e0a9d7a
diff --git a/ee/hogai/tools/test/test_create_insight.py b/ee/hogai/tools/test/test_create_insight.py
index 700c6695dadc..19d3135b3f8d 100644
--- a/ee/hogai/tools/test/test_create_insight.py
+++ b/ee/hogai/tools/test/test_create_insight.py
@@ -238,7 +238,7 @@ class TestCreateInsightTool(ClickhouseTestMixin, NonAtomicBaseTest):
else:
await database_sync_to_async(create_subscription)(team_id=self.team.id, insight_id=insight.id)
- with patch("posthog.api.sharing_publish_gate.blocked_access_for_user", return_value=["restricted table"]):
+ with patch("posthog.api.sharing_publish_gate.denied_query_resources", return_value=["restricted table"]):
with self.assertRaisesRegex(MaxToolRetryableError, expected_reason):
await tool._save_insight_query(insight, {"kind": "TrendsQuery", "series": [], "interval": "week"})
diff --git a/ee/hogai/tools/upsert_dashboard/test/test_tool.py b/ee/hogai/tools/upsert_dashboard/test/test_tool.py
index f051cbb96913..14555b2f9636 100644
--- a/ee/hogai/tools/upsert_dashboard/test/test_tool.py
+++ b/ee/hogai/tools/upsert_dashboard/test/test_tool.py
@@ -258,7 +258,7 @@ class TestUpsertDashboardTool(BaseTest):
self.assertEqual(len(insight_created_events), 0 if source == "saved" else 1)
@parameterized.expand([("saved", True), ("restored", True), ("generated", True), ("saved", False)])
- @patch("posthog.api.sharing_publish_gate.blocked_access_for_user", return_value=["restricted_table"])
+ @patch("posthog.api.sharing_publish_gate.denied_query_resources", return_value=["restricted_table"])
async def test_add_insights_enforces_shared_dashboard_access(
self, source: str, shared: bool, _mock_blocked: MagicMock
) -> None:
@@ -346,7 +346,7 @@ class TestUpsertDashboardTool(BaseTest):
@parameterized.expand([("new_tile",), ("restored_tile",)])
@patch(
- "posthog.api.sharing_publish_gate.blocked_access_for_user",
+ "posthog.api.sharing_publish_gate.denied_query_resources",
return_value=["restricted_table"],
)
async def test_update_dashboard_enforces_subscribed_dashboard_access(
diff --git a/posthog/api/query_access_check.py b/posthog/api/query_access_check.py
index 94625f80ebda..0221bba7a8fa 100644
--- a/posthog/api/query_access_check.py
+++ b/posthog/api/query_access_check.py
@@ -17,7 +17,7 @@ from posthog.models import Team, User
from products.access_control.backend.facade.user_access_control import UserAccessControlError
-def blocked_access_for_user(user: User, team: Team, queries: list[dict[str, Any]]) -> list[str]:
+def denied_query_resources(user: User, team: Team, queries: list[dict[str, Any]]) -> list[str]:
"""Tables (and runner-level resources) the user can't access among everything the given
queries read. Each query is compiled (resolved, not executed) as the user, the same resolution
the read path uses. Non-access compile errors don't gate. Empty list = the user can run them all."""
@@ -28,7 +28,7 @@ def blocked_access_for_user(user: User, team: Team, queries: list[dict[str, Any]
# query's own modifiers must shape it, because a warehouse events mapping can put an expression
# into the schema, and the run would compile that expression against the same modifiers.
contexts: dict[str, HogQLContext] = {}
- blocked: set[str] = set()
+ denied_resources: set[str] = set()
for query in queries:
try:
# get_query_runner unwraps container nodes (DataTableNode, InsightVizNode, ...) itself.
@@ -46,10 +46,10 @@ def blocked_access_for_user(user: User, team: Team, queries: list[dict[str, Any]
)
prepare_ast_for_printing(runner.to_query(), context=context, dialect="clickhouse")
except UserAccessControlError as e:
- blocked.add(e.resource)
+ denied_resources.add(e.resource)
except TableAccessDeniedError as e:
- blocked.add(e.table_name)
+ denied_resources.add(e.table_name)
except Exception:
# Only access denials gate publishing; anything else is the query's own problem.
continue
- return sorted(blocked)
+ return sorted(denied_resources)
diff --git a/posthog/api/sharing.py b/posthog/api/sharing.py
index 7f4d79ea90d8..f57f9a239cf4 100644
--- a/posthog/api/sharing.py
+++ b/posthog/api/sharing.py
@@ -30,7 +30,7 @@ from posthog.api.data_color_theme import DataColorTheme, PublicDataColorThemeSer
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.services.query import process_query_dict
from posthog.api.shared import TeamPublicSerializer
-from posthog.api.sharing_publish_gate import blocked_access_for_publisher
+from posthog.api.sharing_publish_gate import denied_resources_in_share
from posthog.auth import (
SharingAccessTokenAuthentication,
SharingPasswordProtectedAuthentication,
@@ -559,11 +559,11 @@ class SharingConfigurationViewSet(
# org admins have full access, so skip the gate for a faster enable
and not self.user_access_control.is_organization_admin
):
- blocked_names = blocked_access_for_publisher(cast(User, request.user), self.team, instance)
- if blocked_names:
- blocked = ", ".join(f"`{name}`" for name in blocked_names)
+ denied_resources = denied_resources_in_share(cast(User, request.user), self.team, instance)
+ if denied_resources:
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
raise ValidationError(
- f"Can't enable sharing: you don't have access to {blocked}, "
+ f"Can't enable sharing: you don't have access to {denied_names}, "
"which the shared queries use. Ask an admin for access, or remove those queries first."
)
diff --git a/posthog/api/sharing_publish_gate.py b/posthog/api/sharing_publish_gate.py
index ad2e0c20ba4e..9af835cb5c9e 100644
--- a/posthog/api/sharing_publish_gate.py
+++ b/posthog/api/sharing_publish_gate.py
@@ -16,7 +16,7 @@ from rest_framework import serializers
from posthog.hogql.escape_sql import backquote_escape_chars_map
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.query_access_check import denied_query_resources
from posthog.constants import AvailableFeature
from posthog.models import Team, User
from posthog.models.sharing_configuration import SharingConfiguration
@@ -75,11 +75,11 @@ def insight_query_access_error(
exposure = insight_shared_or_subscribed(insight)
if exposure is None:
return None
- blocked = blocked_access_for_user(user, insight.team, [query])
- if not blocked:
+ denied_resources = denied_query_resources(user, insight.team, [query])
+ if not denied_resources:
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}."
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
+ return f"Can't save this query: you don't have access to {denied_names}, and this insight is {exposure}."
def check_can_add_insight_to_dashboard(
@@ -103,31 +103,31 @@ def check_can_add_insight_to_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)
+ denied_resources = denied_query_resources(user, dashboard.team, [query])
+ if denied_resources:
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
raise serializers.ValidationError(
- f"Can't add this insight: you don't have access to {blocked_list}, and this dashboard is {exposure}."
+ f"Can't add this insight: you don't have access to {denied_names}, and this dashboard is {exposure}."
)
-def blocked_access_for_publisher(user: User, team: Team, config: SharingConfiguration) -> list[str]:
+def denied_resources_in_share(user: User, team: Team, config: SharingConfiguration) -> list[str]:
"""
Tables and runner-level resources that stop the publisher from running the shared
artifact's queries. Each query is compiled (resolved, not executed) as the publisher,
the same resolution the read path uses. Non-access compile errors don't gate.
Empty list = safe to publish.
"""
- blocked = blocked_access_for_user(user, team, _queries_exposed_by(config))
+ denied_resources = denied_query_resources(user, team, _queries_exposed_by(config))
# A dashboard's own filters and tile overrides run inside every tile, and they could have
# been saved before the dashboard was shared, when the save-time check did not apply.
if config.dashboard is not None:
leaves = dashboard_filter_leaves(config.dashboard.filters)
for overrides in config.dashboard.tiles.values_list("filters_overrides", flat=True):
leaves += dashboard_filter_leaves(overrides)
- if (table := table_blocking_property_filters(user, team, leaves)) and table not in blocked:
- blocked = sorted([*blocked, table])
- return blocked
+ if (table := table_blocking_property_filters(user, team, leaves)) and table not in denied_resources:
+ denied_resources = sorted([*denied_resources, table])
+ return denied_resources
def dashboard_filter_leaves(filters: Any) -> list[dict[str, Any]]:
@@ -222,7 +222,7 @@ def is_publicly_shared(artifact: "Dashboard | Notebook | Insight") -> bool:
).exists()
-def blocked_access_in_notebook_edit(user: User, notebook: Any, new_content: dict[str, Any] | None) -> list[str]:
+def denied_resources_in_notebook_edit(user: User, notebook: Any, new_content: dict[str, Any] | None) -> list[str]:
"""Only queries the edit adds or changes are checked,
so untouched content (and anything mid-typing that doesn't resolve) never gates."""
old_content = notebook.content or {}
@@ -242,4 +242,4 @@ def blocked_access_in_notebook_edit(user: User, notebook: Any, new_content: dict
).values_list("query", flat=True)
if isinstance(q, dict)
)
- return blocked_access_for_user(user, notebook.team, changed_queries)
+ return denied_query_resources(user, notebook.team, changed_queries)
diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.py
index d422316bc5f7..c7e0a0c94f10 100644
--- a/products/dashboards/backend/api/dashboard.py
+++ b/products/dashboards/backend/api/dashboard.py
@@ -54,7 +54,7 @@ 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.query_access_check import denied_query_resources
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import SearchMatchTypeSerializerMixin, UserBasicSerializer
from posthog.api.sharing_publish_gate import (
@@ -2731,10 +2731,10 @@ class DashboardSerializer(DashboardMetadataSerializer):
.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)
+ if denied_resources := denied_query_resources(user, instance.team, queries):
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
raise serializers.ValidationError(
- f"Can't restore this dashboard: you don't have access to {blocked_list}, and this dashboard is {exposure}."
+ f"Can't restore this dashboard: you don't have access to {denied_names}, and this dashboard is {exposure}."
)
@staticmethod
diff --git a/products/notebooks/backend/logic.py b/products/notebooks/backend/logic.py
index 216b523ea1be..d0ed7ee8dcc0 100644
--- a/products/notebooks/backend/logic.py
+++ b/products/notebooks/backend/logic.py
@@ -33,7 +33,7 @@ if TYPE_CHECKING:
def _validate_shared_notebook_edit(user: "User", notebook: Notebook, content: dict[str, Any]) -> None:
from posthog.api.sharing_publish_gate import ( # noqa: PLC0415 — keep query runners off the facade import path
- blocked_access_in_notebook_edit,
+ denied_resources_in_notebook_edit,
is_publicly_shared,
)
@@ -43,11 +43,11 @@ def _validate_shared_notebook_edit(user: "User", notebook: Notebook, content: di
return
if not is_publicly_shared(notebook):
return
- blocked = blocked_access_in_notebook_edit(user, notebook, content)
- if blocked:
- blocked_list = ", ".join(f"`{name}`" for name in blocked)
+ denied_resources = denied_resources_in_notebook_edit(user, notebook, content)
+ if denied_resources:
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
raise NotebookContentEditNotAllowed(
- f"Can't save: you don't have access to {blocked_list}, and this notebook is publicly shared."
+ f"Can't save: you don't have access to {denied_names}, and this notebook is publicly shared."
)
diff --git a/products/notebooks/backend/presentation/views/notebook.py b/products/notebooks/backend/presentation/views/notebook.py
index 1977b63f11b7..bc78b70a9da8 100644
--- a/products/notebooks/backend/presentation/views/notebook.py
+++ b/products/notebooks/backend/presentation/views/notebook.py
@@ -34,7 +34,7 @@ from posthog.hogql.direct_connection import get_direct_connection_source
from posthog.api.forbid_destroy_model import ForbidDestroyModel
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import UserBasicSerializer
-from posthog.api.sharing_publish_gate import blocked_access_in_notebook_edit, is_publicly_shared
+from posthog.api.sharing_publish_gate import denied_resources_in_notebook_edit, is_publicly_shared
from posthog.api.streaming import sse_streaming_response
from posthog.api.utils import action
from posthog.auth import SessionAuthentication
@@ -449,13 +449,13 @@ class NotebookSerializer(NotebookMinimalSerializer):
and not (self.user_access_control and self.user_access_control.is_organization_admin)
and is_publicly_shared(locked_instance)
):
- blocked = blocked_access_in_notebook_edit(
+ denied_resources = denied_resources_in_notebook_edit(
self.context["request"].user, locked_instance, validated_data.get("content")
)
- if blocked:
- blocked_list = ", ".join(f"`{name}`" for name in blocked)
+ if denied_resources:
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
raise serializers.ValidationError(
- f"Can't save: you don't have access to {blocked_list}, "
+ f"Can't save: you don't have access to {denied_names}, "
"and this notebook is publicly shared."
)
@@ -2503,11 +2503,11 @@ class NotebookViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, ForbidD
and not self.user_access_control.is_organization_admin
and is_publicly_shared(notebook)
):
- blocked = blocked_access_in_notebook_edit(user, notebook, data.get("content"))
- if blocked:
- blocked_list = ", ".join(f"`{name}`" for name in blocked)
+ denied_resources = denied_resources_in_notebook_edit(user, notebook, data.get("content"))
+ if denied_resources:
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
raise serializers.ValidationError(
- f"Can't save: you don't have access to {blocked_list}, and this notebook is publicly shared."
+ f"Can't save: you don't have access to {denied_names}, and this notebook is publicly shared."
)
result = submit_steps(
@@ -2605,11 +2605,11 @@ class NotebookViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, ForbidD
and not self.user_access_control.is_organization_admin
and is_publicly_shared(notebook)
):
- blocked = blocked_access_in_notebook_edit(user, notebook, submitted_content)
- if blocked:
- blocked_list = ", ".join(f"`{name}`" for name in blocked)
+ denied_resources = denied_resources_in_notebook_edit(user, notebook, submitted_content)
+ if denied_resources:
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
raise serializers.ValidationError(
- f"Can't save: you don't have access to {blocked_list}, and this notebook is publicly shared."
+ f"Can't save: you don't have access to {denied_names}, and this notebook is publicly shared."
)
notebook_before: Notebook | None = None
diff --git a/products/subscriptions/backend/logic/subscription_query_access.py b/products/subscriptions/backend/logic/subscription_query_access.py
index 09cc10fd337b..71b408354a88 100644
--- a/products/subscriptions/backend/logic/subscription_query_access.py
+++ b/products/subscriptions/backend/logic/subscription_query_access.py
@@ -9,7 +9,7 @@ delivery.
from typing import Any
-from posthog.api.query_access_check import blocked_access_for_user
+from posthog.api.query_access_check import denied_query_resources
from posthog.constants import AvailableFeature
from posthog.models.team import Team
from posthog.models.user import User
@@ -89,7 +89,7 @@ def delivered_queries(instance: Subscription | None, attrs: dict[str, Any]) -> l
return []
-def blocked_access_for_subscription(
+def denied_resources_in_subscription(
*,
user: User,
team: Team,
@@ -108,4 +108,4 @@ def blocked_access_for_subscription(
return []
if user_access_control.is_organization_admin:
return []
- return blocked_access_for_user(user, team, delivered_queries(_subscription(team.id, subscription_id), attrs))
+ return denied_query_resources(user, team, delivered_queries(_subscription(team.id, subscription_id), attrs))
diff --git a/products/subscriptions/backend/logic/subscription_writes.py b/products/subscriptions/backend/logic/subscription_writes.py
index 6cd9cbab002c..7e257e662559 100644
--- a/products/subscriptions/backend/logic/subscription_writes.py
+++ b/products/subscriptions/backend/logic/subscription_writes.py
@@ -50,7 +50,7 @@ from products.subscriptions.backend.facade.contracts import (
)
from products.subscriptions.backend.logic.auto_disable import validate_re_enable
from products.subscriptions.backend.logic.subscription_query_access import (
- blocked_access_for_subscription,
+ denied_resources_in_subscription,
should_check_table_access,
)
from products.subscriptions.backend.logic.subscription_utils import MAX_INSIGHTS
@@ -542,16 +542,18 @@ class _SubscriptionWrite:
requester: object = self.user
if not isinstance(requester, User):
return
- blocked_names = blocked_access_for_subscription(
+ denied_resources = denied_resources_in_subscription(
user=requester,
team=self.team,
user_access_control=self.viewer,
subscription_id=subscription_id,
attrs=attrs,
)
- if blocked_names:
- blocked = ", ".join(f"`{name}`" for name in blocked_names)
- raise SubscriptionRequestInvalidError(f"Can't save this subscription: you don't have access to {blocked}.")
+ if denied_resources:
+ denied_names = ", ".join(f"`{name}`" for name in denied_resources)
+ raise SubscriptionRequestInvalidError(
+ f"Can't save this subscription: you don't have access to {denied_names}."
+ )
def _is_becoming_active_summary(self, attrs: dict) -> bool:
pre_summary_enabled = self.instance.summary_enabled if self.instance else False