Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 12 additions & 12 deletions src/sentry/auth_v2/endpoints/csrf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, TypedDict

from django.middleware.csrf import rotate_token
from django.utils.decorators import method_decorator
Expand All @@ -13,11 +13,17 @@
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import Endpoint, control_silo_endpoint
from sentry.auth_v2.utils.session import SessionSerializer
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.auth_v2.utils.session import SessionSerializer, SessionSerializerResponse
from sentry.ratelimits.config import RateLimitConfig
from sentry.types.ratelimit import RateLimit, RateLimitCategory


class CsrfTokenResponse(TypedDict):
detail: str
session: SessionSerializerResponse


@control_silo_endpoint
class CsrfTokenEndpoint(Endpoint):
"""
Expand Down Expand Up @@ -48,13 +54,10 @@ class CsrfTokenEndpoint(Endpoint):
@extend_schema(
operation_id="Retrieve the CSRF token in your session",
parameters=[],
responses={
"detail": "string",
"session": SessionSerializer,
},
responses={200: inline_sentry_response_serializer("CsrfTokenResponse", CsrfTokenResponse)},
)
@method_decorator(ensure_csrf_cookie)
def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:
def get(self, request: Request, *args: Any, **kwargs: Any) -> Response[CsrfTokenResponse]:
return self.respond(
{
"detail": "Set CSRF cookie",
Expand All @@ -66,13 +69,10 @@ def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:
@extend_schema(
operation_id="Rotate the CSRF token in your session",
parameters=[],
responses={
"detail": "string",
"session": SessionSerializer,
},
responses={200: inline_sentry_response_serializer("CsrfTokenResponse", CsrfTokenResponse)},
)
@method_decorator(ensure_csrf_cookie)
def put(self, request: Request, *args: Any, **kwargs: Any) -> Response:
def put(self, request: Request, *args: Any, **kwargs: Any) -> Response[CsrfTokenResponse]:
rotate_token(request)
if referrer := request.GET.get("referrer"):
analytics.record(
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/core/endpoints/scim/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def delete(
GlobalParams.member_id("The ID of the member to update."),
],
request=inline_serializer(
"SCIMMemberProvision", fields={"sentryOrgRole": serializers.CharField()}
"SCIMMemberReplace", fields={"sentryOrgRole": serializers.CharField()}
),
responses={
201: OrganizationMemberSCIMSerializer,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/monitors/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class MonitorSerializerResponse(TypedDict):
owner: ActorSerializerResponse


class MonitorBulkEditResponse:
class MonitorBulkEditResponse(TypedDict):
updated: list[MonitorSerializerResponse]
errored: list[MonitorSerializerResponse]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import TypedDict

from drf_spectacular.utils import extend_schema
from rest_framework.exceptions import PermissionDenied
Expand All @@ -13,8 +14,10 @@
from sentry.api.utils import to_valid_int_id
from sentry.apidocs.constants import RESPONSE_FORBIDDEN, RESPONSE_NOT_FOUND, RESPONSE_UNAUTHORIZED
from sentry.apidocs.parameters import DetectorParams, GlobalParams
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.models.organization import Organization
from sentry.seer.anomaly_detection.get_anomaly_data import get_anomaly_threshold_data_from_seer
from sentry.seer.anomaly_detection.types import AnomalyThresholdDataPoint
from sentry.snuba.models import QuerySubscription
from sentry.workflow_engine.models import Detector

Expand All @@ -27,6 +30,10 @@ class SubscriptionNotFound(Exception):
pass


class AnomalyThresholdDataResponse(TypedDict):
data: list[AnomalyThresholdDataPoint]


@extend_schema(tags=["Workflows"])
@cell_silo_endpoint
class OrganizationDetectorAnomalyDataEndpoint(OrganizationEndpoint):
Expand Down Expand Up @@ -62,7 +69,9 @@ def _get_subscription_from_detector(
operation_id="Retrieve Anomaly Detection Threshold Data for a Detector",
parameters=[GlobalParams.ORG_ID_OR_SLUG, DetectorParams.DETECTOR_ID],
responses={
200: object,
200: inline_sentry_response_serializer(
"AnomalyThresholdDataResponse", AnomalyThresholdDataResponse
),
401: RESPONSE_UNAUTHORIZED,
403: RESPONSE_FORBIDDEN,
404: RESPONSE_NOT_FOUND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sentry.api.serializers.rest_framework import CamelSnakeSerializer
from sentry.apidocs.constants import RESPONSE_NOT_FOUND, RESPONSE_UNAUTHORIZED
from sentry.apidocs.parameters import GlobalParams
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.constants import ObjectStatus
from sentry.issues.action_log import (
action_context_scope,
Expand Down Expand Up @@ -81,7 +82,9 @@ class OrganizationTestFireActionsEndpoint(OrganizationEndpoint):
],
responses={
200: None,
400: TestFireActionErrorsResponse,
400: inline_sentry_response_serializer(
"TestFireActionErrorsResponse", TestFireActionErrorsResponse
),
401: RESPONSE_UNAUTHORIZED,
404: RESPONSE_NOT_FOUND,
},
Expand Down
Loading