11from django .db import IntegrityError , transaction
22from 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
56from sentry .api .serializers import serialize
67from sentry .api .serializers .rest_framework import DashboardDetailsSerializer
7- from sentry .models .dashboard import DashboardTombstone
8+ from sentry .models .dashboard import DashboardTombstone , Dashboard
89from sentry .api .endpoints .organization_dashboards import OrganizationDashboardsPermission
910from sentry import features
1011
1112EDIT_FEATURE = "organizations:dashboards-edit"
1213READ_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