|
1 | 1 | from __future__ import absolute_import |
2 | 2 | |
| 3 | +import itertools |
| 4 | + |
3 | 5 | from rest_framework import serializers, status |
4 | 6 | from rest_framework.response import Response |
5 | 7 | |
@@ -8,7 +10,7 @@
|
8 | 10 | from sentry.api.decorators import sudo_required |
9 | 11 | from sentry.api.serializers import serialize |
10 | 12 | from sentry.models import ( |
11 | | -AuditLogEntry, AuditLogEntryEvent, Organization, OrganizationStatus |
| 13 | +AuditLogEntry, AuditLogEntryEvent, Organization, OrganizationStatus, Team |
12 | 14 | ) |
13 | 15 | from sentry.tasks.deletion import delete_organization |
14 | 16 | |
@@ -37,7 +39,36 @@ def get(self, request, organization):
|
37 | 39 | {method} {path} |
38 | 40 | |
39 | 41 | """ |
| 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 | + |
40 | 70 | context = serialize(organization, request.user) |
| 71 | +context['teams'] = teams_context |
41 | 72 | |
42 | 73 | return Response(context) |
43 | 74 | |
|