Browse Source

feat(api-idorslug): Rename Path paramaters to `team_id_or_slug` (#69618)

I renamed `team_slug` to `team_id_or_slug`.

I also had to change some tests since they used `team_slug`
Raj Joshi 10 months ago
parent
commit
1920bee171

+ 2 - 2
api-docs/openapi.json

@@ -87,10 +87,10 @@
     }
   ],
   "paths": {
-    "/api/0/teams/{organization_slug}/{team_slug}/": {
+    "/api/0/teams/{organization_slug}/{team_id_or_slug}/": {
       "$ref": "paths/teams/by-slug.json"
     },
-    "/api/0/teams/{organization_slug}/{team_slug}/stats/": {
+    "/api/0/teams/{organization_slug}/{team_id_or_slug}/stats/": {
       "$ref": "paths/teams/stats.json"
     },
     "/api/0/organizations/": {

+ 6 - 6
api-docs/paths/teams/by-slug.json

@@ -14,9 +14,9 @@
         }
       },
       {
-        "name": "team_slug",
+        "name": "team_id_or_slug",
         "in": "path",
-        "description": "The slug of the team to get.",
+        "description": "The id or slug of the team to get.",
         "required": true,
         "schema": {
           "type": "string"
@@ -92,9 +92,9 @@
         }
       },
       {
-        "name": "team_slug",
+        "name": "team_id_or_slug",
         "in": "path",
-        "description": "The slug of the team to get.",
+        "description": "The id or slug of the team to get.",
         "required": true,
         "schema": {
           "type": "string"
@@ -181,9 +181,9 @@
         }
       },
       {
-        "name": "team_slug",
+        "name": "team_id_or_slug",
         "in": "path",
-        "description": "The slug of the team to get.",
+        "description": "The id or slug of the team to get.",
         "required": true,
         "schema": {
           "type": "string"

+ 2 - 2
api-docs/paths/teams/stats.json

@@ -15,9 +15,9 @@
         }
       },
       {
-        "name": "team_slug",
+        "name": "team_id_or_slug",
         "in": "path",
-        "description": "The slug of the team to get.",
+        "description": "The id or slug of the team to get.",
         "required": true,
         "schema": {
           "type": "string"

+ 4 - 3
src/sentry/api/bases/team.py

@@ -36,19 +36,20 @@ class TeamPermission(OrganizationPermission):
 class TeamEndpoint(Endpoint):
     permission_classes: tuple[type[BasePermission], ...] = (TeamPermission,)
 
-    def convert_args(self, request: Request, organization_slug, team_slug, *args, **kwargs):
+    def convert_args(self, request: Request, organization_slug, team_id_or_slug, *args, **kwargs):
         try:
             if id_or_slug_path_params_enabled(self.convert_args.__qualname__):
                 team = (
                     Team.objects.filter(
-                        organization__slug__id_or_slug=organization_slug, slug__id_or_slug=team_slug
+                        organization__slug__id_or_slug=organization_slug,
+                        slug__id_or_slug=team_id_or_slug,
                     )
                     .select_related("organization")
                     .get()
                 )
             else:
                 team = (
-                    Team.objects.filter(organization__slug=organization_slug, slug=team_slug)
+                    Team.objects.filter(organization__slug=organization_slug, slug=team_id_or_slug)
                     .select_related("organization")
                     .get()
                 )

+ 5 - 3
src/sentry/api/endpoints/codeowners/external_actor/team_details.py

@@ -29,12 +29,14 @@ class ExternalTeamDetailsEndpoint(TeamEndpoint, ExternalActorEndpointMixin):
         self,
         request: Request,
         organization_slug: str,
-        team_slug: str,
+        team_id_or_slug: int | str,
         external_team_id: int,
         *args: Any,
         **kwargs: Any,
     ) -> tuple[Any, Any]:
-        args, kwargs = super().convert_args(request, organization_slug, team_slug, *args, **kwargs)
+        args, kwargs = super().convert_args(
+            request, organization_slug, team_id_or_slug, *args, **kwargs
+        )
         kwargs["external_team"] = self.get_external_actor_or_404(
             external_team_id, kwargs["team"].organization
         )
@@ -47,7 +49,7 @@ class ExternalTeamDetailsEndpoint(TeamEndpoint, ExternalActorEndpointMixin):
 
         :pparam string organization_slug: the slug of the organization the
                                           team belongs to.
-        :pparam string team_slug: the slug of the team to get.
+        :pparam string team_id_or_slug: the id or slug of the team to get.
         :pparam string external_team_id: id of external_team object
         :param string external_id: the associated user ID for this provider
         :param string external_name: the Github/Gitlab team name.

+ 1 - 1
src/sentry/api/endpoints/codeowners/external_actor/team_index.py

@@ -29,7 +29,7 @@ class ExternalTeamEndpoint(TeamEndpoint, ExternalActorEndpointMixin):
 
         :pparam string organization_slug: the slug of the organization the
                                           team belongs to.
-        :pparam string team_slug: the slug of the team to get.
+        :pparam string team_id_or_slug: the team_id_or_slug of the team to get.
         :param required string provider: enum("github", "gitlab")
         :param required string external_name: the associated Github/Gitlab team name.
         :param optional string integration_id: the id of the integration if it exists.

+ 8 - 7
src/sentry/api/endpoints/organization_member/team_details.py

@@ -106,7 +106,7 @@ class OrganizationMemberTeamDetailsEndpoint(OrganizationMemberEndpoint):
     ) -> tuple[tuple[Any, ...], dict[str, Any]]:
         args, kwargs = super().convert_args(request, organization_slug, *args, **kwargs)
 
-        team_slug = kwargs.pop("team_slug")
+        team_id_or_slug = kwargs.pop("team_id_or_slug")
         organization = kwargs["organization"]
         member = kwargs["member"]
 
@@ -116,11 +116,11 @@ class OrganizationMemberTeamDetailsEndpoint(OrganizationMemberEndpoint):
                     self.get.__qualname__, organization_slug=organization.slug
                 ):
                     omt = OrganizationMemberTeam.objects.get(
-                        team__slug__id_or_slug=team_slug, organizationmember=member
+                        team__slug__id_or_slug=team_id_or_slug, organizationmember=member
                     )
                 else:
                     omt = OrganizationMemberTeam.objects.get(
-                        team__slug=team_slug, organizationmember=member
+                        team__slug=team_id_or_slug, organizationmember=member
                     )
             except OrganizationMemberTeam.DoesNotExist:
                 raise ResourceDoesNotExist
@@ -133,10 +133,11 @@ class OrganizationMemberTeamDetailsEndpoint(OrganizationMemberEndpoint):
                     self.post.__qualname__, organization_slug=organization.slug
                 ):
                     team = Team.objects.get(
-                        organization__slug__id_or_slug=organization.slug, slug__id_or_slug=team_slug
+                        organization__slug__id_or_slug=organization.slug,
+                        slug__id_or_slug=team_id_or_slug,
                     )
                 else:
