Skip to content

Commit 75e0860

Browse files
authored
fix(similarity): allow single_org sentry users to not be superuser to call backfill (#70917)
still enforces org / project permissions
1 parent cdf4bd2 commit 75e0860

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/sentry/api/endpoints/project_backfill_similar_issues_embeddings_records.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.conf import settings
12
from rest_framework.request import Request
23
from rest_framework.response import Response
34

@@ -18,11 +19,16 @@ class ProjectBackfillSimilarIssuesEmbeddingsRecords(ProjectEndpoint):
1819
}
1920

2021
def post(self, request: Request, project) -> Response:
21-
if not features.has(
22-
"projects:similarity-embeddings-backfill", project
23-
) or not is_active_superuser(request):
22+
if not features.has("projects:similarity-embeddings-backfill", project):
2423
return Response(status=404)
2524

25+
# needs to have the flag to run
26+
27+
if not (is_active_superuser(request) or settings.SENTRY_SINGLE_ORGANIZATION):
28+
return Response(status=404)
29+
30+
# needs to either be a superuser or be in single org mode
31+
2632
last_processed_id = None
2733
dry_run = False
2834
if request.data.get("last_processed_id"):

tests/sentry/api/endpoints/test_project_backfill_similar_issues_embeddings_records.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from unittest.mock import patch
22

3+
from django.test import override_settings
34
from django.urls import reverse
45

56
from sentry.testutils.cases import APITestCase
@@ -47,6 +48,18 @@ def test_post_success_no_last_processed_id(
4748
assert response.status_code == 204, response.content
4849
mock_backfill_seer_grouping_records.assert_called_with(self.project.id, None, False)
4950

51+
@patch(
52+
"sentry.api.endpoints.project_backfill_similar_issues_embeddings_records.backfill_seer_grouping_records.delay"
53+
)
54+
@with_feature("projects:similarity-embeddings-backfill")
55+
@override_settings(SENTRY_SINGLE_ORGANIZATION=True)
56+
def test_post_success_no_last_processed_id_single_org(
57+
self, mock_backfill_seer_grouping_records
58+
):
59+
response = self.client.post(self.url, data={})
60+
assert response.status_code == 204, response.content
61+
mock_backfill_seer_grouping_records.assert_called_with(self.project.id, None, False)
62+
5063
@patch(
5164
"sentry.api.endpoints.project_backfill_similar_issues_embeddings_records.is_active_superuser",
5265
return_value=True,

0 commit comments

Comments
 (0)