Skip to content

Commit

Permalink
add to more checks in issue details and add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshFerge committed May 5, 2023
1 parent 54f9bd1 commit 05ced3e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
24 changes: 18 additions & 6 deletions src/sentry/api/endpoints/organization_group_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ def get(self, request: Request, organization) -> Response:
if not projects:
return Response([])

if len(projects) > 1 and not features.has(
"organizations:global-views", organization, actor=request.user
is_fetching_replay_data = request.headers.get("X-Sentry-Replay-Request") == "1"
if (
len(projects) > 1
and not features.has("organizations:global-views", organization, actor=request.user)
and not is_fetching_replay_data
):
return Response(
{"detail": "You do not have the multi project stream feature enabled"}, status=400
Expand Down Expand Up @@ -428,8 +431,12 @@ def put(self, request: Request, organization) -> Response:
:auth: required
"""
projects = self.get_projects(request, organization)
if len(projects) > 1 and not features.has(
"organizations:global-views", organization, actor=request.user
is_fetching_replay_data = request.headers.get("X-Sentry-Replay-Request") == "1"

if (
len(projects) > 1
and not features.has("organizations:global-views", organization, actor=request.user)
and not is_fetching_replay_data
):
return Response(
{"detail": "You do not have the multi project stream feature enabled"}, status=400
Expand Down Expand Up @@ -469,8 +476,13 @@ def delete(self, request: Request, organization) -> Response:
:auth: required
"""
projects = self.get_projects(request, organization)
if len(projects) > 1 and not features.has(
"organizations:global-views", organization, actor=request.user

is_fetching_replay_data = request.headers.get("X-Sentry-Replay-Request") == "1"

if (
len(projects) > 1
and not features.has("organizations:global-views", organization, actor=request.user)
and not is_fetching_replay_data
):
return Response(
{"detail": "You do not have the multi project stream feature enabled"}, status=400
Expand Down
8 changes: 6 additions & 2 deletions src/sentry/api/endpoints/organization_issues_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ def get(self, request: Request, organization) -> Response:
if not projects:
return Response([])

if len(projects) > 1 and not features.has(
"organizations:global-views", organization, actor=request.user
is_fetching_replay_data = request.headers.get("X-Sentry-Replay-Request") == "1"

if (
len(projects) > 1
and not features.has("organizations:global-views", organization, actor=request.user)
and not is_fetching_replay_data
):
return Response(
{"detail": "You do not have the multi project stream feature enabled"}, status=400
Expand Down
14 changes: 12 additions & 2 deletions tests/snuba/api/endpoints/test_organization_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def reverse_url(self):
kwargs={"organization_slug": self.organization.slug},
)

def do_request(self, query, features=None):
def do_request(self, query, features=None, **kwargs):
if features is None:
features = {"organizations:discover-basic": True}
features.update(self.features)
self.login_as(user=self.user)
with self.feature(features):
return self.client_get(self.reverse_url(), query, format="json")
return self.client_get(self.reverse_url(), query, format="json", **kwargs)

def load_data(self, platform="transaction", timestamp=None, duration=None, **kwargs):
if timestamp is None:
Expand Down Expand Up @@ -179,6 +179,16 @@ def test_multi_project_feature_gate_rejection(self):
assert response.status_code == 400
assert "events from multiple projects" in response.data["detail"]

def test_multi_project_feature_gate_replays(self):
team = self.create_team(organization=self.organization, members=[self.user])

project = self.create_project(organization=self.organization, teams=[team])
project2 = self.create_project(organization=self.organization, teams=[team])

query = {"field": ["id", "project.id"], "project": [project.id, project2.id]}
response = self.do_request(query, **{"HTTP_X-Sentry-Replay-Request": "1"})
assert response.status_code == 200

def test_invalid_search_terms(self):
self.create_project()

Expand Down
6 changes: 6 additions & 0 deletions tests/snuba/api/endpoints/test_organization_group_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ def test_feature_gate(self):
response = self.get_response()
assert response.status_code == 200

def test_replay_feature_gate(self):
# allow replays to query for backend
self.create_project(organization=self.project.organization)
self.login_as(user=self.user)
self.get_success_response(extra_headers={"HTTP_X-Sentry-Replay-Request": "1"})

def test_with_all_projects(self):
# ensure there are two or more projects
self.create_project(organization=self.project.organization)
Expand Down

0 comments on commit 05ced3e

Please sign in to comment.