-                    team = Team.objects.get(organization=organization, slug=team_slug)
+                    team = Team.objects.get(organization=organization, slug=team_id_or_slug)
             except Team.DoesNotExist:
                 raise ResourceDoesNotExist
             kwargs["team"] = team
@@ -230,7 +231,7 @@ class OrganizationMemberTeamDetailsEndpoint(OrganizationMemberEndpoint):
         parameters=[
             GlobalParams.ORG_SLUG,
             GlobalParams.member_id("The ID of the organization member to add to the team"),
-            GlobalParams.TEAM_SLUG,
+            GlobalParams.TEAM_ID_OR_SLUG,
         ],
         request=None,
         responses={
@@ -420,7 +421,7 @@ class OrganizationMemberTeamDetailsEndpoint(OrganizationMemberEndpoint):
         parameters=[
             GlobalParams.ORG_SLUG,
             GlobalParams.member_id("The ID of the organization member to delete from the team"),
-            GlobalParams.TEAM_SLUG,
+            GlobalParams.TEAM_ID_OR_SLUG,
         ],
         responses={
             200: BaseTeamSerializer,

+ 7 - 5
src/sentry/api/endpoints/project_team_details.py

@@ -41,7 +41,7 @@ class ProjectTeamDetailsEndpoint(ProjectEndpoint):
         request: Request,
         organization_slug: str | int,
         project_slug: str | int,
-        team_slug: str | int,
+        team_id_or_slug: int | str,
         *args,
         **kwargs,
     ):
@@ -57,10 +57,12 @@ class ProjectTeamDetailsEndpoint(ProjectEndpoint):
             ):
                 team = Team.objects.get(
                     organization__slug__id_or_slug=project.organization.slug,
-                    slug__id_or_slug=team_slug,
+                    slug__id_or_slug=team_id_or_slug,
                 )
             else:
