Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import TypedDict

from drf_spectacular.utils import extend_schema
from rest_framework import serializers, status
from rest_framework.request import Request
from rest_framework.response import Response
Expand All @@ -7,26 +10,64 @@
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import cell_silo_endpoint
from sentry.api.bases.project import ProjectEndpoint, ProjectSettingPermission
from sentry.apidocs.constants import (
RESPONSE_BAD_REQUEST,
RESPONSE_FORBIDDEN,
RESPONSE_NO_CONTENT,
RESPONSE_NOT_FOUND,
RESPONSE_UNAUTHORIZED,
)
from sentry.apidocs.parameters import GlobalParams
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.models.project import Project
from sentry.projectoptions.defaults import DEFAULT_PROJECT_PERFORMANCE_GENERAL_SETTINGS

SETTINGS_PROJECT_OPTION_KEY = "sentry:performance_general_settings"


class ProjectPerformanceGeneralSettingsResponse(TypedDict):
enable_images: bool


class ProjectPerformanceGeneralSettingsSerializer(serializers.Serializer):
enable_images = serializers.BooleanField(required=False)
enable_images = serializers.BooleanField(
required=False,
help_text="Whether to display images from real data, such as image resource previews.",
)


@extend_schema(tags=["Projects"])
@cell_silo_endpoint
class ProjectPerformanceGeneralSettingsEndpoint(ProjectEndpoint):
"""
Kept private: these settings only control what the Sentry UI displays (e.g. image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does Kept private: mean in this context?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The api publish status is set to private, meaning it never reaches public docs.

Our goal is to eventually make most APIs public. This Api is 100% ui specific, it's an exception so I added a note explaining that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah should we say something like "This docstring is kept private"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's probably more clear, I'll make a follow up

previews on resource spans) and aren't useful outside of it.
"""

owner = ApiOwner.DATA_BROWSING
publish_status = {
"GET": ApiPublishStatus.PRIVATE,
"POST": ApiPublishStatus.PRIVATE,
}
permission_classes = (ProjectSettingPermission,)

@extend_schema(
operation_id="Retrieve a Project's Performance General Settings",
parameters=[GlobalParams.ORG_ID_OR_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
responses={
200: inline_sentry_response_serializer(
"ProjectPerformanceGeneralSettingsResponse",
ProjectPerformanceGeneralSettingsResponse,
),
401: RESPONSE_UNAUTHORIZED,
403: RESPONSE_FORBIDDEN,
404: RESPONSE_NOT_FOUND,
},
)
def get(self, request: Request, project) -> Response:
"""
Return the general performance settings for a project.
"""
if not self.has_feature(project, request):
return self.respond(status=status.HTTP_404_NOT_FOUND)

Expand All @@ -36,7 +77,22 @@ def get(self, request: Request, project) -> Response:
project_option_settings = self.get_current_settings(project)
return Response(project_option_settings)

@extend_schema(
operation_id="Update a Project's Performance General Settings",
parameters=[GlobalParams.ORG_ID_OR_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
request=ProjectPerformanceGeneralSettingsSerializer,
responses={
204: RESPONSE_NO_CONTENT,
400: RESPONSE_BAD_REQUEST,
401: RESPONSE_UNAUTHORIZED,
403: RESPONSE_FORBIDDEN,
404: RESPONSE_NOT_FOUND,
},
)
def post(self, request: Request, project: Project) -> Response:
"""
Update the general performance settings for a project. Omitted fields are left unchanged.
"""
if not self.has_feature(project, request):
return self.respond(status=status.HTTP_404_NOT_FOUND)

Expand Down
Loading