|
@@ -1,10 +1,13 @@
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
+from rest_framework.response import Response
|
|
|
+
|
|
|
from sentry.api.bases import OrganizationEndpoint, SentryAppBaseEndpoint
|
|
|
from sentry.api.paginator import OffsetPaginator
|
|
|
from sentry.api.serializers import serialize
|
|
|
from sentry.features.helpers import requires_feature
|
|
|
-from sentry.models import SentryAppComponent, SentryApp
|
|
|
+from sentry.mediators import sentry_app_components
|
|
|
+from sentry.models import Project, SentryAppComponent
|
|
|
|
|
|
|
|
|
class SentryAppComponentsEndpoint(SentryAppBaseEndpoint):
|
|
@@ -21,13 +24,36 @@ class SentryAppComponentsEndpoint(SentryAppBaseEndpoint):
|
|
|
class OrganizationSentryAppComponentsEndpoint(OrganizationEndpoint):
|
|
|
@requires_feature('organizations:sentry-apps')
|
|
|
def get(self, request, organization):
|
|
|
+ try:
|
|
|
+ project = Project.objects.get(
|
|
|
+ id=request.GET['projectId'],
|
|
|
+ organization_id=organization.id,
|
|
|
+ )
|
|
|
+ except Project.DoesNotExist:
|
|
|
+ return Response([], status=404)
|
|
|
+
|
|
|
+ components = []
|
|
|
+
|
|
|
+ for install in organization.sentry_app_installations.all():
|
|
|
+ _components = SentryAppComponent.objects.filter(
|
|
|
+ sentry_app_id=install.sentry_app_id,
|
|
|
+ )
|
|
|
+
|
|
|
+ if 'filter' in request.GET:
|
|
|
+ _components = _components.filter(type=request.GET['filter'])
|
|
|
+
|
|
|
+ for component in _components:
|
|
|
+ sentry_app_components.Preparer.run(
|
|
|
+ component=component,
|
|
|
+ install=install,
|
|
|
+ project=project,
|
|
|
+ )
|
|
|
+
|
|
|
+ components.extend(_components)
|
|
|
+
|
|
|
return self.paginate(
|
|
|
request=request,
|
|
|
- queryset=SentryAppComponent.objects.filter(
|
|
|
- sentry_app_id__in=SentryApp.objects.filter(
|
|
|
- installations__in=organization.sentry_app_installations.all(),
|
|
|
- )
|
|
|
- ),
|
|
|
+ queryset=components,
|
|
|
paginator_cls=OffsetPaginator,
|
|
|
on_results=lambda x: serialize(x, request.user),
|
|
|
)
|