From 05ced3e74d428c53836b323e197d69ae82cbc138 Mon Sep 17 00:00:00 2001 From: Joshua Ferge Date: Thu, 4 May 2023 19:09:09 -0700 Subject: [PATCH] add to more checks in issue details and add test coverage --- .../api/endpoints/organization_group_index.py | 24 ++++++++++++++----- .../endpoints/organization_issues_count.py | 8 +++++-- .../api/endpoints/test_organization_events.py | 14 +++++++++-- .../test_organization_group_index.py | 6 +++++ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/sentry/api/endpoints/organization_group_index.py b/src/sentry/api/endpoints/organization_group_index.py index c9dfdd3f389928..40533124972a4f 100644 --- a/src/sentry/api/endpoints/organization_group_index.py +++ b/src/sentry/api/endpoints/organization_group_index.py @@ -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 @@ -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 @@ -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 diff --git a/src/sentry/api/endpoints/organization_issues_count.py b/src/sentry/api/endpoints/organization_issues_count.py index 3b1fff8400f67a..9e3cbee2714ea3 100644 --- a/src/sentry/api/endpoints/organization_issues_count.py +++ b/src/sentry/api/endpoints/organization_issues_count.py @@ -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 diff --git a/tests/snuba/api/endpoints/test_organization_events.py b/tests/snuba/api/endpoints/test_organization_events.py index 124a8f4d905076..b7f7f1c63730eb 100644 --- a/tests/snuba/api/endpoints/test_organization_events.py +++ b/tests/snuba/api/endpoints/test_organization_events.py @@ -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: @@ -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() diff --git a/tests/snuba/api/endpoints/test_organization_group_index.py b/tests/snuba/api/endpoints/test_organization_group_index.py index 404f76d6a49b26..2ff8bfb7b1dd6f 100644 --- a/tests/snuba/api/endpoints/test_organization_group_index.py +++ b/tests/snuba/api/endpoints/test_organization_group_index.py @@ -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)