1
1
from __future__ import absolute_import
2
2
3
3
from sentry .cache import default_cache
4
- from django .core .urlresolvers import reverse
5
4
6
- from sentry . api import client
5
+ from sentry import roles
7
6
from sentry .models import ApiToken
8
7
from sentry .api .serializers import serialize
9
8
from sentry .web .frontend .base import BaseView
10
9
from sentry .web .helpers import render_to_response
10
+ from sentry .models import (Organization , OrganizationStatus , Project , ProjectKey ,
11
+ ProjectKeyStatus , ProjectStatus )
11
12
from sentry .api .endpoints .setup_wizard import SETUP_WIZARD_CACHE_KEY , SETUP_WIZARD_CACHE_TIMEOUT
12
13
13
14
@@ -27,25 +28,28 @@ def get(self, request, wizard_hash):
27
28
if wizard_data is None :
28
29
return self .redirect_to_org (request )
29
30
30
- orgs = client .get (
31
- reverse ('sentry-api-0-organizations' ), request = request )
31
+ orgs = Organization .objects .filter (
32
+ member_set__role__in = [x .id for x in roles .with_scope ('org:read' )],
33
+ member_set__user = request .user ,
34
+ status = OrganizationStatus .VISIBLE ,
35
+ ).order_by ('-date_added' )[:50 ]
32
36
33
37
filled_projects = []
34
38
35
- for org in orgs . data :
36
- projects = client . get ( reverse ( 'sentry-api-0-organization-projects' , kwargs = {
37
- 'organization_slug' : org . get ( 'slug' )
38
- }), request = request )
39
- for project in projects . data :
40
- if project . get ( 'status' ) == 'deleted' :
41
- continue # skip if project has been deleted
42
- enriched_project = project
43
- enriched_project [ 'organization' ] = org
44
- keys = client . get ( reverse ( 'sentry-api-0-project-keys' , kwargs = {
45
- 'organization_slug' : org . get ( 'slug' ) ,
46
- 'project_slug' : project . get ( 'slug' )
47
- }), request = request )
48
- enriched_project ['keys' ] = keys . data
39
+ for org in orgs :
40
+ projects = list ( Project . objects . filter (
41
+ organization = org ,
42
+ status = ProjectStatus . VISIBLE ,
43
+ ). order_by ( '-date_added' )[: 50 ])
44
+ for project in projects :
45
+ enriched_project = serialize ( project )
46
+ enriched_project [ 'organization' ] = serialize ( org )
47
+ keys = list ( ProjectKey . objects . filter (
48
+ project = project ,
49
+ roles = ProjectKey . roles . store ,
50
+ status = ProjectKeyStatus . ACTIVE ,
51
+ ) )
52
+ enriched_project ['keys' ] = serialize ( keys )
49
53
filled_projects .append (enriched_project )
50
54
51
55
# Fetching or creating a token
0 commit comments