Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/sentry/integrations/api/bases/organization_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
RpcOrganizationIntegration,
integration_service,
)
from sentry.workflow_engine.endpoints.utils.ids import to_valid_int_id


class OrganizationIntegrationBaseEndpoint(IntegrationEndpoint):
Expand All @@ -25,6 +26,22 @@ class OrganizationIntegrationBaseEndpoint(IntegrationEndpoint):

permission_classes = (OrganizationIntegrationsPermission,)

def convert_args(
self,
request: Request,
organization_id_or_slug: int | str | None = None,
integration_id: str | None = None,
*args: Any,
**kwargs: Any,
) -> tuple[tuple[Any, ...], dict[str, Any]]:
args, kwargs = super().convert_args(request, organization_id_or_slug, *args, **kwargs)

if integration_id is not None:
kwargs["integration_id"] = to_valid_int_id(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is int here integration or integer? might be nice to either spell out integration or remove int (since all our ids minus a few places are integers)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integer. This is a fancy replacement for the ad hoc int(whatever) calls we have/had sprinkled around.
There are 20+ uses, so probably not renaming in this PR, but it needs to move somewhere more general soon (this sprint would make sense) so we'll address that then.

"integration_id", integration_id, raise_404=True
)
return args, kwargs

@staticmethod
def get_organization_integration(
organization_id: int, integration_id: int
Expand Down Expand Up @@ -82,16 +99,12 @@ def convert_args(
) -> tuple[tuple[Any, ...], dict[str, Any]]:
args, kwargs = super().convert_args(request, organization_id_or_slug, *args, **kwargs)

kwargs["integration_id"] = self.validate_integration_id(integration_id or "")
if integration_id is not None:
kwargs["integration_id"] = to_valid_int_id(
"integration_id", integration_id, raise_404=True
)
return args, kwargs

@staticmethod
def validate_integration_id(integration_id: str) -> int:
try:
return int(integration_id)
except ValueError:
raise Http404

@staticmethod
def get_organization_integration(
organization_id: int, integration_id: int
Expand Down
Loading