|
@@ -6,13 +6,12 @@ from sentry.api.bases.organization import OrganizationEndpoint
|
|
|
from sentry.api.serializers import serialize
|
|
|
from sentry.api.serializers.models.group import StreamGroupSerializer
|
|
|
from sentry.models import (
|
|
|
- EventUser, Group, GroupTagValue, OrganizationMember,
|
|
|
- OrganizationMemberTeam, Project, Team
|
|
|
+ EventUser, Group, GroupTagValue,
|
|
|
+ OrganizationMemberTeam, Project
|
|
|
)
|
|
|
|
|
|
|
|
|
class OrganizationUserIssuesSearchEndpoint(OrganizationEndpoint):
|
|
|
-
|
|
|
def get(self, request, organization):
|
|
|
email = request.GET.get('email')
|
|
|
|
|
@@ -22,33 +21,30 @@ class OrganizationUserIssuesSearchEndpoint(OrganizationEndpoint):
|
|
|
limit = request.GET.get('limit', 100)
|
|
|
|
|
|
# limit to only teams user has opted into
|
|
|
- member = OrganizationMember.objects.get(user=request.user,
|
|
|
- organization=organization)
|
|
|
- teams = Team.objects.filter(
|
|
|
- id__in=OrganizationMemberTeam.objects.filter(
|
|
|
- organizationmember=member,
|
|
|
+ project_ids = list(Project.objects.filter(
|
|
|
+ team__in=OrganizationMemberTeam.objects.filter(
|
|
|
+ organizationmember__user=request.user,
|
|
|
+ organizationmember__organization=organization,
|
|
|
is_active=True,
|
|
|
- ).values('team')
|
|
|
- )
|
|
|
-
|
|
|
- projects = Project.objects.filter(
|
|
|
- team__in=list(teams),
|
|
|
- )
|
|
|
-
|
|
|
- event_users = EventUser.objects.filter(email=email,
|
|
|
- project_id__in=[p.id for p in projects])[:1000]
|
|
|
+ ).values('team'),
|
|
|
+ ).values_list('id', flat=True)[:1000])
|
|
|
|
|
|
- projects = list(set([e.project_id for e in event_users]))
|
|
|
+ event_users = EventUser.objects.filter(
|
|
|
+ email__iexact=email,
|
|
|
+ project_id__in=project_ids,
|
|
|
+ )[:1000]
|
|
|
|
|
|
- tag_values = [eu.tag_value for eu in event_users]
|
|
|
- tags = GroupTagValue.objects.filter(key='sentry:user',
|
|
|
- value__in=tag_values,
|
|
|
- project_id__in=projects)
|
|
|
+ project_ids = list(set([e.project_id for e in event_users]))
|
|
|
|
|
|
- group_ids = set(tags.values_list('group_id', flat=True))
|
|
|
+ group_ids = list(GroupTagValue.objects.filter(
|
|
|
+ key='sentry:user',
|
|
|
+ value__in=[eu.tag_value for eu in event_users],
|
|
|
+ project_id__in=project_ids,
|
|
|
+ ).order_by('-last_seen').values_list('group_id', flat=True)[:limit])
|
|
|
|
|
|
- groups = Group.objects.filter(id__in=group_ids,
|
|
|
- project_id__in=projects).order_by('-last_seen')[:limit]
|
|
|
+ groups = Group.objects.filter(
|
|
|
+ id__in=group_ids,
|
|
|
+ ).order_by('-last_seen')[:limit]
|
|
|
|
|
|
context = serialize(
|
|
|
list(groups), request.user, StreamGroupSerializer(
|
|
@@ -56,6 +52,4 @@ class OrganizationUserIssuesSearchEndpoint(OrganizationEndpoint):
|
|
|
)
|
|
|
)
|
|
|
|
|
|
- response = Response(context)
|
|
|
-
|
|
|
- return response
|
|
|
+ return Response(context)
|