Browse Source

feat(api-idorslug): Updated Subset of Endpoints to use `organization_id_or_slug` (#70636)

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

+ 13 - 3
src/sentry/api/endpoints/broadcast_index.py

@@ -50,9 +50,19 @@ class BroadcastIndexEndpoint(ControlSiloOrganizationEndpoint):
         # used in the SAAS product
         return list(queryset)
 
-    def convert_args(self, request: Request, organization_slug=None, *args, **kwargs):
-        if organization_slug:
-            args, kwargs = super().convert_args(request, organization_slug)
+    def convert_args(self, request: Request, *args, **kwargs):
+        organization_id_or_slug: int | str | None = None
+        if args and args[0] is not None:
+            organization_id_or_slug = args[0]
+            # Required so it behaves like the original convert_args, where organization_id_or_slug was another parameter
+            # TODO: Remove this once we remove the old `organization_slug` parameter from getsentry
+            args = args[1:]
+        else:
+            organization_id_or_slug = kwargs.pop("organization_id_or_slug", None) or kwargs.pop(
+                "organization_slug", None
+            )
+        if organization_id_or_slug:
+            args, kwargs = super().convert_args(request, organization_id_or_slug)
 
         return (args, kwargs)
 

+ 2 - 2
src/sentry/api/endpoints/codeowners/external_actor/user_details.py

@@ -30,12 +30,12 @@ class ExternalUserDetailsEndpoint(OrganizationEndpoint, ExternalActorEndpointMix
     def convert_args(
         self,
         request: Request,
-        organization_slug: str,
+        organization_id_or_slug: int | str,
         external_user_id: int,
         *args: Any,
         **kwargs: Any,
     ) -> tuple[tuple[Any, ...], dict[str, Any]]:
-        args, kwargs = super().convert_args(request, organization_slug, *args, **kwargs)
+        args, kwargs = super().convert_args(request, organization_id_or_slug, *args, **kwargs)
         kwargs["external_user"] = self.get_external_actor_or_404(
             external_user_id, kwargs["organization"]
         )

+ 1 - 1
src/sentry/api/endpoints/group_details.py

@@ -136,7 +136,7 @@ class GroupDetailsEndpoint(GroupEndpoint, EnvironmentMixin):
         the issue (title, last seen, first seen), some overall numbers (number
         of comments, user reports) as well as the summarized event data.
 
-        :pparam string organization_id_or_slug: The slug of the organization.
+        :pparam string organization_id_or_slug: the id or slug of the organization.
         :pparam string issue_id: the ID of the issue to retrieve.
         :auth: required
         """

+ 1 - 1
src/sentry/api/endpoints/integrations/organization_integrations/index.py

@@ -64,7 +64,7 @@ class OrganizationIntegrationsEndpoint(OrganizationIntegrationBaseEndpoint):
     @extend_schema(
         operation_id="List an Organization's Available Integrations",
         parameters=[
-            GlobalParams.ORG_SLUG,
+            GlobalParams.ORG_ID_OR_SLUG,
             IntegrationParams.PROVIDER_KEY,
             IntegrationParams.FEATURES,
             IntegrationParams.INCLUDE_CONFIG,

+ 3 - 3
src/sentry/api/endpoints/notifications/notification_actions_details.py

@@ -87,7 +87,7 @@ class NotificationActionsDetailsEndpoint(OrganizationEndpoint):
     @extend_schema(
         operation_id="Retrieve a Spike Protection Notification Action",
         parameters=[
-            GlobalParams.ORG_SLUG,
+            GlobalParams.ORG_ID_OR_SLUG,
             NotificationParams.ACTION_ID,
         ],
         responses={200: OutgoingNotificationActionSerializer},
@@ -111,7 +111,7 @@ class NotificationActionsDetailsEndpoint(OrganizationEndpoint):
     @extend_schema(
         operation_id="Update a Spike Protection Notification Action",
         parameters=[
-            GlobalParams.ORG_SLUG,
+            GlobalParams.ORG_ID_OR_SLUG,
             NotificationParams.ACTION_ID,
         ],
         request=NotificationActionSerializer,
@@ -159,7 +159,7 @@ class NotificationActionsDetailsEndpoint(OrganizationEndpoint):
     @extend_schema(
         operation_id="Delete a Spike Protection Notification Action",
         parameters=[
-            GlobalParams.ORG_SLUG,
+            GlobalParams.ORG_ID_OR_SLUG,
             NotificationParams.ACTION_ID,
         ],
         responses={

+ 2 - 2
src/sentry/api/endpoints/notifications/notification_actions_index.py

@@ -66,7 +66,7 @@ class NotificationActionsIndexEndpoint(OrganizationEndpoint):
     @extend_schema(
         operation_id="List Spike Protection Notifications",
         parameters=[
-            GlobalParams.ORG_SLUG,
+            GlobalParams.ORG_ID_OR_SLUG,
             OrganizationParams.PROJECT,
             OrganizationParams.PROJECT_ID_OR_SLUG,
             NotificationParams.TRIGGER_TYPE,
@@ -119,7 +119,7 @@ class NotificationActionsIndexEndpoint(OrganizationEndpoint):
     @extend_schema(
         operation_id="Create a Spike Protection Notification Action",
         parameters=[
-            GlobalParams.ORG_SLUG,
+            GlobalParams.ORG_ID_OR_SLUG,
         ],
         request=NotificationActionSerializer,
         responses={

+ 4 - 2
src/sentry/api/endpoints/organization_code_mapping_codeowners.py

@@ -30,8 +30,10 @@ class OrganizationCodeMappingCodeOwnersEndpoint(OrganizationEndpoint):
     }
     permission_classes = (OrganizationIntegrationsPermission,)
 
-    def convert_args(self, request: Request, organization_slug, config_id, *args, **kwargs):
-        args, kwargs = super().convert_args(request, organization_slug, config_id, *args, **kwargs)
+    def convert_args(self, request: Request, organization_id_or_slug, config_id, *args, **kwargs):
+        args, kwargs = super().convert_args(
+            request, organization_id_or_slug, config_id, *args, **kwargs
+        )
         organization = kwargs["organization"]
 
         try:

+ 4 - 2
src/sentry/api/endpoints/organization_code_mapping_details.py

@@ -30,8 +30,10 @@ class OrganizationCodeMappingDetailsEndpoint(OrganizationEndpoint, OrganizationI
     }
     permission_classes = (OrganizationIntegrationsLoosePermission,)
 
-    def convert_args(self, request: Request, organization_slug, config_id, *args, **kwargs):
-        args, kwargs = super().convert_args(request, organization_slug, config_id, *args, **kwargs)
+    def convert_args(self, request: Request, organization_id_or_slug, config_id, *args, **kwargs):
+        args, kwargs = super().convert_args(
+            request, organization_id_or_slug, config_id, *args, **kwargs
+        )
         ois = integration_service.get_organization_integrations(
             organization_id=kwargs["organization"].id
         )

+ 4 - 2
src/sentry/api/endpoints/organization_dashboard_details.py

@@ -24,8 +24,10 @@ class OrganizationDashboardBase(OrganizationEndpoint):
     owner = ApiOwner.PERFORMANCE
     permission_classes = (OrganizationDashboardsPermission,)
 
-    def convert_args(self, request: Request, organization_slug, dashboard_id, *args, **kwargs):
-        args, kwargs = super().convert_args(request, organization_slug, *args, **kwargs)
+    def convert_args(
+        self, request: Request, organization_id_or_slug, dashboard_id, *args, **kwargs
+    ):
+        args, kwargs = super().convert_args(request, organization_id_or_slug, *args, **kwargs)
 
         try:
             kwargs["dashboard"] = self._get_dashboard(request, kwargs["organization"], dashboard_id)

+ 9 - 4
src/sentry/api/endpoints/organization_events.py

@@ -116,7 +116,7 @@ DEFAULT_INCREASED_RATE_LIMIT = dict(limit=50, window=1, concurrent_limit=50)
 
 
 def rate_limit_events(
-    request: Request, organization_slug: str | None = None, *args, **kwargs
+    request: Request, organization_id_or_slug: str | None = None, *args, **kwargs
 ) -> dict[str, dict[RateLimitCategory, RateLimit]]:
     """
     Decision tree for rate limiting for organization events endpoint.
@@ -156,9 +156,14 @@ def rate_limit_events(
     rate_limit = RateLimit(**LEGACY_RATE_LIMIT)
 
     try:
-        organization = Organization.objects.get_from_cache(slug=organization_slug)
+        if str(organization_id_or_slug).isdecimal():
+            organization = Organization.objects.get_from_cache(id=organization_id_or_slug)
+        else:
+            organization = Organization.objects.get_from_cache(slug=organization_id_or_slug)
     except Organization.DoesNotExist:
-        logger.warning("organization.slug.invalid", extra={"organization_slug": organization_slug})
+        logger.warning(
+            "organization.slug.invalid", extra={"organization_id_or_slug": organization_id_or_slug}
+        )
         return _config_for_limit(rate_limit)
 
     if organization.id in options.get("api.organization_events.rate-limit-increased.orgs", []):
@@ -230,7 +235,7 @@ class OrganizationEventsEndpoint(OrganizationEventsV2EndpointBase):
         parameters=[
             GlobalParams.END,
             GlobalParams.ENVIRONMENT,
-            GlobalParams.ORG_SLUG,
+            GlobalParams.ORG_ID_OR_SLUG,
             OrganizationParams.PROJECT,
             GlobalParams.START,
             GlobalParams.STATS_PERIOD,

Some files were not shown because too many files changed in this diff