Skip to content
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

ref(hybrid-cloud): use organization_slug in SharedGroupDetails #42792

Merged
merged 4 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/sentry/api/endpoints/shared_group_details.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from rest_framework.request import Request
from rest_framework.response import Response

Expand All @@ -16,7 +18,9 @@
class SharedGroupDetailsEndpoint(Endpoint, EnvironmentMixin):
permission_classes = ()

def get(self, request: Request, share_id) -> Response:
def get(
self, request: Request, organization_slug: str | None = None, share_id: str | None = None
) -> Response:
"""
Retrieve an aggregate

Expand All @@ -34,6 +38,10 @@ def get(self, request: Request, share_id) -> Response:
except Group.DoesNotExist:
raise ResourceDoesNotExist

if organization_slug:
if organization_slug != group.organization.slug:
return ResourceDoesNotExist

if group.organization.flags.disable_shared_issues:
raise ResourceDoesNotExist

Expand Down
9 changes: 8 additions & 1 deletion src/sentry/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2319,8 +2319,9 @@
),
# Groups
url(r"^(?:issues|groups)/", include(GROUP_URLS)),
# TODO: include in the /organizations/ route tree + remove old dupe once hybrid cloud launches
url(
r"^issues/(?P<organization_slug>[^\/]+)/(?P<issue_id>[^\/]+)/participants/$",
r"^organizations/(?P<organization_slug>[^\/]+)/issues/(?P<issue_id>[^\/]+)/participants/$",
Comment on lines -2323 to +2324
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the old URL for participants?

Copy link
Member Author

Choose a reason for hiding this comment

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

i'm keeping it for now since it's getting some occasional hits

GroupParticipantsEndpoint.as_view(),
name="sentry-api-0-group-stats-with-org",
),
Expand All @@ -2329,6 +2330,12 @@
GroupParticipantsEndpoint.as_view(),
name="sentry-api-0-group-stats",
),
# TODO: include in the /organizations/ route tree + remove old dupe once hybrid cloud launches
url(
r"^organizations/(?P<organization_slug>[^\/]+)/shared/(?:issues|groups)/(?P<share_id>[^\/]+)/$",
SharedGroupDetailsEndpoint.as_view(),
name="sentry-api-0-shared-group-details-with-org",
),
url(
r"^shared/(?:issues|groups)/(?P<share_id>[^\/]+)/$",
SharedGroupDetailsEndpoint.as_view(),
Expand Down
46 changes: 28 additions & 18 deletions tests/sentry/api/endpoints/test_shared_group_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
from sentry.testutils.silo import region_silo_test


@region_silo_test
@region_silo_test(stable=True)
class SharedGroupDetailsTest(APITestCase):
def _get_path_functions(self):
return (
lambda share_id: f"/api/0/shared/issues/{share_id}/",
lambda share_id: f"/api/0/organizations/{self.organization.slug}/shared/issues/{share_id}/",
)

def test_simple(self):
self.login_as(user=self.user)

Expand All @@ -21,14 +27,15 @@ def test_simple(self):
share_id = group.get_share_id()
assert share_id is not None

url = f"/api/0/shared/issues/{share_id}/"
response = self.client.get(url, format="json")
for path_func in self._get_path_functions():
path = path_func(share_id)
response = self.client.get(path, format="json")

assert response.status_code == 200, response.content
assert response.data["id"] == str(group.id)
assert response.data["latestEvent"]["id"] == str(event.event_id)
assert response.data["project"]["slug"] == group.project.slug
assert response.data["project"]["organization"]["slug"] == group.organization.slug
assert response.status_code == 200, response.content
assert response.data["id"] == str(group.id)
assert response.data["latestEvent"]["id"] == str(event.event_id)
assert response.data["project"]["slug"] == group.project.slug
assert response.data["project"]["organization"]["slug"] == group.organization.slug

def test_feature_disabled(self):
self.login_as(user=self.user)
Expand All @@ -46,10 +53,11 @@ def test_feature_disabled(self):
share_id = group.get_share_id()
assert share_id is not None

url = f"/api/0/shared/issues/{share_id}/"
response = self.client.get(url, format="json")
for path_func in self._get_path_functions():
path = path_func(share_id)
response = self.client.get(path, format="json")

assert response.status_code == 404
assert response.status_code == 404

def test_permalink(self):
group = self.create_group()
Expand All @@ -62,14 +70,16 @@ def test_permalink(self):
share_id = group.get_share_id()
assert share_id is not None

url = f"/api/0/shared/issues/{share_id}/"
response = self.client.get(url, format="json")
for path_func in self._get_path_functions():
path = path_func(share_id)
response = self.client.get(path, format="json")

assert response.status_code == 200, response.content
assert not response.data["permalink"] # not show permalink when not logged in
assert response.status_code == 200, response.content
assert not response.data["permalink"] # not show permalink when not logged in

self.login_as(user=self.user)
response = self.client.get(url, format="json")
for path_func in self._get_path_functions():
response = self.client.get(path, format="json")

assert response.status_code == 200, response.content
assert response.data["permalink"] # show permalink when logged in
assert response.status_code == 200, response.content
assert response.data["permalink"] # show permalink when logged in