Browse Source

feat(api): Add endpoint to list a project's teams

Jess MacQueen 7 years ago
parent
commit
6e31aad3a3
3 changed files with 39 additions and 0 deletions
  1. 1 0
      CHANGES
  2. 32 0
      src/sentry/api/endpoints/project_teams.py
  3. 6 0
      src/sentry/api/urls.py

+ 1 - 0
CHANGES

@@ -11,6 +11,7 @@ API Changes
 ~~~~~~~~~~~
 - Project plugins endpoint returns every configurable plugin, and includes additional information about each one
 - Added user "appearances" endpoint to list and modify appearance options.
+- Add endpoint to list a project's teams
 
 Version 8.22
 ------------

+ 32 - 0
src/sentry/api/endpoints/project_teams.py

@@ -0,0 +1,32 @@
+from __future__ import absolute_import
+
+from sentry.api.bases.project import ProjectEndpoint
+from sentry.api.paginator import OffsetPaginator
+from sentry.api.serializers import serialize
+from sentry.models import Team
+
+
+class ProjectTeamsEndpoint(ProjectEndpoint):
+
+    def get(self, request, project):
+        """
+        List a Project's Teams
+        ``````````````````````
+
+        Return a list of teams that have access to this project.
+
+        :pparam string organization_slug: the slug of the organization.
+        :pparam string project_slug: the slug of the project.
+        :auth: required
+        """
+        queryset = Team.objects.filter(
+            projectteam__project=project,
+        )
+
+        return self.paginate(
+            request=request,
+            queryset=queryset,
+            order_by='name',
+            paginator_cls=OffsetPaginator,
+            on_results=lambda x: serialize(x, request.user),
+        )

+ 6 - 0
src/sentry/api/urls.py

@@ -104,6 +104,7 @@ from .endpoints.project_stats import ProjectStatsEndpoint
 from .endpoints.project_tags import ProjectTagsEndpoint
 from .endpoints.project_tagkey_details import ProjectTagKeyDetailsEndpoint
 from .endpoints.project_tagkey_values import ProjectTagKeyValuesEndpoint
+from .endpoints.project_teams import ProjectTeamsEndpoint
 from .endpoints.project_processingissues import ProjectProcessingIssuesEndpoint, \
     ProjectProcessingIssuesFixEndpoint, ProjectProcessingIssuesDiscardEndpoint
 from .endpoints.project_reprocessing import ProjectReprocessingEndpoint
@@ -637,6 +638,11 @@ urlpatterns = patterns(
         ProjectTagKeyValuesEndpoint.as_view(),
         name='sentry-api-0-project-tagkey-values'
     ),
+    url(
+        r'^projects/(?P<organization_slug>[^\/]+)/(?P<project_slug>[^\/]+)/teams/',
+        ProjectTeamsEndpoint.as_view(),
+        name='sentry-api-0-project-teams'
+    ),
     url(
         r'^projects/(?P<organization_slug>[^\/]+)/(?P<project_slug>[^\/]+)/users/$',
         ProjectUsersEndpoint.as_view(),