:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(error-tracking): support scoped auth for all endpoints (#77260)
Hugues Pouillot0d23da7f9a4d
diff --git a/products/error_tracking/backend/presentation/views/assignment_rules.py b/products/error_tracking/backend/presentation/views/assignment_rules.pyindex 3c4e9758e905..b9f39fe15bbb 100644--- a/products/error_tracking/backend/presentation/views/assignment_rules.py+++ b/products/error_tracking/backend/presentation/views/assignment_rules.py@@ -129,6 +129,7 @@ class ErrorTrackingAssignmentRuleSerializer(serializers.Serializer):class ErrorTrackingAssignmentRuleViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):scope_object = "error_tracking"+ scope_object_write_actions = ["create", "update", "partial_update", "destroy", "reorder"]serializer_class = ErrorTrackingAssignmentRuleSerializerdef list(self, request, *args, **kwargs) -> Response:diff --git a/products/error_tracking/backend/presentation/views/bypass_rules.py b/products/error_tracking/backend/presentation/views/bypass_rules.pyindex b9a4f1c843db..a13dcbf22b14 100644--- a/products/error_tracking/backend/presentation/views/bypass_rules.py+++ b/products/error_tracking/backend/presentation/views/bypass_rules.py@@ -83,6 +83,7 @@ class ErrorTrackingBypassRuleUpdateRequestSerializer(serializers.Serializer):class ErrorTrackingBypassRuleViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):scope_object = "error_tracking"+ scope_object_write_actions = ["create", "update", "partial_update", "destroy", "reorder"]serializer_class = ErrorTrackingBypassRuleSerializerdef list(self, request, *args, **kwargs) -> Response:diff --git a/products/error_tracking/backend/presentation/views/git_provider_file_link_resolver.py b/products/error_tracking/backend/presentation/views/git_provider_file_link_resolver.pyindex 54e40d379058..b0318dd89921 100644--- a/products/error_tracking/backend/presentation/views/git_provider_file_link_resolver.py+++ b/products/error_tracking/backend/presentation/views/git_provider_file_link_resolver.py@@ -259,6 +259,7 @@ def get_gitlab_file_url(class GitProviderFileLinksViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):scope_object = "error_tracking"+ scope_object_read_actions = ["resolve_github", "resolve_gitlab"]@extend_schema(parameters=[GitProviderFileLinkResolveQuerySerializer],diff --git a/products/error_tracking/backend/presentation/views/grouping_rules.py b/products/error_tracking/backend/presentation/views/grouping_rules.pyindex 421c7b0e3778..b3e078f5600f 100644--- a/products/error_tracking/backend/presentation/views/grouping_rules.py+++ b/products/error_tracking/backend/presentation/views/grouping_rules.py@@ -141,6 +141,7 @@ class ErrorTrackingGroupingRuleListResponseSerializer(serializers.Serializer):class ErrorTrackingGroupingRuleViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):scope_object = "error_tracking"+ scope_object_write_actions = ["create", "update", "partial_update", "destroy", "reorder"]serializer_class = ErrorTrackingGroupingRuleSerializer# The list endpoint returns all rules unpaginated ({"results": [...]}); without this the# default paginator makes the schema advertise limit/offset params the view doesn't honor.diff --git a/products/error_tracking/backend/presentation/views/spike_detection_config.py b/products/error_tracking/backend/presentation/views/spike_detection_config.pyindex 60948b6f1cbc..621a9d74d1f9 100644--- a/products/error_tracking/backend/presentation/views/spike_detection_config.py+++ b/products/error_tracking/backend/presentation/views/spike_detection_config.py@@ -25,6 +25,7 @@ class ErrorTrackingSpikeDetectionConfigSerializer(serializers.Serializer):class ErrorTrackingSpikeDetectionConfigViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):scope_object = "error_tracking"+ scope_object_write_actions = ["update_config"]@extend_schema(responses={200: ErrorTrackingSpikeDetectionConfigSerializer})def list(self, request, *args, **kwargs):diff --git a/products/error_tracking/backend/presentation/views/suppression_rules.py b/products/error_tracking/backend/presentation/views/suppression_rules.pyindex 1181360e2c9a..b6f129f0f0f3 100644--- a/products/error_tracking/backend/presentation/views/suppression_rules.py+++ b/products/error_tracking/backend/presentation/views/suppression_rules.py@@ -90,6 +90,7 @@ class ErrorTrackingSuppressionRuleUpdateRequestSerializer(serializers.Serializerclass ErrorTrackingSuppressionRuleViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):scope_object = "error_tracking"+ scope_object_write_actions = ["create", "update", "partial_update", "destroy", "reorder"]serializer_class = ErrorTrackingSuppressionRuleSerializerdef list(self, request, *args, **kwargs) -> Response:diff --git a/products/error_tracking/backend/presentation/views/symbol_sets.py b/products/error_tracking/backend/presentation/views/symbol_sets.pyindex 89490a20c6ab..9d5b4dfa1cb5 100644--- a/products/error_tracking/backend/presentation/views/symbol_sets.py+++ b/products/error_tracking/backend/presentation/views/symbol_sets.py@@ -137,6 +137,8 @@ class ErrorTrackingSymbolSetViewSet(TeamAndOrgViewSetMixin, viewsets.GenericView"bulk_finish_upload","start_upload","finish_upload",+ "update",+ "partial_update","destroy","bulk_delete","create",diff --git a/products/error_tracking/backend/tests/api/test_api_scopes.py b/products/error_tracking/backend/tests/api/test_api_scopes.pynew file mode 100644index 000000000000..81aeeb9c33bc--- /dev/null+++ b/products/error_tracking/backend/tests/api/test_api_scopes.py@@ -0,0 +1,45 @@+from typing import Any, cast++from django.test import SimpleTestCase++from rest_framework.viewsets import ViewSetMixin++from posthog.api.forbid_destroy_model import ForbidDestroyModel+from posthog.permissions import ScopeBasePermission++from products.error_tracking.backend.routes import register_routes+++class _RouteCollector:+ def __init__(self) -> None:+ self.projects = self+ self.viewsets: list[type[ViewSetMixin]] = []++ def register(self, _prefix: str, viewset: type[ViewSetMixin], _basename: str, _parents: list[str]) -> None:+ self.viewsets.append(viewset)+++class TestErrorTrackingAPIScopes(SimpleTestCase):+ def test_all_registered_actions_support_scoped_authentication(self) -> None:+ routes = _RouteCollector()+ register_routes(cast(Any, routes))++ missing_actions: list[str] = []+ standard_actions = set(ScopeBasePermission.read_actions + ScopeBasePermission.write_actions)++ for viewset in routes.viewsets:+ actions = {action.__name__ for action in viewset.get_extra_actions()}+ actions.update(action for action in standard_actions if callable(getattr(viewset, action, None)))++ read_actions = set(getattr(viewset, "scope_object_read_actions", ScopeBasePermission.read_actions))+ write_actions = set(getattr(viewset, "scope_object_write_actions", ScopeBasePermission.write_actions))++ for action in actions:+ action_method: Any = getattr(viewset, action)+ if action_method is ForbidDestroyModel.destroy:+ continue+ required_scopes = getattr(action_method, "kwargs", {}).get("required_scopes")+ if action not in read_actions | write_actions and not required_scopes:+ missing_actions.append(f"{viewset.__name__}.{action}")++ self.assertEqual(missing_actions, [])