Skip to content

Commit 13d530a

Browse files
fix(dashboards): Updates dashboard quota to not count prebuilt dashboards (#103985)
Filters out prebuilt dashboards when fetching count to check against dashboard quota
1 parent 4136362 commit 13d530a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/sentry/dashboards/endpoints/organization_dashboards.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ def post(self, request: Request, organization: Organization, retry: int = 0) ->
446446
if not features.has("organizations:dashboards-edit", organization, actor=request.user):
447447
return Response(status=404)
448448

449-
dashboard_count = Dashboard.objects.filter(organization=organization).count()
449+
dashboard_count = Dashboard.objects.filter(
450+
organization=organization, prebuilt_id=None
451+
).count()
450452
dashboard_limit = quotas.backend.get_dashboard_limit(organization.id)
451453
if dashboard_limit >= 0 and dashboard_count >= dashboard_limit:
452454
return Response(

tests/sentry/dashboards/endpoints/test_organization_dashboards.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,36 @@ def test_dashboard_limit_prevents_creation(self, mock_get_dashboard_limit) -> No
18931893
response = self.do_request("post", self.url, data={"title": "New Dashboard w/ Limit"})
18941894
assert response.status_code == 201
18951895

1896+
@patch("sentry.quotas.backend.get_dashboard_limit")
1897+
def test_dashboard_limit_does_not_count_prebuilt_dashboards(
1898+
self, mock_get_dashboard_limit
1899+
) -> None:
1900+
mock_get_dashboard_limit.return_value = 2
1901+
1902+
Dashboard.objects.create(
1903+
organization=self.organization,
1904+
title="Prebuilt Dashboard 1",
1905+
created_by_id=None,
1906+
prebuilt_id=1,
1907+
)
1908+
Dashboard.objects.create(
1909+
organization=self.organization,
1910+
title="Prebuilt Dashboard 2",
1911+
created_by_id=None,
1912+
prebuilt_id=2,
1913+
)
1914+
1915+
# 2 prebuilt + 2 user dashboards
1916+
response = self.do_request("post", self.url, data={"title": "Dashboard at Limit"})
1917+
assert response.status_code == 400
1918+
assert response.data == "You may not exceed 2 dashboards on your current plan."
1919+
1920+
self.dashboard.delete()
1921+
1922+
# 2 prebuilt + 1 user dashboard
1923+
response = self.do_request("post", self.url, data={"title": "New Dashboard w/ Prebuilt"})
1924+
assert response.status_code == 201
1925+
18961926
def test_prebuilt_dashboard_is_shown_when_favorites_pinned_and_no_dashboards(self) -> None:
18971927
# The prebuilt dashboard should not show up when filtering by owned dashboards
18981928
# because it is not created by the user

0 commit comments

Comments
 (0)