Skip to content

Commit 8b5e30f

Browse files
committed
ref(typing): Check batched feature flags against the acting user
The events, events-stats and trace-item-attributes endpoints pass acting_user(request.user) to features.batch_has() instead of the raw principal. Feature handlers here and in getsentry only read the actor as `actor is not None and actor.is_superuser` or through has_user(), so None and AnonymousUser behave the same and nothing changes for users or token callers. Drops the three endpoints from the request.user allowlist.
1 parent 68466b8 commit 8b5e30f

5 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎src/sentry/api/endpoints/organization_events.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
)
3838
from sentry.apidocs.response_types import DetailResponse
3939
from sentry.apidocs.utils import inline_sentry_response_serializer
40+
from sentry.auth.principal import acting_user
4041
from sentry.discover.models import DiscoverSavedQuery, DiscoverSavedQueryTypes
4142
from sentry.explore.models import ExploreSavedFormula, ExploreSavedQueryDataset
4243
from sentry.ingestion_delay.meta import IngestionMeta
@@ -159,7 +160,7 @@ def get_features(self, organization: Organization, request: Request) -> Mapping[
159160
batch_features = features.batch_has(
160161
feature_names,
161162
organization=organization,
162-
actor=request.user,
163+
actor=acting_user(request.user),
163164
)
164165

165166
all_features: dict[str, bool] = {}

‎src/sentry/api/endpoints/organization_events_stats.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from sentry.api.serializers.snuba import StatsTimeSeriesResult
2222
from sentry.apidocs.utils import inline_sentry_response_serializer
23+
from sentry.auth.principal import acting_user
2324
from sentry.constants import MAX_TOP_EVENTS
2425
from sentry.models.dashboard_widget import DashboardWidget, DashboardWidgetTypes
2526
from sentry.models.organization import Organization
@@ -79,7 +80,7 @@ def get_features(
7980
batch_features = features.batch_has(
8081
feature_names,
8182
organization=organization,
82-
actor=request.user,
83+
actor=acting_user(request.user),
8384
)
8485
return (
8586
batch_features.get(f"organization:{organization.id}", {})

‎src/sentry/api/endpoints/organization_trace_item_attributes.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
as_validation_errors,
6565
)
6666
from sentry.apidocs.utils import inline_sentry_response_serializer
67+
from sentry.auth.principal import acting_user
6768
from sentry.auth.staff import is_active_staff
6869
from sentry.auth.superuser import is_active_superuser
6970
from sentry.exceptions import InvalidSearchQuery
@@ -256,7 +257,7 @@ class OrganizationTraceItemAttributesEndpointBase(OrganizationEventsEndpointBase
256257

257258
def has_feature(self, organization: Organization, request: Request) -> bool:
258259
batch_features = features.batch_has(
259-
self.feature_flags, organization=organization, actor=request.user
260+
self.feature_flags, organization=organization, actor=acting_user(request.user)
260261
)
261262

262263
if batch_features is None:

‎tests/sentry/auth/test_principal.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def _is_request_user_type_check(node: ast.AST) -> bool:
277277
# Lower these as callers move off. Exact, so the baseline can't drift back up.
278278
REQUEST_USER_ID_BASELINE = 133
279279
REQUEST_USER_TYPE_CHECK_BASELINE = 29
280-
REQUEST_USER_ALLOWLIST_BASELINE = 15
280+
REQUEST_USER_ALLOWLIST_BASELINE = 12
281281

282282

283283
def test_request_user_id_uses_only_go_down() -> None:

‎tools/mypy_helpers/request_user_allowlist.txt‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
src/sentry/api/bases/organizationmember.py
2-
src/sentry/api/endpoints/organization_events.py
3-
src/sentry/api/endpoints/organization_events_stats.py
42
src/sentry/api/endpoints/organization_releases.py
5-
src/sentry/api/endpoints/organization_trace_item_attributes.py
63
src/sentry/api/endpoints/prompts_activity.py
74
src/sentry/core/endpoints/organization_member_details.py
85
src/sentry/core/endpoints/organization_member_index.py

0 commit comments

Comments
 (0)