|
4 | 4 |
|
5 | 5 | from django.db import IntegrityError, router, transaction |
6 | 6 | from django.db.models import Case, IntegerField, When |
| 7 | +from drf_spectacular.utils import extend_schema |
7 | 8 | from rest_framework.request import Request |
8 | 9 | from rest_framework.response import Response |
9 | 10 |
|
|
14 | 15 | from sentry.api.bases.organization import OrganizationEndpoint, OrganizationPermission |
15 | 16 | from sentry.api.paginator import ChainPaginator |
16 | 17 | from sentry.api.serializers import serialize |
17 | | -from sentry.api.serializers.models.dashboard import DashboardListSerializer |
| 18 | +from sentry.api.serializers.models.dashboard import ( |
| 19 | + DashboardDetailsModelSerializer, |
| 20 | + DashboardListResponse, |
| 21 | + DashboardListSerializer, |
| 22 | +) |
18 | 23 | from sentry.api.serializers.rest_framework import DashboardSerializer |
| 24 | +from sentry.apidocs.constants import ( |
| 25 | + RESPONSE_BAD_REQUEST, |
| 26 | + RESPONSE_CONFLICT, |
| 27 | + RESPONSE_FORBIDDEN, |
| 28 | + RESPONSE_NOT_FOUND, |
| 29 | +) |
| 30 | +from sentry.apidocs.examples.dashboard_examples import DashboardExamples |
| 31 | +from sentry.apidocs.parameters import CursorQueryParam, GlobalParams, VisibilityParams |
| 32 | +from sentry.apidocs.utils import inline_sentry_response_serializer |
19 | 33 | from sentry.models.dashboard import Dashboard |
20 | 34 | from sentry.models.organization import Organization |
21 | 35 |
|
@@ -43,28 +57,33 @@ def has_object_permission(self, request: Request, view, obj): |
43 | 57 | return True |
44 | 58 |
|
45 | 59 |
|
| 60 | +@extend_schema(tags=["Dashboards"]) |
46 | 61 | @region_silo_endpoint |
47 | 62 | class OrganizationDashboardsEndpoint(OrganizationEndpoint): |
48 | 63 | publish_status = { |
49 | | - "GET": ApiPublishStatus.UNKNOWN, |
50 | | - "POST": ApiPublishStatus.UNKNOWN, |
| 64 | + "GET": ApiPublishStatus.PUBLIC, |
| 65 | + "POST": ApiPublishStatus.PUBLIC, |
51 | 66 | } |
52 | 67 | owner = ApiOwner.PERFORMANCE |
53 | 68 | permission_classes = (OrganizationDashboardsPermission,) |
54 | 69 |
|
| 70 | + @extend_schema( |
| 71 | + operation_id="Retrieve an Organization's Custom Dashboards", |
| 72 | + parameters=[GlobalParams.ORG_ID_OR_SLUG, VisibilityParams.PER_PAGE, CursorQueryParam], |
| 73 | + request=None, |
| 74 | + responses={ |
| 75 | + 200: inline_sentry_response_serializer( |
| 76 | + "DashboardListResponse", list[DashboardListResponse] |
| 77 | + ), |
| 78 | + 400: RESPONSE_BAD_REQUEST, |
| 79 | + 403: RESPONSE_FORBIDDEN, |
| 80 | + 404: RESPONSE_NOT_FOUND, |
| 81 | + }, |
| 82 | + examples=DashboardExamples.DASHBOARDS_QUERY_RESPONSE, |
| 83 | + ) |
55 | 84 | def get(self, request: Request, organization) -> Response: |
56 | 85 | """ |
57 | | - Retrieve an Organization's Dashboards |
58 | | - ````````````````````````````````````` |
59 | | -
|
60 | | - Retrieve a list of dashboards that are associated with the given organization. |
61 | | - If on the first page, this endpoint will also include any pre-built dashboards |
62 | | - that haven't been replaced or removed. |
63 | | -
|
64 | | - :pparam string organization_id_or_slug: the id or slug of the organization the |
65 | | - dashboards belongs to. |
66 | | - :qparam string query: the title of the dashboard being searched for. |
67 | | - :auth: required |
| 86 | + Retrieve a list of custom dashboards that are associated with the given organization. |
68 | 87 | """ |
69 | 88 | if not features.has("organizations:dashboards-basic", organization, actor=request.user): |
70 | 89 | return Response(status=404) |
@@ -148,14 +167,22 @@ def handle_results(results): |
148 | 167 | on_results=handle_results, |
149 | 168 | ) |
150 | 169 |
|
| 170 | + @extend_schema( |
| 171 | + operation_id="Create a New Dashboard for an Organization", |
| 172 | + parameters=[GlobalParams.ORG_ID_OR_SLUG], |
| 173 | + request=DashboardSerializer, |
| 174 | + responses={ |
| 175 | + 201: DashboardDetailsModelSerializer, |
| 176 | + 400: RESPONSE_BAD_REQUEST, |
| 177 | + 403: RESPONSE_FORBIDDEN, |
| 178 | + 404: RESPONSE_NOT_FOUND, |
| 179 | + 409: RESPONSE_CONFLICT, |
| 180 | + }, |
| 181 | + examples=DashboardExamples.DASHBOARD_POST_RESPONSE, |
| 182 | + ) |
151 | 183 | def post(self, request: Request, organization, retry=0) -> Response: |
152 | 184 | """ |
153 | | - Create a New Dashboard for an Organization |
154 | | - `````````````````````````````````````````` |
155 | | -
|
156 | 185 | Create a new dashboard for the given Organization |
157 | | - :pparam string organization_id_or_slug: the id or slug of the organization the |
158 | | - dashboards belongs to. |
159 | 186 | """ |
160 | 187 | if not features.has("organizations:dashboards-edit", organization, actor=request.user): |
161 | 188 | return Response(status=404) |
|
0 commit comments