Skip to content

publish api endpoints #77179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 25 additions & 7 deletions src/sentry/api/endpoints/organization_user_teams.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from drf_spectacular.utils import extend_schema
from rest_framework.request import Request
from rest_framework.response import Response

Expand All @@ -7,26 +8,43 @@
from sentry.api.bases.organization import OrganizationEndpoint
from sentry.api.serializers import serialize
from sentry.api.serializers.models.team import TeamWithProjectsSerializer
from sentry.apidocs.constants import RESPONSE_BAD_REQUEST, RESPONSE_FORBIDDEN
from sentry.apidocs.examples.team_examples import TeamExamples
from sentry.apidocs.parameters import GlobalParams
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.auth.superuser import is_active_superuser
from sentry.models.team import Team, TeamStatus


@extend_schema(tags=["Teams"])
@region_silo_endpoint
class OrganizationUserTeamsEndpoint(OrganizationEndpoint):
publish_status = {
"GET": ApiPublishStatus.UNKNOWN,
"GET": ApiPublishStatus.PUBLIC,
}
owner = ApiOwner.ENTERPRISE

@extend_schema(
operation_id="List a User's Teams for an Organization",
parameters=[GlobalParams.ORG_ID_OR_SLUG],
request=None,
responses={
200: inline_sentry_response_serializer(
"ListOrgTeamResponse", list[TeamWithProjectsSerializer]
),
400: RESPONSE_BAD_REQUEST,
403: RESPONSE_FORBIDDEN,
},
examples=TeamExamples.LIST_ORG_TEAMS,
)
def get(self, request: Request, organization) -> Response:
"""
List your Teams In the Current Organization
```````````````````````````````````````````

Return a list of the teams available to the authenticated session and
with the supplied organization. If the user is a super user, then all
teams within the organization are returned.
Returns a list of teams the user has access to in the specified organization.
Note that this endpoint is restricted to [user auth tokens](https://docs.sentry.io/account/auth-tokens/#user-auth-tokens).
"""
# Return a list of the teams available to the authenticated session and
# with the supplied organization. If the user is a super user, then all
# teams within the organization are returned.
if is_active_superuser(request):
# retrieve all teams within the organization
queryset = Team.objects.filter(
Expand Down
25 changes: 24 additions & 1 deletion src/sentry/api/endpoints/project_member_index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db.models import Q
from drf_spectacular.utils import extend_schema
from rest_framework.request import Request
from rest_framework.response import Response

Expand All @@ -7,17 +8,39 @@
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.project import ProjectEndpoint
from sentry.api.serializers import serialize
from sentry.api.serializers.models.organization_member.response import OrganizationMemberResponse
from sentry.apidocs.constants import RESPONSE_BAD_REQUEST, RESPONSE_FORBIDDEN
from sentry.apidocs.examples.organization_member_examples import OrganizationMemberExamples
from sentry.apidocs.parameters import GlobalParams
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.models.organizationmember import OrganizationMember


@extend_schema(tags=["Projects"])
@region_silo_endpoint
class ProjectMemberIndexEndpoint(ProjectEndpoint):
publish_status = {
"GET": ApiPublishStatus.UNKNOWN,
"GET": ApiPublishStatus.PUBLIC,
}
owner = ApiOwner.ENTERPRISE

@extend_schema(
operation_id="List a Project's Organization Members",
parameters=[GlobalParams.ORG_ID_OR_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
request=None,
responses={
200: inline_sentry_response_serializer(
"ListOrgMembersResponse", list[OrganizationMemberResponse]
),
400: RESPONSE_BAD_REQUEST,
403: RESPONSE_FORBIDDEN,
},
examples=OrganizationMemberExamples.LIST_ORG_MEMBERS,
)
def get(self, request: Request, project) -> Response:
"""
Returns a list of active organization member's that belong to any team assigned to the project.
Copy link
Contributor

Choose a reason for hiding this comment

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

whoops I had a typo

Suggested change
Returns a list of active organization member's that belong to any team assigned to the project.
Returns a list of active organization members that belong to any team assigned to the project.

"""
queryset = OrganizationMember.objects.filter(
Q(user_is_active=True, user_id__isnull=False) | Q(user_id__isnull=True),
organization=project.organization,
Expand Down
Loading