Browse Source

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.
Alex Xu @ Sentry 4 years ago
parent
commit
fac2efa1a0

+ 0 - 1
src/sentry/api/bases/__init__.py

@@ -1,5 +1,4 @@
 from .group import *  # NOQA
-from .dashboard import *  # NOQA
 from .organization import *  # NOQA
 from .organization_events import *  # NOQA
 from .organizationissues import *  # NOQA

+ 0 - 21
src/sentry/api/bases/dashboard.py

@@ -1,21 +0,0 @@
-from sentry.api.bases.organization import OrganizationEndpoint
-from sentry.api.exceptions import ResourceDoesNotExist
-from sentry.models import Dashboard
-
-
-class OrganizationDashboardEndpoint(OrganizationEndpoint):
-    def convert_args(self, request, organization_slug, dashboard_id, *args, **kwargs):
-        args, kwargs = super().convert_args(request, organization_slug)
-
-        try:
-            kwargs["dashboard"] = self._get_dashboard(request, kwargs["organization"], dashboard_id)
-        except (Dashboard.DoesNotExist, ValueError):
-            raise ResourceDoesNotExist
-
-        return (args, kwargs)
-
-    def _get_dashboard(self, request, organization, dashboard_id):
-        prebuilt = Dashboard.get_prebuilt(dashboard_id)
-        if prebuilt:
-            return prebuilt
-        return Dashboard.objects.get(id=dashboard_id, organization_id=organization.id)

+ 26 - 14
src/sentry/api/endpoints/organization_dashboard_details.py

@@ -1,10 +1,11 @@
 from django.db import IntegrityError, transaction
 from rest_framework.response import Response
 
-from sentry.api.bases.dashboard import OrganizationDashboardEndpoint
+from sentry.api.bases.organization import OrganizationEndpoint
+from sentry.api.exceptions import ResourceDoesNotExist
 from sentry.api.serializers import serialize
 from sentry.api.serializers.rest_framework import DashboardDetailsSerializer
-from sentry.models.dashboard import DashboardTombstone
+from sentry.models.dashboard import DashboardTombstone, Dashboard
 from sentry.api.endpoints.organization_dashboards import OrganizationDashboardsPermission
 from sentry import features
 
@@ -12,9 +13,25 @@ EDIT_FEATURE = "organizations:dashboards-edit"
 READ_FEATURE = "organizations:dashboards-basic"
 
 
-class OrganizationDashboardDetailsEndpoint(OrganizationDashboardEndpoint):
+class OrganizationDashboardDetailsEndpoint(OrganizationEndpoint):
     permission_classes = (OrganizationDashboardsPermission,)
 
+    def convert_args(self, request, organization_slug, dashboard_id, *args, **kwargs):
+        args, kwargs = super().convert_args(request, organization_slug)
+
+        try:
+            kwargs["dashboard"] = self._get_dashboard(request, kwargs["organization"], dashboard_id)
+        except (Dashboard.DoesNotExist, ValueError):
+            raise ResourceDoesNotExist
+
+        return (args, kwargs)
+
+    def _get_dashboard(self, request, organization, dashboard_id):
+        prebuilt = Dashboard.get_prebuilt(dashboard_id)
+        if prebuilt:
+            return prebuilt
+        return Dashboard.objects.get(id=dashboard_id, organization_id=organization.id)
+
     def get(self, request, organization, dashboard):
         """
         Retrieve an Organization's Dashboard
@@ -22,9 +39,8 @@ class OrganizationDashboardDetailsEndpoint(OrganizationDashboardEndpoint):
 
         Return details on an individual organization's dashboard.
 
-        :pparam string organization_slug: the slug of the organization the
-                                          dashboard belongs to.
-        :pparam int dashboard_id: the id of the dashboard.
+        :pparam Organization organization: the organization the dashboard belongs to.
+        :pparam Dashboard dashboard: the dashboard object
         :auth: required
         """
         if not features.has(READ_FEATURE, organization, actor=request.user):
@@ -43,9 +59,8 @@ class OrganizationDashboardDetailsEndpoint(OrganizationDashboardEndpoint):
         Delete an individual organization's dashboard, or tombstone
         a pre-built dashboard which effectively deletes it.
 
-        :pparam string organization_slug: the slug of the organization the
-                                          dashboard belongs to.
-        :pparam int dashboard_id: the id of the dashboard.
+        :pparam Organization organization: the organization the dashboard belongs to.
+        :pparam Dashboard dashboard: the dashboard object
         :auth: required
         """
         if not features.has(EDIT_FEATURE, organization, actor=request.user):
@@ -68,11 +83,8 @@ class OrganizationDashboardDetailsEndpoint(OrganizationDashboardEndpoint):
         Edit an individual organization's dashboard as well as
         bulk edits on widgets (i.e. rearranging widget order).
 
-        :pparam string organization_slug: the slug of the organization the
-                                          dashboard belongs to.
-        :pparam int dashboard_id: the id of the dashboard.
-        :param array widgets: the array of widgets (consisting of a widget id and the order)
-                            to be updated.
+        :pparam Organization organization: the organization the dashboard belongs to.
+        :pparam Dashboard dashboard: the old dashboard object
         :auth: required
         """
         if not features.has(EDIT_FEATURE, organization, actor=request.user):