: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(visual_review): allow tolerate via personal API keys (#60749)
Paul D'Ambraa8b93e729344
diff --git a/products/visual_review/backend/presentation/views.py b/products/visual_review/backend/presentation/views.pyindex 4b1ed1a645b7..38060f7df17c 100644--- a/products/visual_review/backend/presentation/views.py+++ b/products/visual_review/backend/presentation/views.py@@ -356,7 +356,15 @@ class RunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):"""scope_object = "visual_review"- scope_object_write_actions = ["create", "complete", "approve", "auto_approve", "add_snapshots", "recompute"]+ scope_object_write_actions = [+ "create",+ "complete",+ "approve",+ "auto_approve",+ "add_snapshots",+ "recompute",+ "mark_tolerated",+ ]scope_object_read_actions = ["list", "retrieve", "snapshots", "counts", "snapshot_history", "tolerated_hashes"]serializer_class = RunSerializerdiff --git a/products/visual_review/backend/tests/test_presentation.py b/products/visual_review/backend/tests/test_presentation.pyindex 4d69c4cdb7fe..484f9ffc3f7e 100644--- a/products/visual_review/backend/tests/test_presentation.py+++ b/products/visual_review/backend/tests/test_presentation.py@@ -6,6 +6,7 @@ from uuid import uuid4from posthog.test.base import APIBaseTestfrom unittest.mock import patch+from parameterized import parameterizedfrom rest_framework import statusfrom products.visual_review.backend import logic@@ -194,6 +195,53 @@ class TestRunViewSet(VisualReviewTeamScopedTestMixin, APIBaseTest):# Per-snapshot approval is DB only — run not finalizedself.assertFalse(response.json()["run"]["approved"])+ def _changed_snapshot_for_tolerate(self) -> tuple[str, str]:+ logic.get_or_create_artifact(+ repo_id=self.vr_project.id,+ content_hash="new_hash",+ storage_path="visual_review/new_hash",+ )+ create_result = api.create_run(+ CreateRunInput(+ repo_id=self.vr_project.id,+ run_type=RunType.STORYBOOK,+ commit_sha="abc123",+ branch="main",+ snapshots=[SnapshotManifestItem(identifier="Button", content_hash="new_hash")],+ baseline_hashes={"Button": "old_hash"},+ ),+ team_id=self.team.id,+ )+ snapshot = RunSnapshot.objects.get(run_id=create_result.run_id, identifier="Button")+ # The diff pipeline normally classifies the snapshot — short-circuit it here+ # so the test stays a permission-boundary test rather than an integration test.+ snapshot.result = SnapshotResult.CHANGED+ snapshot.save(update_fields=["result"])+ return str(create_result.run_id), str(snapshot.id)++ @parameterized.expand(+ [+ ("session_auth", None, status.HTTP_200_OK),+ ("personal_api_key_write_scope", "visual_review:write", status.HTTP_200_OK),+ ("personal_api_key_read_scope", "visual_review:read", status.HTTP_403_FORBIDDEN),+ ]+ )+ def test_mark_tolerated_permission_boundary(self, _name: str, scope: str | None, expected_status: int):+ run_id, snapshot_id = self._changed_snapshot_for_tolerate()++ if scope is not None:+ key = self.create_personal_api_key_with_scopes([scope])+ self.client.logout()+ self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {key}")++ response = self.client.post(+ f"/api/projects/{self.team.id}/visual_review/runs/{run_id}/tolerate/",+ {"snapshot_id": snapshot_id},+ format="json",+ )++ assert response.status_code == expected_status, response.json()+def _seed_history_row(self,sha: str,