Skip to content

Commit

Permalink
fix(api): make UserEmailsEndpoint private (#83867)
Browse files Browse the repository at this point in the history
make `UserEmailsEndpoint` private
  • Loading branch information
ameliahsu authored and andrewshie-sentry committed Jan 29, 2025
1 parent b3a3e1d commit 2c47cbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 101 deletions.
35 changes: 0 additions & 35 deletions src/sentry/apidocs/examples/user_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,3 @@ class UserExamples:
response_only=True,
)
]

LIST_USER_EMAILS = [
OpenApiExample(
"List user emails",
value=[
{
"email": "[email protected]",
"isPrimary": True,
"isVerified": True,
},
{
"email": "[email protected]",
"isPrimary": False,
"isVerified": True,
},
],
status_codes=["200"],
response_only=True,
)
]

ADD_SECONDARY_EMAIL = [
OpenApiExample(
"Adds a secondary email",
value=[
{
"email": "[email protected]",
"isPrimary": True,
"isVerified": True,
},
],
status_codes=["200", "201"],
response_only=True,
)
]
71 changes: 5 additions & 66 deletions src/sentry/users/api/endpoints/user_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.db import IntegrityError, router, transaction
from django.db.models import Q
from django.utils.translation import gettext as _
from drf_spectacular.utils import extend_schema
from rest_framework import serializers
from rest_framework.request import Request
from rest_framework.response import Response
Expand All @@ -15,17 +14,8 @@
from sentry.api.decorators import sudo_required
from sentry.api.serializers import serialize
from sentry.api.validators import AllowedEmailField
from sentry.apidocs.constants import (
RESPONSE_BAD_REQUEST,
RESPONSE_CONFLICT,
RESPONSE_FORBIDDEN,
RESPONSE_NO_CONTENT,
)
from sentry.apidocs.examples.user_examples import UserExamples
from sentry.apidocs.parameters import GlobalParams
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.users.api.bases.user import UserEndpoint
from sentry.users.api.serializers.useremail import UserEmailSerializer, UserEmailSerializerResponse
from sentry.users.api.serializers.useremail import UserEmailSerializer
from sentry.users.models.user import User
from sentry.users.models.user_option import UserOption
from sentry.users.models.useremail import UserEmail
Expand Down Expand Up @@ -94,29 +84,16 @@ def add_email(email: str, user: User) -> UserEmail:
return new_email


@extend_schema(tags=["Users"])
@control_silo_endpoint
class UserEmailsEndpoint(UserEndpoint):
publish_status = {
"DELETE": ApiPublishStatus.PUBLIC,
"GET": ApiPublishStatus.PUBLIC,
"PUT": ApiPublishStatus.PUBLIC,
"POST": ApiPublishStatus.PUBLIC,
"DELETE": ApiPublishStatus.PRIVATE,
"GET": ApiPublishStatus.PRIVATE,
"PUT": ApiPublishStatus.PRIVATE,
"POST": ApiPublishStatus.PRIVATE,
}
owner = ApiOwner.UNOWNED

@extend_schema(
operation_id="List user emails",
parameters=[GlobalParams.USER_ID],
request=None,
responses={
200: inline_sentry_response_serializer(
"UserEmailSerializerResponse", list[UserEmailSerializerResponse]
),
403: RESPONSE_FORBIDDEN,
},
examples=UserExamples.LIST_USER_EMAILS,
)
def get(self, request: Request, user: User) -> Response:
"""
Returns a list of emails. Primary email will have `isPrimary: true`
Expand All @@ -129,22 +106,6 @@ def get(self, request: Request, user: User) -> Response:
status=200,
)

@extend_schema(
operation_id="Add a secondary email address",
parameters=[GlobalParams.USER_ID],
request=EmailValidator,
responses={
200: inline_sentry_response_serializer(
"UserEmailSerializerResponse", list[UserEmailSerializerResponse]
),
201: inline_sentry_response_serializer(
"UserEmailSerializerResponse", list[UserEmailSerializerResponse]
),
403: RESPONSE_FORBIDDEN,
409: RESPONSE_CONFLICT,
},
examples=UserExamples.ADD_SECONDARY_EMAIL,
)
@sudo_required
def post(self, request: Request, user: User) -> Response:
"""
Expand Down Expand Up @@ -196,18 +157,6 @@ def post(self, request: Request, user: User) -> Response:
status=409,
)

@extend_schema(
operation_id="Update a primary email address",
parameters=[GlobalParams.USER_ID],
request=EmailValidator,
responses={
200: inline_sentry_response_serializer(
"UserEmailSerializerResponse", list[UserEmailSerializerResponse]
),
403: RESPONSE_FORBIDDEN,
400: RESPONSE_BAD_REQUEST,
},
)
@sudo_required
def put(self, request: Request, user: User) -> Response:
"""
Expand Down Expand Up @@ -299,16 +248,6 @@ def put(self, request: Request, user: User) -> Response:
status=200,
)

@extend_schema(
operation_id="Remove an email address",
parameters=[GlobalParams.USER_ID],
request=UserEmailSerializer,
responses={
204: RESPONSE_NO_CONTENT,
403: RESPONSE_FORBIDDEN,
400: RESPONSE_BAD_REQUEST,
},
)
@sudo_required
def delete(self, request: Request, user: User) -> Response:
"""
Expand Down

0 comments on commit 2c47cbb

Please sign in to comment.