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
9 changes: 7 additions & 2 deletions src/sentry/api/endpoints/organization_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sentry.api.bases.organization import OrganizationEndpoint, OrganizationPermission
from sentry.api.paginator import OffsetPaginator
from sentry.api.serializers import serialize
from sentry.api.serializers.models.team import TeamWithProjectsSerializer
from sentry.api.serializers.models import team as team_serializers
from sentry.models import (
AuditLogEntryEvent, OrganizationMember, OrganizationMemberTeam, Team, TeamStatus
)
Expand Down Expand Up @@ -81,6 +81,7 @@ def get(self, request, organization):

:pparam string organization_slug: the slug of the organization for
which the teams should be listed.
:param string detailed: Specify "0" to return team details that do not include projects
Copy link
Member

Choose a reason for hiding this comment

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

Would a better name be sparse? And then it can do the inverse here.

Copy link
Member

Choose a reason for hiding this comment

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

We use detailed elsewhere, and I think that makes sense in terms of how we'd like our API to behave. Ideally our default behaviour becomes not detailed, and people have to explicitly ask for detailed, and so pass detailed=1

Copy link
Member Author

Choose a reason for hiding this comment

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

See this thread #13925 (comment)

:auth: required
"""
# TODO(dcramer): this should be system-wide default for organization
Expand All @@ -94,6 +95,7 @@ def get(self, request, organization):
).order_by('slug')

query = request.GET.get('query')

if query:
tokens = tokenize_query(query)
for key, value in six.iteritems(tokens):
Expand All @@ -103,11 +105,14 @@ def get(self, request, organization):
else:
queryset = queryset.none()

is_detailed = request.GET.get('detailed', '1') != '0'
serializer = team_serializers.TeamWithProjectsSerializer if is_detailed else team_serializers.TeamSerializer

return self.paginate(
request=request,
queryset=queryset,
order_by='slug',
on_results=lambda x: serialize(x, request.user, TeamWithProjectsSerializer()),
on_results=lambda x: serialize(x, request.user, serializer()),
paginator_cls=OffsetPaginator,
)

Expand Down
24 changes: 24 additions & 0 deletions tests/sentry/api/endpoints/test_organization_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ def test_simple(self):
assert response.data[1]['id'] == six.text_type(team1.id)
assert response.data[1]['isMember']

def test_simple_results_no_projects(self):
user = self.create_user()
org = self.create_organization(owner=self.user)
team1 = self.create_team(organization=org, name='foo')
self.create_team(organization=org, name='bar')

self.create_member(
organization=org,
user=user,
has_global_access=False,
teams=[team1],
)

path = u'/api/0/organizations/{}/teams/?detailed=0'.format(org.slug)

self.login_as(user=user)

response = self.client.get(path)

assert response.status_code == 200, response.content
assert len(response.data) == 2
assert 'projects' not in response.data[0]
assert 'projects' not in response.data[1]

def test_search(self):
user = self.create_user()
org = self.create_organization(owner=self.user)
Expand Down