Browse Source

feat(api-idorslug): Update Some Endpoints use `organization_id_or_slug` (#70556)

A subset of changes from https://github.com/getsentry/sentry/pull/70081!
Raj Joshi 10 months ago
parent
commit
4d8451c961

+ 8 - 6
src/sentry/api/bases/group.py

@@ -40,7 +40,9 @@ class GroupEndpoint(Endpoint):
     owner = ApiOwner.ISSUES
     permission_classes = (GroupPermission,)
 
-    def convert_args(self, request: Request, issue_id, organization_slug=None, *args, **kwargs):
+    def convert_args(
+        self, request: Request, issue_id, organization_id_or_slug=None, *args, **kwargs
+    ):
         # TODO(tkaemming): Ideally, this would return a 302 response, rather
         # than just returning the data that is bound to the new group. (It
         # technically shouldn't be a 301, since the response could change again
@@ -51,17 +53,17 @@ class GroupEndpoint(Endpoint):
         # string replacement, or making the endpoint aware of the URL pattern
         # that caused it to be dispatched, and reversing it with the correct
         # `issue_id` keyword argument.
-        if organization_slug:
+        if organization_id_or_slug:
             try:
                 if (
                     id_or_slug_path_params_enabled(
-                        self.convert_args.__qualname__, str(organization_slug)
+                        self.convert_args.__qualname__, str(organization_id_or_slug)
                     )
-                    and str(organization_slug).isdecimal()
+                    and str(organization_id_or_slug).isdecimal()
                 ):
-                    organization = Organization.objects.get_from_cache(id=organization_slug)
+                    organization = Organization.objects.get_from_cache(id=organization_id_or_slug)
                 else:
-                    organization = Organization.objects.get_from_cache(slug=organization_slug)
+                    organization = Organization.objects.get_from_cache(slug=organization_id_or_slug)
             except Organization.DoesNotExist:
                 raise ResourceDoesNotExist
 

+ 7 - 5
src/sentry/api/bases/sentryapps.py

@@ -325,22 +325,24 @@ class SentryAppInstallationsPermission(SentryPermission):
 class SentryAppInstallationsBaseEndpoint(IntegrationPlatformEndpoint):
     permission_classes = (SentryAppInstallationsPermission,)
 
-    def convert_args(self, request: Request, organization_slug, *args, **kwargs):
+    def convert_args(self, request: Request, organization_id_or_slug, *args, **kwargs):
         extra_args = {}
         # We need to pass user_id if the user is not a superuser
         if not is_active_superuser(request):
             extra_args["user_id"] = request.user.id
 
         if (
-            id_or_slug_path_params_enabled(self.convert_args.__qualname__, str(organization_slug))
-            and str(organization_slug).isdecimal()
+            id_or_slug_path_params_enabled(
+                self.convert_args.__qualname__, str(organization_id_or_slug)
+            )
+            and str(organization_id_or_slug).isdecimal()
         ):
             organization = organization_service.get_org_by_id(
-                id=int(organization_slug), **extra_args
+                id=int(organization_id_or_slug), **extra_args
             )
         else:
             organization = organization_service.get_org_by_slug(
-                slug=organization_slug, **extra_args
+                slug=str(organization_id_or_slug), **extra_args
             )
 
         if organization is None:

+ 2 - 2
src/sentry/api/urls.py

@@ -1113,7 +1113,7 @@ ORGANIZATION_URLS = [
         name="sentry-api-0-organization-details",
     ),
     re_path(
-        r"^(?P<organization_slug>[^\/]+)/(?:issues|groups)/",
+        r"^(?P<organization_id_or_slug>[^\/]+)/(?:issues|groups)/",
         include(create_group_urls("sentry-api-0-organization-group")),
     ),
     # Alert Rules
@@ -1870,7 +1870,7 @@ ORGANIZATION_URLS = [
         name="sentry-api-0-organization-user-details",
     ),
     re_path(
-        r"^(?P<organization_slug>[^\/]+)/sentry-app-installations/$",
+        r"^(?P<organization_id_or_slug>[^\/]+)/sentry-app-installations/$",
         SentryAppInstallationsEndpoint.as_view(),
         name="sentry-api-0-sentry-app-installations",
     ),

+ 1 - 1
tests/apidocs/endpoints/integration_platform/test_sentry_app_installations.py

@@ -24,7 +24,7 @@ class SentryAppInstallationDocsTest(APIDocsTestCase):
         self.login_as(user=self.user)
         self.url = reverse(
             "sentry-api-0-sentry-app-installations",
-            kwargs={"organization_slug": self.org.slug},
+            kwargs={"organization_id_or_slug": self.org.slug},
         )
 
     def test_get(self):