-                team = Team.objects.get(organization_id=project.organization_id, slug=team_slug)
+                team = Team.objects.get(
+                    organization_id=project.organization_id, slug=team_id_or_slug
+                )
         except Team.DoesNotExist:
             raise ResourceDoesNotExist(detail="Team does not exist.")
 
@@ -72,7 +74,7 @@ class ProjectTeamDetailsEndpoint(ProjectEndpoint):
         parameters=[
             GlobalParams.ORG_SLUG,
             GlobalParams.PROJECT_SLUG,
-            GlobalParams.TEAM_SLUG,
+            GlobalParams.TEAM_ID_OR_SLUG,
         ],
         request=None,
         responses={
@@ -103,7 +105,7 @@ class ProjectTeamDetailsEndpoint(ProjectEndpoint):
         parameters=[
             GlobalParams.ORG_SLUG,
             GlobalParams.PROJECT_SLUG,
-            GlobalParams.TEAM_SLUG,
+            GlobalParams.TEAM_ID_OR_SLUG,
         ],
         responses={
             200: ProjectWithTeamSerializer,

+ 2 - 2
src/sentry/api/endpoints/team_details.py

@@ -53,7 +53,7 @@ class TeamDetailsEndpoint(TeamEndpoint):
 
         :pparam string organization_slug: the slug of the organization the
                                           team belongs to.
-        :pparam string team_slug: the slug of the team to get.
+        :pparam string team_id_or_slug: the id or slug of the team to get.
         :qparam list expand: an optional list of strings to opt in to additional
             data. Supports `projects`, `externalTeams`.
         :qparam list collapse: an optional list of strings to opt out of certain
@@ -83,7 +83,7 @@ class TeamDetailsEndpoint(TeamEndpoint):
 
         :pparam string organization_slug: the slug of the organization the
                                           team belongs to.
-        :pparam string team_slug: the slug of the team to get.
+        :pparam string team_id_or_slug: the id or slug of the team to get.
         :param string name: the new name for the team.
         :param string slug: a new slug for the team.  It has to be unique
                             and available.

+ 2 - 2
src/sentry/api/endpoints/team_projects.py

@@ -88,7 +88,7 @@ class TeamProjectsEndpoint(TeamEndpoint, EnvironmentMixin):
         operation_id="List a Team's Projects",
         parameters=[
             GlobalParams.ORG_SLUG,
-            GlobalParams.TEAM_SLUG,
+            GlobalParams.TEAM_ID_OR_SLUG,
             CursorQueryParam,
         ],
         request=None,
@@ -143,7 +143,7 @@ class TeamProjectsEndpoint(TeamEndpoint, EnvironmentMixin):
         operation_id="Create a New Project",
         parameters=[
             GlobalParams.ORG_SLUG,
-            GlobalParams.TEAM_SLUG,
+            GlobalParams.TEAM_ID_OR_SLUG,
         ],
         request=ProjectPostSerializer,
         responses={

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