From 51f8c56d940a14a182e1d77dba74d4b905499e16 Mon Sep 17 00:00:00 2001 From: Dominik Buszowiecki Date: Tue, 18 Nov 2025 16:59:08 -0500 Subject: [PATCH 1/3] wip --- .../endpoints/organization_dashboards.py | 12 ++++++++++++ .../endpoints/test_organization_dashboards.py | 14 +++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/sentry/dashboards/endpoints/organization_dashboards.py b/src/sentry/dashboards/endpoints/organization_dashboards.py index f6c9ccbd71319f..b7a3e0656e4aaa 100644 --- a/src/sentry/dashboards/endpoints/organization_dashboards.py +++ b/src/sentry/dashboards/endpoints/organization_dashboards.py @@ -236,8 +236,20 @@ def get(self, request: Request, organization: Organization) -> Response: dashboards = Dashboard.objects.filter(organization_id=organization.id) query = request.GET.get("query") + prebuilt_ids = request.GET.getlist("prebuiltId") if query: dashboards = dashboards.filter(title__icontains=query) + if ( + prebuilt_ids + and len(prebuilt_ids) > 0 + and features.has( + "organizations:dashboards-prebuilt-insights-dashboards", + organization, + actor=request.user, + ) + ): + dashboards = dashboards.filter(prebuilt_id__in=prebuilt_ids) + prebuilt = Dashboard.get_prebuilt_list(organization, request.user, query) sort_by = request.query_params.get("sort") diff --git a/tests/sentry/dashboards/endpoints/test_organization_dashboards.py b/tests/sentry/dashboards/endpoints/test_organization_dashboards.py index 967b761487fae1..42c904a7126bf0 100644 --- a/tests/sentry/dashboards/endpoints/test_organization_dashboards.py +++ b/tests/sentry/dashboards/endpoints/test_organization_dashboards.py @@ -6,7 +6,10 @@ from django.urls import reverse -from sentry.dashboards.endpoints.organization_dashboards import PREBUILT_DASHBOARDS +from sentry.dashboards.endpoints.organization_dashboards import ( + PREBUILT_DASHBOARDS, + PrebuiltDashboardId, +) from sentry.models.dashboard import ( Dashboard, DashboardFavoriteUser, @@ -1991,3 +1994,12 @@ def test_endpoint_does_not_sync_without_feature_flag(self) -> None: organization=self.organization, prebuilt_id__isnull=False ).count() assert prebuilt_count == 0 + + def test_get_with_prebuilt_ids(self) -> None: + with self.feature("organizations:dashboards-prebuilt-insights-dashboards"): + response = self.do_request( + "get", self.url, {"prebuiltId": [PrebuiltDashboardId.FRONTEND_SESSION_HEALTH]} + ) + assert response.status_code == 200 + assert len(response.data) == 1 + assert response.data[0]["prebuiltId"] == PrebuiltDashboardId.FRONTEND_SESSION_HEALTH From eb0826b3013a076e57d77e82c30ee9eff0b55755 Mon Sep 17 00:00:00 2001 From: Dominik Buszowiecki Date: Wed, 19 Nov 2025 12:01:09 -0500 Subject: [PATCH 2/3] fix --- .../dashboards/endpoints/organization_dashboards.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sentry/dashboards/endpoints/organization_dashboards.py b/src/sentry/dashboards/endpoints/organization_dashboards.py index b7a3e0656e4aaa..cb279509389ead 100644 --- a/src/sentry/dashboards/endpoints/organization_dashboards.py +++ b/src/sentry/dashboards/endpoints/organization_dashboards.py @@ -237,9 +237,7 @@ def get(self, request: Request, organization: Organization) -> Response: query = request.GET.get("query") prebuilt_ids = request.GET.getlist("prebuiltId") - if query: - dashboards = dashboards.filter(title__icontains=query) - if ( + should_filter_by_prebuilt_ids = ( prebuilt_ids and len(prebuilt_ids) > 0 and features.has( @@ -247,7 +245,10 @@ def get(self, request: Request, organization: Organization) -> Response: organization, actor=request.user, ) - ): + ) + if query: + dashboards = dashboards.filter(title__icontains=query) + if should_filter_by_prebuilt_ids: dashboards = dashboards.filter(prebuilt_id__in=prebuilt_ids) prebuilt = Dashboard.get_prebuilt_list(organization, request.user, query) @@ -396,7 +397,7 @@ def handle_results(results: list[Dashboard | dict[str, Any]]) -> list[dict[str, return serialized render_pre_built_dashboard = True - if filter_by and filter_by in {"onlyFavorites", "owned"}: + if filter_by and filter_by in {"onlyFavorites", "owned"} or should_filter_by_prebuilt_ids: render_pre_built_dashboard = False elif pin_by and pin_by == "favorites": # Only hide prebuilt dashboard when pinning favorites if there are actual dashboards to show From a5c636384b7fe6c86b057991143b1031d1820dfe Mon Sep 17 00:00:00 2001 From: Dominik Buszowiecki Date: Wed, 19 Nov 2025 12:02:16 -0500 Subject: [PATCH 3/3] short circuit early --- .../dashboards/endpoints/organization_dashboards.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sentry/dashboards/endpoints/organization_dashboards.py b/src/sentry/dashboards/endpoints/organization_dashboards.py index cb279509389ead..d32513613a9f90 100644 --- a/src/sentry/dashboards/endpoints/organization_dashboards.py +++ b/src/sentry/dashboards/endpoints/organization_dashboards.py @@ -237,15 +237,17 @@ def get(self, request: Request, organization: Organization) -> Response: query = request.GET.get("query") prebuilt_ids = request.GET.getlist("prebuiltId") + should_filter_by_prebuilt_ids = ( - prebuilt_ids - and len(prebuilt_ids) > 0 - and features.has( + features.has( "organizations:dashboards-prebuilt-insights-dashboards", organization, actor=request.user, ) + and prebuilt_ids + and len(prebuilt_ids) > 0 ) + if query: dashboards = dashboards.filter(title__icontains=query) if should_filter_by_prebuilt_ids: