Skip to content

Commit e7cc36c

Browse files
alxu-sentryahmedetefy
authored andcommitted
ref(dashboards): unsplit OrganizationDashboardEndpoint (#24617)
This was previously split due to use in OrganizationDashboardWidget(s)Endpoint but those were removed. It doesn't really make sense to have it separate so merge it back in. Additionally, the endpoint comments became incorrect over time so update those as well.
1 parent 5122adc commit e7cc36c

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

src/sentry/api/bases/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from .group import * # NOQA
2-
from .dashboard import * # NOQA
32
from .organization import * # NOQA
43
from .organization_events import * # NOQA
54
from .organizationissues import * # NOQA

src/sentry/api/bases/dashboard.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/sentry/api/endpoints/organization_dashboard_details.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
from django.db import IntegrityError, transaction
22
from rest_framework.response import Response
33

4-
from sentry.api.bases.dashboard import OrganizationDashboardEndpoint
4+
from sentry.api.bases.organization import OrganizationEndpoint
5+
from sentry.api.exceptions import ResourceDoesNotExist
56
from sentry.api.serializers import serialize
67
from sentry.api.serializers.rest_framework import DashboardDetailsSerializer
7-
from sentry.models.dashboard import DashboardTombstone
8+
from sentry.models.dashboard import DashboardTombstone, Dashboard
89
from sentry.api.endpoints.organization_dashboards import OrganizationDashboardsPermission
910
from sentry import features
1011

1112
EDIT_FEATURE = "organizations:dashboards-edit"
1213
READ_FEATURE = "organizations:dashboards-basic"
1314

1415

15-
class OrganizationDashboardDetailsEndpoint(OrganizationDashboardEndpoint):
16+
class OrganizationDashboardDetailsEndpoint(OrganizationEndpoint):
1617
permission_classes = (OrganizationDashboardsPermission,)
1718

19+
def convert_args(self, request, organization_slug, dashboard_id, *args, **kwargs):
20+
args, kwargs = super().convert_args(request, organization_slug)
21+
22+
try:
23+
kwargs["dashboard"] = self._get_dashboard(request, kwargs["organization"], dashboard_id)
24+
except (Dashboard.DoesNotExist, ValueError):
25+
raise ResourceDoesNotExist
26+
27+
return (args, kwargs)
28+
29+
def _get_dashboard(self, request, organization, dashboard_id):
30+
prebuilt = Dashboard.get_prebuilt(dashboard_id)
31+
if prebuilt:
32+
return prebuilt
33+
return Dashboard.objects.get(id=dashboard_id, organization_id=organization.id)
34+
1835
def get(self, request, organization, dashboard):
1936
"""
2037
Retrieve an Organization's Dashboard
2138
````````````````````````````````````
2239
2340
Return details on an individual organization's dashboard.
2441
25-
:pparam string organization_slug: the slug of the organization the
26-
dashboard belongs to.
27-
:pparam int dashboard_id: the id of the dashboard.
42+
:pparam Organization organization: the organization the dashboard belongs to.
43+
:pparam Dashboard dashboard: the dashboard object
2844
:auth: required
2945
"""
3046
if not features.has(READ_FEATURE, organization, actor=request.user):
@@ -43,9 +59,8 @@ def delete(self, request, organization, dashboard):
4359
Delete an individual organization's dashboard, or tombstone
4460
a pre-built dashboard which effectively deletes it.
4561
46-
:pparam string organization_slug: the slug of the organization the
47-
dashboard belongs to.
48-
:pparam int dashboard_id: the id of the dashboard.
62+
:pparam Organization organization: the organization the dashboard belongs to.
63+
:pparam Dashboard dashboard: the dashboard object
4964
:auth: required
5065
"""
5166
if not features.has(EDIT_FEATURE, organization, actor=request.user):
@@ -68,11 +83,8 @@ def put(self, request, organization, dashboard):
6883
Edit an individual organization's dashboard as well as
6984
bulk edits on widgets (i.e. rearranging widget order).
7085
71-
:pparam string organization_slug: the slug of the organization the
72-
dashboard belongs to.
73-
:pparam int dashboard_id: the id of the dashboard.
74-
:param array widgets: the array of widgets (consisting of a widget id and the order)
75-
to be updated.
86+
:pparam Organization organization: the organization the dashboard belongs to.
87+
:pparam Dashboard dashboard: the old dashboard object
7688
:auth: required
7789
"""
7890
if not features.has(EDIT_FEATURE, organization, actor=request.user):

0 commit comments

Comments
 (0)