Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/sentry/dashboards/endpoints/organization_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,23 @@ 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")

should_filter_by_prebuilt_ids = (
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:
dashboards = dashboards.filter(prebuilt_id__in=prebuilt_ids)

prebuilt = Dashboard.get_prebuilt_list(organization, request.user, query)

sort_by = request.query_params.get("sort")
Expand Down Expand Up @@ -384,7 +399,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Loading