-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api-idorslug): Rename Path paramaters to organization_id_or_slug
#70081
Changes from 17 commits
f5ea30f
230208d
57cc4ba
1a32ac1
cc0dda3
e93be66
1acb6d9
c645f51
497d58a
7b01160
66eca20
a39344d
b3f9626
0b299fb
7793107
12ff01b
b92e84b
049c7e0
1069c76
9a3fd90
158fd40
09ece06
f7c0391
d4e4786
6447350
6dbff1a
fd524ce
621246e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,30 +242,42 @@ class ControlSiloOrganizationEndpoint(Endpoint): | |
def convert_args( | ||
self, | ||
request: Request, | ||
organization_slug: str | int | None = None, | ||
*args: Any, | ||
**kwargs: Any, | ||
) -> tuple[tuple[Any, ...], dict[str, Any]]: | ||
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 not subdomain_is_region(request): | ||
subdomain = getattr(request, "subdomain", None) | ||
if subdomain is not None and subdomain != organization_slug: | ||
if subdomain is not None and subdomain != organization_id_or_slug: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subdomain is never ID. Does this mean it would fail anytime we use the API with ID? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is related to my question here: https://sentry.slack.com/archives/C032E82D338/p1714605291155389, the git blame is related to customer domain stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tldr from the thread: this would fail if we get a request like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
raise ResourceDoesNotExist | ||
|
||
if not organization_slug: | ||
if not organization_id_or_slug: | ||
raise ResourceDoesNotExist | ||
|
||
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() | ||
): | ||
# It is ok that `get_organization_by_id` doesn't check for visibility as we | ||
# don't check the visibility in `get_organization_by_slug` either (only_active=False). | ||
organization_context = organization_service.get_organization_by_id( | ||
id=int(organization_slug), user_id=request.user.id | ||
id=int(organization_id_or_slug), user_id=request.user.id | ||
) | ||
else: | ||
organization_context = organization_service.get_organization_by_slug( | ||
slug=str(organization_slug), only_visible=False, user_id=request.user.id | ||
slug=str(organization_id_or_slug), only_visible=False, user_id=request.user.id | ||
) | ||
if organization_context is None: | ||
raise ResourceDoesNotExist | ||
|
@@ -536,32 +548,42 @@ def get_filter_params( | |
def convert_args( | ||
self, | ||
request: Request, | ||
organization_slug: str | int | None = None, | ||
*args: Any, | ||
**kwargs: Any, | ||
) -> tuple[tuple[Any, ...], dict[str, Any]]: | ||
""" | ||
We temporarily allow the organization_slug to be an integer as it actually can be both slug or id | ||
We temporarily allow the organization_id_or_slug to be an integer as it actually can be both slug or id | ||
Eventually, we will rename this method to organization_id_or_slug | ||
""" | ||
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 not subdomain_is_region(request): | ||
subdomain = getattr(request, "subdomain", None) | ||
if subdomain is not None and subdomain != organization_slug: | ||
if subdomain is not None and subdomain != organization_id_or_slug: | ||
raise ResourceDoesNotExist | ||
|
||
if not organization_slug: | ||
if not organization_id_or_slug: | ||
raise ResourceDoesNotExist | ||
|
||
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 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,10 +111,19 @@ class ProjectEndpoint(Endpoint): | |
def convert_args( | ||
self, | ||
request: Request, | ||
organization_slug: str | int, | ||
*args, | ||
**kwargs, | ||
): | ||
if args and args[0] is not None: | ||
organization_id_or_slug: int | str = 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" | ||
) | ||
|
||
if args and args[0] is not None: | ||
project_id_or_slug: int | str = args[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get this. So args[0] is both project slug and org slug?! Edit: Oh I see. You're removing args one by one. Why not keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a temporary jerry rig so that we maintain backwards compatibility with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a TODO comment and make sure they will be done right after. I see your point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope it isn't, Org is above Project in the hierarchy |
||
# Required so it behaves like the original convert_args, where project_id_or_slug was another parameter | ||
|
@@ -125,11 +134,11 @@ def convert_args( | |
) | ||
try: | ||
if id_or_slug_path_params_enabled( | ||
self.convert_args.__qualname__, str(organization_slug) | ||
self.convert_args.__qualname__, str(organization_id_or_slug) | ||
): | ||
project = ( | ||
Project.objects.filter( | ||
organization__slug__id_or_slug=organization_slug, | ||
organization__slug__id_or_slug=organization_id_or_slug, | ||
slug__id_or_slug=project_id_or_slug, | ||
) | ||
.select_related("organization") | ||
|
@@ -139,7 +148,7 @@ def convert_args( | |
else: | ||
project = ( | ||
Project.objects.filter( | ||
organization__slug=organization_slug, slug=project_id_or_slug | ||
organization__slug=organization_id_or_slug, slug=project_id_or_slug | ||
) | ||
.select_related("organization") | ||
.prefetch_related("teams") | ||
|
@@ -151,24 +160,24 @@ def convert_args( | |
# This will only happen if the passed in project_id_or_slug is a slug and not an id | ||
redirect = ProjectRedirect.objects.select_related("project") | ||
if id_or_slug_path_params_enabled( | ||
self.convert_args.__qualname__, str(organization_slug) | ||
self.convert_args.__qualname__, str(organization_id_or_slug) | ||
): | ||
redirect = redirect.get( | ||
organization__slug__id_or_slug=organization_slug, | ||
organization__slug__id_or_slug=organization_id_or_slug, | ||
redirect_slug=project_id_or_slug, | ||
) | ||
else: | ||
redirect = redirect.get( | ||
organization__slug=organization_slug, redirect_slug=project_id_or_slug | ||
organization__slug=organization_id_or_slug, redirect_slug=project_id_or_slug | ||
) | ||
# Without object permissions don't reveal the rename | ||
self.check_object_permissions(request, redirect.project) | ||
|
||
# get full path so that we keep query strings | ||
requested_url = request.get_full_path() | ||
new_url = requested_url.replace( | ||
f"projects/{organization_slug}/{project_id_or_slug}/", | ||
f"projects/{organization_slug}/{redirect.project.slug}/", | ||
f"projects/{organization_id_or_slug}/{project_id_or_slug}/", | ||
f"projects/{organization_id_or_slug}/{redirect.project.slug}/", | ||
) | ||
|
||
# Resource was moved/renamed if the requested url is different than the new url | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getsantry made these changes so I am assuming they are correct