:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(canvas): store canvas comments under the canvas scope (#107353)
Shy Altere0ce3c3a4924
diff --git a/posthog/api/test/test_comments.py b/posthog/api/test/test_comments.pyindex 0a4b8198e970..7409bbc6fe1e 100644--- a/posthog/api/test/test_comments.py+++ b/posthog/api/test/test_comments.py@@ -837,7 +837,7 @@ class TestComments(APIBaseTest, QueryMatchingTest):team=self.team, channel=channel, name="Scoped canvas", created_by=self.user)earlier = Comment.objects.create(- team=self.team, scope="canvas", item_id=str(canvas.id), content="Earlier", created_by=self.user+ team=self.team, scope="desktop_canvas", item_id=str(canvas.id), content="Earlier", created_by=self.user)created = self.client.post(@@ -851,9 +851,9 @@ class TestComments(APIBaseTest, QueryMatchingTest):)assert created.status_code == status.HTTP_201_CREATED- assert created.json()["scope"] == "desktop_canvas"- assert Comment.objects.get(id=created.json()["id"]).scope == "desktop_canvas"- expected = sorted([(created.json()["id"], "desktop_canvas"), (str(earlier.id), "desktop_canvas")])+ assert created.json()["scope"] == "canvas"+ assert Comment.objects.get(id=created.json()["id"]).scope == "canvas"+ expected = sorted([(created.json()["id"], "canvas"), (str(earlier.id), "canvas")])for scope in ("canvas", "desktop_canvas"):listed = self.client.get(f"/api/projects/{self.team.id}/comments?scope={scope}&item_id={canvas.id}")assert sorted((row["id"], row["scope"]) for row in listed.json()["results"]) == expecteddiff --git a/posthog/migrations/1390_rename_desktop_canvas_comment_scope.py b/posthog/migrations/1390_rename_desktop_canvas_comment_scope.pynew file mode 100644index 000000000000..a4f8290bd001--- /dev/null+++ b/posthog/migrations/1390_rename_desktop_canvas_comment_scope.py@@ -0,0 +1,26 @@+from django.apps.registry import Apps+from django.db import migrations+from django.db.backends.base.schema import BaseDatabaseSchemaEditor+++def rename_comment_scope(apps: Apps, from_scope: str, to_scope: str) -> None:+ for model_name in ("Comment", "CommentSlackThread"):+ apps.get_model("posthog", model_name).objects.filter(scope=from_scope).update(scope=to_scope)+++def forwards(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:+ rename_comment_scope(apps, "desktop_canvas", "canvas")+++def backwards(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:+ rename_comment_scope(apps, "canvas", "desktop_canvas")+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1389_teameventvolume"),+ ]++ operations = [+ migrations.RunPython(forwards, backwards),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex f4cfd85f8bee..edd202d38d78 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1389_teameventvolume+1390_rename_desktop_canvas_comment_scopediff --git a/posthog/models/comment/comment.py b/posthog/models/comment/comment.pyindex 6a23bce2b028..5eaef91b9091 100644--- a/posthog/models/comment/comment.py+++ b/posthog/models/comment/comment.py@@ -77,7 +77,7 @@ TICKET_COMMENT_SCOPES = frozenset({"Ticket", "conversations_ticket"})COMMENT_SCOPES_BLOCKED_FROM_GENERIC_API = frozenset({"EmailThread"})CANVAS_COMMENT_SCOPES = frozenset({"canvas", "desktop_canvas"})-STORED_CANVAS_COMMENT_SCOPE = "desktop_canvas"+STORED_CANVAS_COMMENT_SCOPE = "canvas"def canonical_comment_scope(scope: str) -> str:diff --git a/posthog/test/test_migration_rename_desktop_canvas_comment_scope.py b/posthog/test/test_migration_rename_desktop_canvas_comment_scope.pynew file mode 100644index 000000000000..56830cf9c79e--- /dev/null+++ b/posthog/test/test_migration_rename_desktop_canvas_comment_scope.py@@ -0,0 +1,42 @@+from typing import Any++from posthog.test.base import TestMigrations++from django.db import connection+from django.db.migrations.executor import MigrationExecutor+++class TestRenameDesktopCanvasCommentScope(TestMigrations):+ migrate_from = "1389_teameventvolume"+ migrate_to = "1390_rename_desktop_canvas_comment_scope"++ def setUpBeforeMigration(self, apps: Any) -> None:+ Comment = apps.get_model("posthog", "Comment")+ integration = apps.get_model("posthog", "Integration").objects.create(+ team_id=self.team.id, kind="slack", integration_id="T1"+ )+ for scope in ["desktop_canvas", "desktop_canvas", "task", "Insight"]:+ root = Comment.objects.create(team_id=self.team.id, scope=scope, item_id="item-1", content="c")+ apps.get_model("posthog", "CommentSlackThread").objects.create(+ team_id=self.team.id,+ scope=scope,+ item_id="item-1",+ source_comment=root,+ integration=integration,+ slack_channel_id="C1",+ )++ def _scopes(self, model_name: str) -> list[str]:+ assert self.apps is not None+ model = self.apps.get_model("posthog", model_name)+ return sorted(model.objects.filter(team_id=self.team.id).values_list("scope", flat=True))++ def test_moves_only_desktop_canvas_comments_and_mirrors_and_reverses(self) -> None:+ for model_name in ("Comment", "CommentSlackThread"):+ assert self._scopes(model_name) == ["Insight", "canvas", "canvas", "task"]++ executor = MigrationExecutor(connection)+ executor.migrate([("posthog", self.migrate_from)])++ for model_name in ("Comment", "CommentSlackThread"):+ assert self._scopes(model_name) == ["Insight", "desktop_canvas", "desktop_canvas", "task"]