Browse Source

chore(hybrid-cloud): Update OrganizationSentryAppComponentsEndpoint to be a control silo endpoint (#54763)

Alberto Leal 1 year ago
parent
commit
3ad762f7ed

+ 17 - 9
src/sentry/api/endpoints/integrations/sentry_apps/components.py

@@ -2,16 +2,17 @@ from rest_framework.request import Request
 from rest_framework.response import Response
 from rest_framework.response import Response
 
 
 from sentry.api.base import control_silo_endpoint
 from sentry.api.base import control_silo_endpoint
-from sentry.api.bases import (
-    OrganizationEndpoint,
-    SentryAppBaseEndpoint,
-    add_integration_platform_metric_tag,
-)
+from sentry.api.bases import SentryAppBaseEndpoint, add_integration_platform_metric_tag
+from sentry.api.bases.organization import ControlSiloOrganizationEndpoint
 from sentry.api.paginator import OffsetPaginator
 from sentry.api.paginator import OffsetPaginator
 from sentry.api.serializers import serialize
 from sentry.api.serializers import serialize
 from sentry.coreapi import APIError
 from sentry.coreapi import APIError
 from sentry.models import SentryAppComponent, SentryAppInstallation
 from sentry.models import SentryAppComponent, SentryAppInstallation
 from sentry.sentry_apps.components import SentryAppComponentPreparer
 from sentry.sentry_apps.components import SentryAppComponentPreparer
+from sentry.services.hybrid_cloud.organization.model import (
+    RpcOrganization,
+    RpcUserOrganizationContext,
+)
 
 
 
 
 # TODO(mgaeta): These endpoints are doing the same thing, but one takes a
 # TODO(mgaeta): These endpoints are doing the same thing, but one takes a
@@ -29,16 +30,23 @@ class SentryAppComponentsEndpoint(SentryAppBaseEndpoint):
 
 
 
 
 @control_silo_endpoint
 @control_silo_endpoint
-class OrganizationSentryAppComponentsEndpoint(OrganizationEndpoint):
+class OrganizationSentryAppComponentsEndpoint(ControlSiloOrganizationEndpoint):
     @add_integration_platform_metric_tag
     @add_integration_platform_metric_tag
-    def get(self, request: Request, organization) -> Response:
+    def get(
+        self,
+        request: Request,
+        organization_context: RpcUserOrganizationContext,
+        organization: RpcOrganization,
+    ) -> Response:
         components = []
         components = []
         errors = []
         errors = []
 
 
         for install in SentryAppInstallation.objects.get_installed_for_organization(
         for install in SentryAppInstallation.objects.get_installed_for_organization(
             organization.id
             organization.id
-        ):
-            _components = SentryAppComponent.objects.filter(sentry_app_id=install.sentry_app_id)
+        ).order_by("pk"):
+            _components = SentryAppComponent.objects.filter(
+                sentry_app_id=install.sentry_app_id
+            ).order_by("pk")
 
 
             if "filter" in request.GET:
             if "filter" in request.GET:
                 _components = _components.filter(type=request.GET["filter"])
                 _components = _components.filter(type=request.GET["filter"])

+ 6 - 4
tests/sentry/api/endpoints/test_sentry_app_components.py

@@ -84,9 +84,9 @@ class OrganizationSentryAppComponentsTest(APITestCase):
             status=SentryAppInstallationStatus.PENDING,
             status=SentryAppInstallationStatus.PENDING,
         )
         )
 
 
-        self.component1 = self.sentry_app1.components.first()
-        self.component2 = self.sentry_app2.components.first()
-        self.component3 = self.sentry_app3.components.first()
+        self.component1 = self.sentry_app1.components.order_by("pk").first()
+        self.component2 = self.sentry_app2.components.order_by("pk").first()
+        self.component3 = self.sentry_app3.components.order_by("pk").first()
 
 
         self.login_as(user=self.user)
         self.login_as(user=self.user)
 
 
@@ -168,7 +168,7 @@ class OrganizationSentryAppComponentsTest(APITestCase):
 
 
         # self.component1 data contains an error, because it raised an exception
         # self.component1 data contains an error, because it raised an exception
         # during preparation.
         # during preparation.
-        assert response.data == [
+        expected = [
             {
             {
                 "uuid": str(self.component1.uuid),
                 "uuid": str(self.component1.uuid),
                 "type": self.component1.type,
                 "type": self.component1.type,
@@ -194,3 +194,5 @@ class OrganizationSentryAppComponentsTest(APITestCase):
                 },
                 },
             },
             },
         ]
         ]
+
+        assert response.data == expected