Skip to content

Commit 3aade54

Browse files
authored
feat(api-idorslug): Updated Subset of Endpoints to use organization_id_or_slug (#70636)
A subset of changes from #70081!
1 parent 59524f9 commit 3aade54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+142
-113
lines changed

src/sentry/api/endpoints/broadcast_index.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,19 @@ def _secondary_filtering(self, request: Request, organization_slug, queryset):
5050
# used in the SAAS product
5151
return list(queryset)
5252

53-
def convert_args(self, request: Request, organization_slug=None, *args, **kwargs):
54-
if organization_slug:
55-
args, kwargs = super().convert_args(request, organization_slug)
53+
def convert_args(self, request: Request, *args, **kwargs):
54+
organization_id_or_slug: int | str | None = None
55+
if args and args[0] is not None:
56+
organization_id_or_slug = args[0]
57+
# Required so it behaves like the original convert_args, where organization_id_or_slug was another parameter
58+
# TODO: Remove this once we remove the old `organization_slug` parameter from getsentry
59+
args = args[1:]
60+
else:
61+
organization_id_or_slug = kwargs.pop("organization_id_or_slug", None) or kwargs.pop(
62+
"organization_slug", None
63+
)
64+
if organization_id_or_slug:
65+
args, kwargs = super().convert_args(request, organization_id_or_slug)
5666

5767
return (args, kwargs)
5868

src/sentry/api/endpoints/codeowners/external_actor/user_details.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class ExternalUserDetailsEndpoint(OrganizationEndpoint, ExternalActorEndpointMix
3030
def convert_args(
3131
self,
3232
request: Request,
33-
organization_slug: str,
33+
organization_id_or_slug: int | str,
3434
external_user_id: int,
3535
*args: Any,
3636
**kwargs: Any,
3737
) -> tuple[tuple[Any, ...], dict[str, Any]]:
38-
args, kwargs = super().convert_args(request, organization_slug, *args, **kwargs)
38+
args, kwargs = super().convert_args(request, organization_id_or_slug, *args, **kwargs)
3939
kwargs["external_user"] = self.get_external_actor_or_404(
4040
external_user_id, kwargs["organization"]
4141
)

src/sentry/api/endpoints/group_details.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get(self, request: Request, group) -> Response:
136136
the issue (title, last seen, first seen), some overall numbers (number
137137
of comments, user reports) as well as the summarized event data.
138138
139-
:pparam string organization_id_or_slug: The slug of the organization.
139+
:pparam string organization_id_or_slug: the id or slug of the organization.
140140
:pparam string issue_id: the ID of the issue to retrieve.
141141
:auth: required
142142
"""

src/sentry/api/endpoints/integrations/organization_integrations/index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class OrganizationIntegrationsEndpoint(OrganizationIntegrationBaseEndpoint):
6464
@extend_schema(
6565
operation_id="List an Organization's Available Integrations",
6666
parameters=[
67-
GlobalParams.ORG_SLUG,
67+
GlobalParams.ORG_ID_OR_SLUG,
6868
IntegrationParams.PROVIDER_KEY,
6969
IntegrationParams.FEATURES,
7070
IntegrationParams.INCLUDE_CONFIG,

src/sentry/api/endpoints/notifications/notification_actions_details.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def convert_args(self, request: Request, action_id: int, *args, **kwargs):
8787
@extend_schema(
8888
operation_id="Retrieve a Spike Protection Notification Action",
8989
parameters=[
90-
GlobalParams.ORG_SLUG,
90+
GlobalParams.ORG_ID_OR_SLUG,
9191
NotificationParams.ACTION_ID,
9292
],
9393
responses={200: OutgoingNotificationActionSerializer},
@@ -111,7 +111,7 @@ def get(
111111
@extend_schema(
112112
operation_id="Update a Spike Protection Notification Action",
113113
parameters=[
114-
GlobalParams.ORG_SLUG,
114+
GlobalParams.ORG_ID_OR_SLUG,
115115
NotificationParams.ACTION_ID,
116116
],
117117
request=NotificationActionSerializer,
@@ -159,7 +159,7 @@ def put(
159159
@extend_schema(
160160
operation_id="Delete a Spike Protection Notification Action",
161161
parameters=[
162-
GlobalParams.ORG_SLUG,
162+
GlobalParams.ORG_ID_OR_SLUG,
163163
NotificationParams.ACTION_ID,
164164
],
165165
responses={

src/sentry/api/endpoints/notifications/notification_actions_index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class NotificationActionsIndexEndpoint(OrganizationEndpoint):
6666
@extend_schema(
6767
operation_id="List Spike Protection Notifications",
6868
parameters=[
69-
GlobalParams.ORG_SLUG,
69+
GlobalParams.ORG_ID_OR_SLUG,
7070
OrganizationParams.PROJECT,
7171
OrganizationParams.PROJECT_ID_OR_SLUG,
7272
NotificationParams.TRIGGER_TYPE,
@@ -119,7 +119,7 @@ def get(self, request: Request, organization: Organization) -> Response:
119119
@extend_schema(
120120
operation_id="Create a Spike Protection Notification Action",
121121
parameters=[
122-
GlobalParams.ORG_SLUG,
122+
GlobalParams.ORG_ID_OR_SLUG,
123123
],
124124
request=NotificationActionSerializer,
125125
responses={

src/sentry/api/endpoints/organization_code_mapping_codeowners.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class OrganizationCodeMappingCodeOwnersEndpoint(OrganizationEndpoint):
3030
}
3131
permission_classes = (OrganizationIntegrationsPermission,)
3232

33-
def convert_args(self, request: Request, organization_slug, config_id, *args, **kwargs):
34-
args, kwargs = super().convert_args(request, organization_slug, config_id, *args, **kwargs)
33+
def convert_args(self, request: Request, organization_id_or_slug, config_id, *args, **kwargs):
34+
args, kwargs = super().convert_args(
35+
request, organization_id_or_slug, config_id, *args, **kwargs
36+
)
3537
organization = kwargs["organization"]
3638

3739
try:

src/sentry/api/endpoints/organization_code_mapping_details.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class OrganizationCodeMappingDetailsEndpoint(OrganizationEndpoint, OrganizationI
3030
}
3131
permission_classes = (OrganizationIntegrationsLoosePermission,)
3232

33-
def convert_args(self, request: Request, organization_slug, config_id, *args, **kwargs):
34-
args, kwargs = super().convert_args(request, organization_slug, config_id, *args, **kwargs)
33+
def convert_args(self, request: Request, organization_id_or_slug, config_id, *args, **kwargs):
34+
args, kwargs = super().convert_args(
35+
request, organization_id_or_slug, config_id, *args, **kwargs
36+
)
3537
ois = integration_service.get_organization_integrations(
3638
organization_id=kwargs["organization"].id
3739
)

src/sentry/api/endpoints/organization_dashboard_details.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ class OrganizationDashboardBase(OrganizationEndpoint):
2424
owner = ApiOwner.PERFORMANCE
2525
permission_classes = (OrganizationDashboardsPermission,)
2626

27-
def convert_args(self, request: Request, organization_slug, dashboard_id, *args, **kwargs):
28-
args, kwargs = super().convert_args(request, organization_slug, *args, **kwargs)
27+
def convert_args(
28+
self, request: Request, organization_id_or_slug, dashboard_id, *args, **kwargs
29+
):
30+
args, kwargs = super().convert_args(request, organization_id_or_slug, *args, **kwargs)
2931

3032
try:
3133
kwargs["dashboard"] = self._get_dashboard(request, kwargs["organization"], dashboard_id)

src/sentry/api/endpoints/organization_events.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

117117

118118
def rate_limit_events(
119-
request: Request, organization_slug: str | None = None, *args, **kwargs
119+
request: Request, organization_id_or_slug: str | None = None, *args, **kwargs
120120
) -> dict[str, dict[RateLimitCategory, RateLimit]]:
121121
"""
122122
Decision tree for rate limiting for organization events endpoint.
@@ -156,9 +156,14 @@ def _validated_limits(limits: dict[str, Any], fallback: dict[str, Any]) -> RateL
156156
rate_limit = RateLimit(**LEGACY_RATE_LIMIT)
157157

158158
try:
159-
organization = Organization.objects.get_from_cache(slug=organization_slug)
159+
if str(organization_id_or_slug).isdecimal():
160+
organization = Organization.objects.get_from_cache(id=organization_id_or_slug)
161+
else:
162+
organization = Organization.objects.get_from_cache(slug=organization_id_or_slug)
160163
except Organization.DoesNotExist:
161-
logger.warning("organization.slug.invalid", extra={"organization_slug": organization_slug})
164+
logger.warning(
165+
"organization.slug.invalid", extra={"organization_id_or_slug": organization_id_or_slug}
166+
)
162167
return _config_for_limit(rate_limit)
163168

164169
if organization.id in options.get("api.organization_events.rate-limit-increased.orgs", []):
@@ -230,7 +235,7 @@ def get_features(self, organization: Organization, request: Request) -> Mapping[
230235
parameters=[
231236
GlobalParams.END,
232237
GlobalParams.ENVIRONMENT,
233-
GlobalParams.ORG_SLUG,
238+
GlobalParams.ORG_ID_OR_SLUG,
234239
OrganizationParams.PROJECT,
235240
GlobalParams.START,
236241
GlobalParams.STATS_PERIOD,

src/sentry/api/endpoints/organization_member/index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class OrganizationMemberIndexEndpoint(OrganizationEndpoint):
189189
@extend_schema(
190190
operation_id="List an Organization's Members",
191191
parameters=[
192-
GlobalParams.ORG_SLUG,
192+
GlobalParams.ORG_ID_OR_SLUG,
193193
],
194194
responses={
195195
200: inline_sentry_response_serializer(
@@ -299,7 +299,7 @@ def get(self, request: Request, organization) -> Response:
299299
@extend_schema(
300300
operation_id="Add a Member to an Organization",
301301
parameters=[
302-
GlobalParams.ORG_SLUG,
302+
GlobalParams.ORG_ID_OR_SLUG,
303303
],
304304
request=OrganizationMemberRequestSerializer,
305305
responses={

src/sentry/api/endpoints/organization_projects.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class OrganizationProjectsEndpoint(OrganizationEndpoint, EnvironmentMixin):
5151

5252
@extend_schema(
5353
operation_id="List an Organization's Projects",
54-
parameters=[GlobalParams.ORG_SLUG, CursorQueryParam],
54+
parameters=[GlobalParams.ORG_ID_OR_SLUG, CursorQueryParam],
5555
request=None,
5656
responses={
5757
200: inline_sentry_response_serializer(

src/sentry/api/endpoints/organization_relay_usage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class OrganizationRelayUsage(OrganizationEndpoint):
2727

2828
@extend_schema(
2929
operation_id="List an Organization's trusted Relays",
30-
parameters=[GlobalParams.ORG_SLUG],
30+
parameters=[GlobalParams.ORG_ID_OR_SLUG],
3131
request=None,
3232
responses={
3333
200: inline_sentry_response_serializer(

src/sentry/api/endpoints/organization_search_details.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class OrganizationSearchDetailsEndpoint(OrganizationEndpoint):
4343
}
4444
permission_classes = (OrganizationSearchEditPermission,)
4545

46-
def convert_args(self, request: Request, organization_slug, search_id, *args, **kwargs):
47-
(args, kwargs) = super().convert_args(request, organization_slug, *args, **kwargs)
46+
def convert_args(self, request: Request, organization_id_or_slug, search_id, *args, **kwargs):
47+
(args, kwargs) = super().convert_args(request, organization_id_or_slug, *args, **kwargs)
4848

4949
# Only allow users to delete their own personal searches OR
5050
# organization level searches

src/sentry/api/endpoints/organization_sessions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class OrganizationSessionsEndpoint(OrganizationEndpoint):
4545
GlobalParams.START,
4646
GlobalParams.END,
4747
GlobalParams.ENVIRONMENT,
48-
GlobalParams.ORG_SLUG,
48+
GlobalParams.ORG_ID_OR_SLUG,
4949
GlobalParams.STATS_PERIOD,
5050
OrganizationParams.PROJECT,
5151
SessionsParams.FIELD,

src/sentry/api/endpoints/organization_stats_summary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class OrganizationStatsSummaryEndpoint(OrganizationEndpoint):
125125

126126
@extend_schema(
127127
operation_id="Retrieve an Organization's Events Count by Project",
128-
parameters=[GlobalParams.ORG_SLUG, OrgStatsSummaryQueryParamsSerializer],
128+
parameters=[GlobalParams.ORG_ID_OR_SLUG, OrgStatsSummaryQueryParamsSerializer],
129129
request=None,
130130
responses={
131131
200: inline_sentry_response_serializer(

src/sentry/api/endpoints/organization_stats_v2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class OrganizationStatsEndpointV2(OrganizationEndpoint):
151151

152152
@extend_schema(
153153
operation_id="Retrieve Event Counts for an Organization (v2)",
154-
parameters=[GlobalParams.ORG_SLUG, OrgStatsQueryParamsSerializer],
154+
parameters=[GlobalParams.ORG_ID_OR_SLUG, OrgStatsQueryParamsSerializer],
155155
request=None,
156156
responses={
157157
200: inline_sentry_response_serializer("OutcomesResponse", StatsApiResponse),

src/sentry/api/endpoints/organization_teams.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def team_serializer_for_post(self):
8080
@extend_schema(
8181
operation_id="List an Organization's Teams",
8282
parameters=[
83-
GlobalParams.ORG_SLUG,
83+
GlobalParams.ORG_ID_OR_SLUG,
8484
TeamParams.DETAILED,
8585
CursorQueryParam,
8686
],
@@ -161,7 +161,7 @@ def should_add_creator_to_team(self, request: Request):
161161
@extend_schema(
162162
operation_id="Create a New Team",
163163
parameters=[
164-
GlobalParams.ORG_SLUG,
164+
GlobalParams.ORG_ID_OR_SLUG,
165165
],
166166
request=TeamPostSerializer,
167167
responses={

src/sentry/api/endpoints/project_details.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def _get_unresolved_count(self, project):
456456

457457
@extend_schema(
458458
operation_id="Retrieve a Project",
459-
parameters=[GlobalParams.ORG_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
459+
parameters=[GlobalParams.ORG_ID_OR_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
460460
request=None,
461461
responses={
462462
200: DetailedProjectSerializer,
@@ -500,7 +500,7 @@ def get(self, request: Request, project: Project) -> Response:
500500
@extend_schema(
501501
operation_id="Update a Project",
502502
parameters=[
503-
GlobalParams.ORG_SLUG,
503+
GlobalParams.ORG_ID_OR_SLUG,
504504
GlobalParams.PROJECT_ID_OR_SLUG,
505505
],
506506
request=ProjectAdminSerializer,
@@ -891,7 +891,7 @@ def put(self, request: Request, project) -> Response:
891891

892892
@extend_schema(
893893
operation_id="Delete a Project",
894-
parameters=[GlobalParams.ORG_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
894+
parameters=[GlobalParams.ORG_ID_OR_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
895895
responses={
896896
204: RESPONSE_NO_CONTENT,
897897
403: RESPONSE_FORBIDDEN,

src/sentry/api/endpoints/project_filter_details.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ProjectFilterDetailsEndpoint(ProjectEndpoint):
3030
@extend_schema(
3131
operation_id="Update an Inbound Data Filter",
3232
parameters=[
33-
GlobalParams.ORG_SLUG,
33+
GlobalParams.ORG_ID_OR_SLUG,
3434
GlobalParams.PROJECT_ID_OR_SLUG,
3535
ProjectParams.FILTER_ID,
3636
],

src/sentry/api/endpoints/project_keys.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ProjectKeysEndpoint(ProjectEndpoint):
3333
@extend_schema(
3434
operation_id="List a Project's Client Keys",
3535
parameters=[
36-
GlobalParams.ORG_SLUG,
36+
GlobalParams.ORG_ID_OR_SLUG,
3737
GlobalParams.PROJECT_ID_OR_SLUG,
3838
CursorQueryParam,
3939
ProjectParams.STATUS,
@@ -72,7 +72,7 @@ def get(self, request: Request, project) -> Response:
7272
@extend_schema(
7373
operation_id="Create a New Client Key",
7474
parameters=[
75-
GlobalParams.ORG_SLUG,
75+
GlobalParams.ORG_ID_OR_SLUG,
7676
GlobalParams.PROJECT_ID_OR_SLUG,
7777
],
7878
request=ProjectKeyPostSerializer,

src/sentry/api/endpoints/project_ownership.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def rename_schema_identifier_for_parsing(self, ownership: ProjectOwnership) -> N
219219
@extend_schema(
220220
operation_id="Retrieve Ownership Configuration for a Project",
221221
parameters=[
222-
GlobalParams.ORG_SLUG,
222+
GlobalParams.ORG_ID_OR_SLUG,
223223
GlobalParams.PROJECT_ID_OR_SLUG,
224224
],
225225
request=None,
@@ -241,7 +241,7 @@ def get(self, request: Request, project) -> Response:
241241
@extend_schema(
242242
operation_id="Update Ownership Configuration for a Project",
243243
parameters=[
244-
GlobalParams.ORG_SLUG,
244+
GlobalParams.ORG_ID_OR_SLUG,
245245
GlobalParams.PROJECT_ID_OR_SLUG,
246246
],
247247
request=ProjectOwnershipRequestSerializer,

src/sentry/api/endpoints/project_rule_details.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ProjectRuleDetailsEndpoint(RuleEndpoint):
108108
@extend_schema(
109109
operation_id="Retrieve an Issue Alert Rule for a Project",
110110
parameters=[
111-
GlobalParams.ORG_SLUG,
111+
GlobalParams.ORG_ID_OR_SLUG,
112112
GlobalParams.PROJECT_ID_OR_SLUG,
113113
IssueAlertParams.ISSUE_RULE_ID,
114114
],
@@ -208,7 +208,7 @@ def get(self, request: Request, project, rule) -> Response:
208208
@extend_schema(
209209
operation_id="Update an Issue Alert Rule",
210210
parameters=[
211-
GlobalParams.ORG_SLUG,
211+
GlobalParams.ORG_ID_OR_SLUG,
212212
GlobalParams.PROJECT_ID_OR_SLUG,
213213
IssueAlertParams.ISSUE_RULE_ID,
214214
],
@@ -398,7 +398,7 @@ def put(self, request: Request, project, rule) -> Response:
398398
@extend_schema(
399399
operation_id="Delete an Issue Alert Rule",
400400
parameters=[
401-
GlobalParams.ORG_SLUG,
401+
GlobalParams.ORG_ID_OR_SLUG,
402402
GlobalParams.PROJECT_ID_OR_SLUG,
403403
IssueAlertParams.ISSUE_RULE_ID,
404404
],

src/sentry/api/endpoints/project_rules.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ class ProjectRulesEndpoint(ProjectEndpoint):
681681

682682
@extend_schema(
683683
operation_id="List a Project's Issue Alert Rules",
684-
parameters=[GlobalParams.ORG_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
684+
parameters=[GlobalParams.ORG_ID_OR_SLUG, GlobalParams.PROJECT_ID_OR_SLUG],
685685
request=None,
686686
responses={
687687
200: inline_sentry_response_serializer("ListRules", list[RuleSerializerResponse]),
@@ -715,7 +715,7 @@ def get(self, request: Request, project) -> Response:
715715
@extend_schema(
716716
operation_id="Create an Issue Alert Rule for a Project",
717717
parameters=[
718-
GlobalParams.ORG_SLUG,
718+
GlobalParams.ORG_ID_OR_SLUG,
719719
GlobalParams.PROJECT_ID_OR_SLUG,
720720
],
721721
request=ProjectRulesPostSerializer,

0 commit comments

Comments
 (0)