@@ -120,39 +120,8 @@ class DetailedOrganizationSerializer(OrganizationSerializer):
120120 def get_attrs (self , item_list , user , ** kwargs ):
121121 return super (DetailedOrganizationSerializer , self ).get_attrs (item_list , user )
122122
123- def _project_list (self , organization , access ):
124- member_projects = list (access .projects )
125- member_project_ids = [p .id for p in member_projects ]
126- other_projects = list (Project .objects .filter (
127- organization = organization ,
128- status = ProjectStatus .VISIBLE ,
129- ).exclude (id__in = member_project_ids ))
130- project_list = sorted (other_projects + member_projects , key = lambda x : x .slug )
131-
132- for project in project_list :
133- project ._organization_cache = organization
134- return project_list
135-
136- def _team_list (self , organization , access ):
137- member_teams = list (access .teams )
138- member_team_ids = [p .id for p in member_teams ]
139- other_teams = list (Team .objects .filter (
140- organization = organization ,
141- status = TeamStatus .VISIBLE ,
142- ).exclude (id__in = member_team_ids ))
143- team_list = sorted (other_teams + member_teams , key = lambda x : x .slug )
144-
145- for team in team_list :
146- team ._organization_cache = organization
147- return team_list
148-
149123 def serialize (self , obj , attrs , user , access ):
150124 from sentry import experiments
151- from sentry .api .serializers .models .project import ProjectSummarySerializer
152- from sentry .api .serializers .models .team import TeamSerializer
153-
154- team_list = self ._team_list (obj , access )
155- project_list = self ._project_list (obj , access )
156125
157126 onboarding_tasks = list (
158127 OrganizationOnboardingTask .objects .filter (
@@ -205,11 +174,61 @@ def serialize(self, obj, attrs, user, access):
205174 'scrapeJavaScript' : bool (obj .get_option ('sentry:scrape_javascript' , SCRAPE_JAVASCRIPT_DEFAULT )),
206175 'trustedRelays' : obj .get_option ('sentry:trusted-relays' , TRUSTED_RELAYS_DEFAULT ) or [],
207176 })
208- context ['teams' ] = serialize (team_list , user , TeamSerializer ())
209- context ['projects' ] = serialize (project_list , user , ProjectSummarySerializer ())
210177 context ['access' ] = access .scopes
211178 context ['pendingAccessRequests' ] = OrganizationAccessRequest .objects .filter (
212179 team__organization = obj ,
213180 ).count ()
214181 context ['onboardingTasks' ] = serialize (onboarding_tasks , user , OnboardingTasksSerializer ())
215182 return context
183+
184+
185+ class DetailedOrganizationSerializerWithProjectsAndTeams (DetailedOrganizationSerializer ):
186+ def get_attrs (self , item_list , user , ** kwargs ):
187+ return super (DetailedOrganizationSerializerWithProjectsAndTeams ,
188+ self ).get_attrs (item_list , user )
189+
190+ def _project_list (self , organization , access ):
191+ member_projects = list (access .projects )
192+ member_project_ids = [p .id for p in member_projects ]
193+ other_projects = list (Project .objects .filter (
194+ organization = organization ,
195+ status = ProjectStatus .VISIBLE ,
196+ ).exclude (id__in = member_project_ids ))
197+ project_list = sorted (other_projects + member_projects , key = lambda x : x .slug )
198+
199+ for project in project_list :
200+ project ._organization_cache = organization
201+ return project_list
202+
203+ def _team_list (self , organization , access ):
204+ member_teams = list (access .teams )
205+ member_team_ids = [p .id for p in member_teams ]
206+ other_teams = list (Team .objects .filter (
207+ organization = organization ,
208+ status = TeamStatus .VISIBLE ,
209+ ).exclude (id__in = member_team_ids ))
210+ team_list = sorted (other_teams + member_teams , key = lambda x : x .slug )
211+
212+ for team in team_list :
213+ team ._organization_cache = organization
214+ return team_list
215+
216+ def serialize (self , obj , attrs , user , access ):
217+ from sentry .api .serializers .models .project import ProjectSummarySerializer
218+ from sentry .api .serializers .models .team import TeamSerializer
219+
220+ context = super (
221+ DetailedOrganizationSerializerWithProjectsAndTeams ,
222+ self ).serialize (
223+ obj ,
224+ attrs ,
225+ user ,
226+ access )
227+
228+ team_list = self ._team_list (obj , access )
229+ project_list = self ._project_list (obj , access )
230+
231+ context ['teams' ] = serialize (team_list , user , TeamSerializer ())
232+ context ['projects' ] = serialize (project_list , user , ProjectSummarySerializer ())
233+
234+ return context
0 commit comments