GitHub

Original file line numberDiff line numberDiff line change

@@ -1,5 +1,7 @@

11

from __future__ import absolute_import

22
3+

import itertools

4+
35

from rest_framework import serializers, status

46

from rest_framework.response import Response

57

@@ -8,7 +10,7 @@

810

from sentry.api.decorators import sudo_required

911

from sentry.api.serializers import serialize

1012

from sentry.models import (

11-

AuditLogEntry, AuditLogEntryEvent, Organization, OrganizationStatus

13+

AuditLogEntry, AuditLogEntryEvent, Organization, OrganizationStatus, Team

1214

)

1315

from sentry.tasks.deletion import delete_organization

1416

@@ -37,7 +39,36 @@ def get(self, request, organization):

3739

{method} {path}

3840
3941

"""

42+

team_list = Team.objects.get_for_user(

43+

organization=organization,

44+

user=request.user,

45+

with_projects=True,

46+

)

47+

team_map = {

48+

t[0].id: s

49+

for t, s in zip(

50+

team_list,

51+

serialize([t for t, _ in team_list], request.user)

52+

)

53+

}

54+
55+

project_list = list(itertools.chain(*[p for _, p in team_list]))

56+

project_map = {

57+

p.id: s

58+

for p, s in zip(

59+

project_list,

60+

serialize(project_list, request.user)

61+

)

62+

}

63+
64+

teams_context = []

65+

for team, project_list in team_list:

66+

team_data = team_map[team.id]

67+

team_data['projects'] = [project_map[p.id] for p in project_list]

68+

teams_context.append(team_data)

69+
4070

context = serialize(organization, request.user)

71+

context['teams'] = teams_context

4172
4273

return Response(context)

4374

Read the original on github.com ↗