: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(today): show your views when the views pane filters by creator (#116524)
Shy Alterc3f95deb7a52
diff --git a/frontend/src/layout/today/todayViewsLogic.ts b/frontend/src/layout/today/todayViewsLogic.tsindex 90fb6273e4d8..4f289758b267 100644--- a/frontend/src/layout/today/todayViewsLogic.ts+++ b/frontend/src/layout/today/todayViewsLogic.ts@@ -128,7 +128,11 @@ export interface todayViewsLogicMeta {__keaTypeGenInternalSelectorTypes: {recentlyViewed: (recentViewEntries: TodayRecentEntry[], recentQuery: string) => TodayRecentEntry[]recentFiltersActive: (recentFilters: TodayViewsFilters) => boolean- recentFeedQuery: (recentFilters: TodayViewsFilters, recentSearch: string) => ViewFeedQuery+ recentFeedQuery: (+ recentFilters: TodayViewsFilters,+ recentSearch: string,+ user: UserType | null+ ) => ViewFeedQueryallRecentViews: (sources: Record<string, ViewSourceState>,spaceNames: Record<string, string>,@@ -283,10 +287,11 @@ export const todayViewsLogic = kea<todayViewsLogicType>([(recentFilters: TodayViewsFilters): boolean => viewsFiltersActive(recentFilters),],recentFeedQuery: [- (s) => [s.recentFilters, s.recentSearch],- (recentFilters: TodayViewsFilters, recentSearch: string): ViewFeedQuery => ({+ (s) => [s.recentFilters, s.recentSearch, s.user],+ (recentFilters: TodayViewsFilters, recentSearch: string, user: UserType | null): ViewFeedQuery => ({type: recentFilters.type,search: recentSearch.trim(),+ createdBy: recentFilters.createdBy === 'me' ? (user?.uuid ?? null) : null,}),],allRecentViews: [@@ -362,7 +367,11 @@ export const todayViewsLogic = kea<todayViewsLogicType>([listeners(({ actions, values, cache }) => ({loadRecentViews: () => {actions.refreshFeed(ALL_RECENT_QUERY)- if (values.recentFeedQuery.type !== 'all' || values.recentFeedQuery.search) {+ if (+ values.recentFeedQuery.type !== 'all' ||+ values.recentFeedQuery.search ||+ values.recentFeedQuery.createdBy+ ) {actions.refreshFeed(values.recentFeedQuery)}},diff --git a/frontend/src/scenes/views/viewFeed.ts b/frontend/src/scenes/views/viewFeed.tsindex fd32519490c3..00e32384ab67 100644--- a/frontend/src/scenes/views/viewFeed.ts+++ b/frontend/src/scenes/views/viewFeed.ts@@ -19,6 +19,7 @@ export const VIEW_FEED_PAGE_SIZE = 50export interface ViewFeedQuery {type: ViewTypeFiltersearch: string+ createdBy?: string | null}export interface ViewSourcePage {@@ -30,6 +31,7 @@ export interface ViewSourcePage {export interface ViewSourceState {projectId: stringsearch: string+ createdBy: string | nulltype: ViewTypeitems: ViewItem[]offset: number@@ -54,22 +56,25 @@ export function viewFeedTypes(query: ViewFeedQuery): ViewType[] {return query.type === 'all' ? VIEW_TYPES.map((info) => info.type) : [query.type]}-export function viewSourceKey(projectId: string, search: string, type: ViewType): string {- return JSON.stringify([projectId, search.trim(), type])+export function viewSourceKey(projectId: string, search: string, type: ViewType, createdBy: string | null): string {+ return JSON.stringify([projectId, search.trim(), type, createdBy])}export async function fetchViewSourcePage(projectId: string,type: ViewType,search: string,+ createdBy: string | null,offset: number): Promise<ViewSourcePage> {const limit = VIEW_FEED_PAGE_SIZEconst query = search.trim() || undefined+ const created_by = createdBy ?? undefinedif (type === 'canvas') {const page = await canvasesList(projectId, {kind: LISTED_CANVAS_KIND,search: query,+ created_by,ordering: '-updated_at',limit,offset,@@ -82,7 +87,7 @@ export async function fetchViewSourcePage(}if (type === 'notebook') {// The notebooks endpoint filters on `search`, but its schema does not declare the parameter.- const params: NotebooksListParams & { search?: string } = { limit, offset, search: query }+ const params: NotebooksListParams & { search?: string } = { limit, offset, search: query, created_by }const page = await notebooksList(projectId, params)return {items: page.results.filter((notebook) => !notebook.deleted).map(notebookToView),@@ -90,7 +95,13 @@ export async function fetchViewSourcePage(hasMore: !!page.next && page.results.length > 0,}}- const page = await dashboardsList(projectId, { search: query, ordering: '-last_viewed_at', limit, offset })+ const page = await dashboardsList(projectId, {+ search: query,+ created_by,+ ordering: '-last_viewed_at',+ limit,+ offset,+ })return {items: page.results.filter((dashboard) => !dashboard.deleted).map(dashboardToView),fetched: page.results.length,diff --git a/frontend/src/scenes/views/viewFeedLogic.ts b/frontend/src/scenes/views/viewFeedLogic.tsindex 293a51e82d95..85aead7d8b58 100644--- a/frontend/src/scenes/views/viewFeedLogic.ts+++ b/frontend/src/scenes/views/viewFeedLogic.ts@@ -43,7 +43,7 @@ function settledSources(sources: Record<string, ViewSourceState>): Record<string}function withoutOldSearches(sources: Record<string, ViewSourceState>): Record<string, ViewSourceState> {- const searchKeys = Object.keys(sources).filter((key) => sources[key].search)+ const searchKeys = Object.keys(sources).filter((key) => sources[key].search || sources[key].createdBy)const dropped = new Set(searchKeys.slice(0, Math.max(0, searchKeys.length - MAX_SEARCH_SOURCES)))return dropped.size ? Object.fromEntries(Object.entries(sources).filter(([key]) => !dropped.has(key))) : sources}@@ -56,7 +56,9 @@ export function selectViewFeed(): ViewFeed {return viewFeedFromSources(viewFeedTypes(query).map((type) =>- projectId ? sources[viewSourceKey(String(projectId), query.search, type)] : undefined+ projectId+ ? sources[viewSourceKey(String(projectId), query.search, type, query.createdBy ?? null)]+ : undefined),spaceNames)@@ -104,8 +106,10 @@ export interface viewFeedLogicActions {key: string,projectId: string,search: string,- type: ViewType+ type: ViewType,+ createdBy: string | null) => {+ createdBy: string | nullkey: stringprojectId: stringsearch: string@@ -144,11 +148,12 @@ export const viewFeedLogic = kea<viewFeedLogicType>([actions({ensureFeed: (query: ViewFeedQuery, count: number) => ({ query, count }),refreshFeed: (query: ViewFeedQuery) => ({ query }),- refreshSource: (key: string, projectId: string, search: string, type: ViewType) => ({+ refreshSource: (key: string, projectId: string, search: string, type: ViewType, createdBy: string | null) => ({key,projectId,search,type,+ createdBy,}),sourceRefreshed: (key: string, generation: number, page: ViewSourcePage | null) => ({key,@@ -192,7 +197,7 @@ export const viewFeedLogic = kea<viewFeedLogicType>([{} as Record<string, ViewSourceState>,{restoreSnapshot: (state, { snapshot }) => ({ ...snapshot.sources, ...state }),- refreshSource: (state, { key, projectId, search, type }) => {+ refreshSource: (state, { key, projectId, search, type, createdBy }) => {const { [key]: current, ...rest } = statereturn withoutOldSearches({...rest,@@ -201,6 +206,7 @@ export const viewFeedLogic = kea<viewFeedLogicType>([: {projectId,search,+ createdBy,type,items: [],offset: 0,@@ -265,10 +271,11 @@ export const viewFeedLogic = kea<viewFeedLogicType>([return}const projectId = String(values.currentTeamId)+ const createdBy = query.createdBy ?? nullfor (const type of viewFeedTypes(query)) {- const key = viewSourceKey(projectId, query.search, type)+ const key = viewSourceKey(projectId, query.search, type, createdBy)if (!values.sources[key]?.refreshing) {- actions.refreshSource(key, projectId, query.search.trim(), type)+ actions.refreshSource(key, projectId, query.search.trim(), type, createdBy)}}},@@ -277,7 +284,9 @@ export const viewFeedLogic = kea<viewFeedLogicType>([return}const projectId = String(values.currentTeamId)- const keys = viewFeedTypes(query).map((type) => viewSourceKey(projectId, query.search, type))+ const keys = viewFeedTypes(query).map((type) =>+ viewSourceKey(projectId, query.search, type, query.createdBy ?? null)+ )if (keys.some((key) => !values.sources[key])) {actions.refreshFeed(query)return@@ -288,13 +297,15 @@ export const viewFeedLogic = kea<viewFeedLogicType>([}for (const source of blocking) {if (source.initialized && !source.loading && !source.refreshing) {- actions.loadSourcePage(viewSourceKey(source.projectId, source.search, source.type))+ actions.loadSourcePage(+ viewSourceKey(source.projectId, source.search, source.type, source.createdBy)+ )}}},- refreshSource: async ({ key, projectId, search, type }) => {+ refreshSource: async ({ key, projectId, search, type, createdBy }) => {const generation = values.sources[key].generation- const page = await fetchViewSourcePage(projectId, type, search, 0).catch(() => null)+ const page = await fetchViewSourcePage(projectId, type, search, createdBy, 0).catch(() => null)actions.sourceRefreshed(key, generation, page)},loadSourcePage: async ({ key }) => {@@ -303,9 +314,13 @@ export const viewFeedLogic = kea<viewFeedLogicType>([return}const { generation, offset } = source- const page = await fetchViewSourcePage(source.projectId, source.type, source.search, offset).catch(- () => null- )+ const page = await fetchViewSourcePage(+ source.projectId,+ source.type,+ source.search,+ source.createdBy,+ offset+ ).catch(() => null)actions.sourcePageLoaded(key, generation, offset, page)},})),diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.pyindex f12572d664f7..21375ca51483 100644--- a/posthog/api/test/dashboards/test_dashboard.py+++ b/posthog/api/test/dashboards/test_dashboard.py@@ -244,6 +244,19 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):for name in excluded:assert name not in result_names, f"expected {name!r} excluded, got {result_names}"+ def test_list_filter_by_creator(self):+ mine_id, _ = self.dashboard_api.create_dashboard({"name": "mine"})+ theirs_id, _ = self.dashboard_api.create_dashboard({"name": "theirs"})+ other_user = User.objects.create_and_join(self.organization, "[email protected]", None)+ Dashboard.objects.filter(id=theirs_id).update(created_by=other_user)++ response = self.dashboard_api.list_dashboards(query_params={"created_by": str(self.user.uuid)})++ assert [d["id"] for d in response["results"]] == [mine_id]+ self.dashboard_api.list_dashboards(+ query_params={"created_by": "not-a-uuid"}, expected_status=status.HTTP_400_BAD_REQUEST+ )+def test_list_filter_by_search_matches_description_with_lower_rank_than_name(self):# Description matches are kept but rank below name matches.name_match_id, _ = self.dashboard_api.create_dashboard({"name": "revenue"})diff --git a/products/canvas/backend/logic/canvases.py b/products/canvas/backend/logic/canvases.pyindex dea6f3370356..6943551a0111 100644--- a/products/canvas/backend/logic/canvases.py+++ b/products/canvas/backend/logic/canvases.py@@ -49,6 +49,7 @@ def _listing(channel_id: str | None,kind: str | None,search: str | None,+ created_by: str | None,user_access_control: "UserAccessControl | None",include_all_if_admin: bool,) -> QuerySet[Canvas]:@@ -69,6 +70,12 @@ def _listing(queryset = queryset.filter(kind=kind)if search:queryset = queryset.filter(Q(name__icontains=search) | Q(description__icontains=search))+ if created_by:+ try:+ created_by = str(UUID(created_by))+ except ValueError:+ return queryset.none()+ queryset = queryset.filter(created_by__uuid=created_by)return queryset@@ -78,6 +85,7 @@ def count_canvases(channel_id: str | None,kind: str | None,search: str | None,+ created_by: str | None = None,user_access_control: "UserAccessControl | None",include_all_if_admin: bool,) -> int:@@ -86,6 +94,7 @@ def count_canvases(channel_id=channel_id,kind=kind,search=search,+ created_by=created_by,user_access_control=user_access_control,include_all_if_admin=include_all_if_admin,).count()@@ -97,6 +106,7 @@ def list_canvases(channel_id: str | None,kind: str | None,search: str | None,+ created_by: str | None = None,user_access_control: "UserAccessControl | None",include_all_if_admin: bool,offset: int,@@ -109,6 +119,7 @@ def list_canvases(channel_id=channel_id,kind=kind,search=search,+ created_by=created_by,user_access_control=user_access_control,include_all_if_admin=include_all_if_admin,).select_related(*_RECORD_RELATIONS)diff --git a/products/canvas/backend/presentation/views.py b/products/canvas/backend/presentation/views.pyindex aaa5cdd84d52..c89f01c44148 100644--- a/products/canvas/backend/presentation/views.py+++ b/products/canvas/backend/presentation/views.py@@ -502,6 +502,12 @@ class CanvasViewSet(CanvasAccessMixin, viewsets.GenericViewSet):required=False,description="Only return canvases whose name or description contains this text (case-insensitive).",),+ OpenApiParameter(+ "created_by",+ OpenApiTypes.UUID,+ required=False,+ description="Only return canvases created by the user with this UUID.",+ ),OpenApiParameter("ordering",OpenApiTypes.STR,@@ -518,6 +524,7 @@ class CanvasViewSet(CanvasAccessMixin, viewsets.GenericViewSet):"channel_id": request.query_params.get("channel"),"kind": request.query_params.get("kind"),"search": request.query_params.get("search"),+ "created_by": request.query_params.get("created_by"),# Service credentials skip access-control filtering, as the model viewset list did."user_access_control": None if is_service_auth(request) else self.user_access_control,"include_all_if_admin": request.query_params.get("admin_include_all") == "true",diff --git a/products/canvas/backend/tests/test_canvas_api.py b/products/canvas/backend/tests/test_canvas_api.pyindex 1451fbc7a664..86a1d42d8f80 100644--- a/products/canvas/backend/tests/test_canvas_api.py+++ b/products/canvas/backend/tests/test_canvas_api.py@@ -163,6 +163,20 @@ 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}+ @parameterized.expand([("mine", True, ["mine"]), ("invalid uuid", False, [])])+ def test_list_filters_by_creator(self, _name: str, valid: bool, expected: list[str]) -> None:+ self._create_canvas(name="mine")+ other_id = self._create_canvas(name="theirs")+ other_user = self._create_user("[email protected]")+ with team_scope(self.team.id):+ Canvas.objects.filter(id=other_id).update(created_by=other_user)+ created_by = self.user.uuid if valid else "not-a-uuid"++ response = self.client.get(f"/api/projects/{self.team.id}/canvases/?created_by={created_by}")++ assert response.status_code == status.HTTP_200_OK+ assert [row["name"] for row in response.json()["results"]] == expected+@parameterized.expand([("default", "", ["newer", "older"]), ("updated", "?ordering=-updated_at", ["older", "newer"])])diff --git a/products/canvas/frontend/generated/api.schemas.ts b/products/canvas/frontend/generated/api.schemas.tsindex ebe1ad623b0b..af3e3f917ef2 100644--- a/products/canvas/frontend/generated/api.schemas.ts+++ b/products/canvas/frontend/generated/api.schemas.ts@@ -1842,6 +1842,10 @@ export type CanvasesListParams = {* Only return canvases in this channel.*/channel?: string+ /**+ * Only return canvases created by the user with this UUID.+ */+ created_by?: string/*** Only return canvases of this kind. kind=component lists the component store.*/diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.pyindex 46e248d0ad25..9eb3b23ca49c 100644--- a/products/dashboards/backend/api/dashboard.py+++ b/products/dashboards/backend/api/dashboard.py@@ -2791,6 +2791,12 @@ class DashboardSubscribeNudgeResponseSerializer(serializers.Serializer):location=OpenApiParameter.QUERY,description="Optional. Exclude dashboards that PostHog generated.",),+ OpenApiParameter(+ "created_by",+ OpenApiTypes.UUID,+ location=OpenApiParameter.QUERY,+ description="Optional. Return only dashboards created by the user with this UUID.",+ ),OpenApiParameter("ordering",OpenApiTypes.STR,@@ -2871,6 +2877,13 @@ class DashboardsViewSet(if folder is not None:queryset = self._apply_folder_filter(queryset, folder)+ created_by = self.request.query_params.get("created_by")+ if created_by:+ try:+ queryset = queryset.filter(created_by__uuid=uuid.UUID(created_by))+ except ValueError:+ raise serializers.ValidationError({"created_by": "Must be a valid user UUID."})+queryset = drop_similar_when_exact_exists(queryset)if self.action == "list" and self.request.query_params.get("ordering") == "-last_viewed_at":queryset = queryset.order_by(Coalesce("last_viewed_at", "created_at").desc(), "-id")diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex ce639d3b3775..cf7d4c4e1328 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -11274,6 +11274,10 @@ export const DashboardTemplatesListScope = {} as constexport type DashboardsListParams = {+ /**+ * Optional. Return only dashboards created by the user with this UUID.+ */+ created_by?: string/*** Optional. Exclude dashboards that PostHog generated.*/diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex f16ddefde08e..f70ee340dbd0 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -120117,6 +120117,10 @@ export namespace Schemas {* Only return canvases in this channel.*/channel?: string;+ /**+ * Only return canvases created by the user with this UUID.+ */+ created_by?: string;/*** Only return canvases of this kind. kind=component lists the component store.*/@@ -120975,6 +120979,10 @@ export namespace Schemas {} as const;export type DashboardsListParams = {+ /**+ * Optional. Return only dashboards created by the user with this UUID.+ */+ created_by?: string;/*** Optional. Exclude dashboards that PostHog generated.*/diff --git a/services/mcp/src/generated/canvas/api.ts b/services/mcp/src/generated/canvas/api.tsindex edf3f7cba9ac..77c21228123e 100644--- a/services/mcp/src/generated/canvas/api.ts+++ b/services/mcp/src/generated/canvas/api.ts@@ -24,6 +24,7 @@ export const CanvasesListParams = () => zod.object({export const CanvasesListQueryParams = () => zod.object({channel: zod.string().optional().describe('Only return canvases in this channel.'),+ created_by: zod.string().optional().describe('Only return canvases created by the user with this UUID.'),kind: zod.enum(['component', 'freeform', 'grid']).optional()diff --git a/services/mcp/src/generated/dashboards/api.ts b/services/mcp/src/generated/dashboards/api.tsindex ffb861099b23..ae28342277e6 100644--- a/services/mcp/src/generated/dashboards/api.ts+++ b/services/mcp/src/generated/dashboards/api.ts@@ -63,6 +63,10 @@ export const DashboardsListParams = () => zod.object({})export const DashboardsListQueryParams = () => zod.object({+ created_by: zod+ .string()+ .optional()+ .describe('Optional. Return only dashboards created by the user with this UUID.'),exclude_generated: zod.boolean().optional().describe('Optional. Exclude dashboards that PostHog generated.'),folder: zod.string()diff --git a/services/mcp/src/tools/generated/canvas.ts b/services/mcp/src/tools/generated/canvas.tsindex 9b850352c4cc..bfe79fe9825b 100644--- a/services/mcp/src/tools/generated/canvas.ts+++ b/services/mcp/src/tools/generated/canvas.ts@@ -399,6 +399,7 @@ const canvasList = (): ToolBase<ReturnType<typeof CanvasListSchema>, Schemas.Pagpath: `/api/projects/${encodeURIComponent(String(projectId))}/canvases/`,query: {channel: params.channel,+ created_by: params.created_by,kind: params.kind,limit: params.limit,offset: params.offset,diff --git a/services/mcp/src/tools/generated/dashboards.ts b/services/mcp/src/tools/generated/dashboards.tsindex 85d57f76226f..c935b54f094c 100644--- a/services/mcp/src/tools/generated/dashboards.ts+++ b/services/mcp/src/tools/generated/dashboards.ts@@ -889,6 +889,7 @@ const dashboardsGetAll = (): ToolBase<method: 'GET',path: `/api/projects/${encodeURIComponent(String(projectId))}/dashboards/`,query: {+ created_by: params.created_by,exclude_generated: params.exclude_generated,folder: params.folder,limit: params.limit,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-list.jsonindex cb31d32ef83f..2e21e42962a1 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-list.json@@ -5,6 +5,10 @@"description": "Only return canvases in this channel (channel id).","type": "string"},+ "created_by": {+ "description": "Only return canvases created by the user with this UUID.",+ "type": "string"+ },"kind": {"description": "Only return canvases of this kind. kind=component lists the component store.","enum": ["component", "freeform", "grid"],diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboards-get-all.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboards-get-all.jsonindex cfb8c99f14b5..5b4397b1ee6c 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboards-get-all.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboards-get-all.json@@ -1,6 +1,10 @@{"$schema": "https://json-schema.org/draft/2020-12/schema","properties": {+ "created_by": {+ "description": "Optional. Return only dashboards created by the user with this UUID.",+ "type": "string"+ },"exclude_generated": {"description": "Optional. Exclude dashboards that PostHog generated.","type": "boolean"