: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): allow moving canvases between spaces (#86844)
Peter Kirkham11b59ace24fd
diff --git a/products/canvas/backend/presentation/serializers.py b/products/canvas/backend/presentation/serializers.pyindex b90411c00c6a..e17998a1fa2d 100644--- a/products/canvas/backend/presentation/serializers.py+++ b/products/canvas/backend/presentation/serializers.py@@ -215,6 +215,7 @@ class CanvasUpdateSerializer(serializers.Serializer):trim_whitespace=True,help_text="Updated canvas description (for components, the store-search text).",)+ channel_id = serializers.UUIDField(required=False, help_text="Id of the space the canvas belongs to.")pinned = serializers.BooleanField(required=False, help_text="Whether the canvas is pinned in its channel.")generation_task_id = serializers.UUIDField(required=False, allow_null=True, help_text="Task currently generating this canvas, or null to clear it."diff --git a/products/canvas/backend/presentation/views.py b/products/canvas/backend/presentation/views.pyindex 50d6f7930321..1bb30c852fff 100644--- a/products/canvas/backend/presentation/views.py+++ b/products/canvas/backend/presentation/views.py@@ -394,7 +394,7 @@ class CanvasViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):responses={200: CanvasSerializer},)def partial_update(self, request: Request, *args: Any, **kwargs: Any) -> Response:- """Update canvas metadata (name, author context, pin, generation-task pointer)."""+ """Update canvas metadata, including the space it belongs to."""canvas = self.get_object()payload = CanvasUpdateSerializer(data=request.data)payload.is_valid(raise_exception=True)@@ -422,6 +422,29 @@ class CanvasViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):record("description", canvas.description, data["description"])canvas.description = data["description"]update_fields.append("description")+ if "channel_id" in data:+ channel_id = data["channel_id"]+ user = self._request_user()+ if not tasks_facade.channel_exists(self.team_id, channel_id, user.id if user else None):+ return Response({"detail": "Channel not found in this team."}, status=status.HTTP_400_BAD_REQUEST)+ if self._is_sandbox_authenticated(request):+ sandbox_task_id = self._sandbox_task_id(request)+ task_channel_id = (+ tasks_facade.task_channel_id(sandbox_task_id, self.team_id) if sandbox_task_id else None+ )+ if task_channel_id != channel_id:+ return Response(+ {"detail": "This sandbox can file canvases only in its task's space."},+ status=status.HTTP_403_FORBIDDEN,+ )+ if channel_id != canvas.channel_id:+ record("channel", str(canvas.channel_id), str(channel_id))+ if canvas.pinned_at is not None:+ record("pinned", True, False)+ canvas.pinned_at = None+ update_fields.append("pinned_at")+ canvas.channel_id = channel_id+ update_fields.append("channel_id")if "pinned" in data:was_pinned = canvas.pinned_at is not Noneif data["pinned"] != was_pinned:diff --git a/products/canvas/backend/tests/test_canvas_api.py b/products/canvas/backend/tests/test_canvas_api.pyindex 56840f5adec2..f68242bed247 100644--- a/products/canvas/backend/tests/test_canvas_api.py+++ b/products/canvas/backend/tests/test_canvas_api.py@@ -145,6 +145,41 @@ class TestCanvasCrud(CanvasAPIBaseTest):response = self.client.get(f"/api/projects/{self.team.id}/canvases/")assert {row["id"] for row in response.json()["results"]} == {canvas_id, other_id}+ def test_can_file_canvas_to_another_visible_channel(self):+ canvas_id = self._create_canvas()+ with team_scope(self.team.id):+ destination = Channel.objects.create(team=self.team, name="destination")++ response = self.client.patch(+ f"/api/projects/{self.team.id}/canvases/{canvas_id}/",+ {"channel_id": str(destination.id)},+ format="json",+ )++ assert response.status_code == status.HTTP_200_OK+ assert response.json()["channel"] == str(destination.id)+ assert Canvas.objects.unscoped().get(id=canvas_id).channel_id == destination.id++ def test_cannot_file_canvas_to_another_users_personal_channel(self):+ canvas_id = self._create_canvas()+ other_user = self._create_user("[email protected]")+ with team_scope(self.team.id):+ destination = Channel.objects.create(+ team=self.team,+ name="me",+ channel_type=Channel.ChannelType.PERSONAL,+ created_by=other_user,+ )++ response = self.client.patch(+ f"/api/projects/{self.team.id}/canvases/{canvas_id}/",+ {"channel_id": str(destination.id)},+ format="json",+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST+ assert Canvas.objects.unscoped().get(id=canvas_id).channel_id == self.channel.id+def test_personal_channel_canvases_are_invisible_to_other_users(self):# A canvas filed into a teammate's personal channel is private to them:# list omits it, and every detail/write action 404s for anyone else.@@ -528,6 +563,35 @@ class TestCanvasCrud(CanvasAPIBaseTest):)assert response.json()["pinned"] is False+ def test_moving_canvas_clears_channel_pin(self):+ canvas_id = self._create_canvas()+ with team_scope(self.team.id):+ destination = Channel.objects.create(team=self.team, name="destination", created_by=self.user)+ self.client.patch(+ f"/api/projects/{self.team.id}/canvases/{canvas_id}/",+ {"pinned": True},+ format="json",+ )++ response = self.client.patch(+ f"/api/projects/{self.team.id}/canvases/{canvas_id}/",+ {"channel_id": str(destination.id)},+ format="json",+ )++ assert response.status_code == status.HTTP_200_OK, response.json()+ assert response.json()["pinned"] is False+ assert self._changes(self._activity("updated")[-1]) == [+ {+ "type": "Canvas",+ "action": "changed",+ "field": "channel",+ "before": str(self.channel.id),+ "after": str(destination.id),+ },+ {"type": "Canvas", "action": "changed", "field": "pinned", "before": True, "after": False},+ ]+def test_generation_task_pointer_validates_team(self):canvas_id = self._create_canvas()response = self.client.patch(diff --git a/products/canvas/frontend/generated/api.schemas.ts b/products/canvas/frontend/generated/api.schemas.tsindex 62c92ce32233..0cbb5895c5bb 100644--- a/products/canvas/frontend/generated/api.schemas.ts+++ b/products/canvas/frontend/generated/api.schemas.ts@@ -224,6 +224,8 @@ export interface PatchedCanvasUpdateApi {context?: string/** Updated canvas description (for components, the store-search text). */description?: string+ /** Id of the space the canvas belongs to. */+ channel_id?: string/** Whether the canvas is pinned in its channel. */pinned?: boolean/**diff --git a/products/canvas/frontend/generated/api.ts b/products/canvas/frontend/generated/api.tsindex 3090f6deaf4c..77a9dcd85447 100644--- a/products/canvas/frontend/generated/api.ts+++ b/products/canvas/frontend/generated/api.ts@@ -129,7 +129,7 @@ export const getCanvasesPartialUpdateUrl = (projectId: string, id: string) => {}/**- * Update canvas metadata (name, author context, pin, generation-task pointer).+ * Update canvas metadata, including the space it belongs to.*/export const canvasesPartialUpdate = async (projectId: string,diff --git a/products/canvas/frontend/generated/api.zod.ts b/products/canvas/frontend/generated/api.zod.tsindex e6f6a4c71192..416d1c558907 100644--- a/products/canvas/frontend/generated/api.zod.ts+++ b/products/canvas/frontend/generated/api.zod.ts@@ -45,7 +45,7 @@ export const CanvasesCreateBody = /* @__PURE__ */ zod.describe('Payload for creating a new, empty canvas in a channel.')/**- * Update canvas metadata (name, author context, pin, generation-task pointer).+ * Update canvas metadata, including the space it belongs to.*/export const canvasesPartialUpdateBodyNameMax = 400@@ -57,6 +57,7 @@ export const CanvasesPartialUpdateBody = /* @__PURE__ */ zod.string().optional().describe('Updated canvas description (for components, the store-search text).'),+ channel_id: zod.uuid().optional().describe('Id of the space the canvas belongs to.'),pinned: zod.boolean().optional().describe('Whether the canvas is pinned in its channel.'),generation_task_id: zod.uuid()diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex aec8a32a8865..09cbe1d509be 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -57678,6 +57678,8 @@ export namespace Schemas {context?: string;/** Updated canvas description (for components, the store-search text). */description?: string;+ /** Id of the space the canvas belongs to. */+ channel_id?: string;/** Whether the canvas is pinned in its channel. */pinned?: boolean;/**