diff --git a/src/sentry/features/helpers.py b/src/sentry/features/helpers.py index 2f11fa1235b578..37c84a71baafdb 100644 --- a/src/sentry/features/helpers.py +++ b/src/sentry/features/helpers.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence +from typing import TYPE_CHECKING, Any, Callable, Sequence from rest_framework.request import Request from rest_framework.response import Response @@ -18,16 +18,11 @@ def any_organization_has_feature( return any([features.has(feature, organization, **kwargs) for organization in organizations]) -def requires_feature( - feature: str, any_org: Optional[bool] = None -) -> Callable[[EndpointFunc], EndpointFunc]: +def requires_feature(feature: str) -> Callable[[EndpointFunc], EndpointFunc]: """ Require a feature flag to access an endpoint. - If ``any_org`` is ``True``, this will check all of the request User's - Organizations for the flag. If any are flagged in, the endpoint is accessible. - - Without ``any_org=True``, the endpoint must resolve an Organization via + The endpoint must resolve an Organization via ``convert_args`` (and therefor be in ``kwargs``). The resolved Org must have the passed feature. @@ -41,26 +36,13 @@ def requires_feature( def decorator(func: EndpointFunc) -> EndpointFunc: def wrapped(self: Any, request: Request, *args: Any, **kwargs: Any) -> Response: - # The endpoint is accessible if any of the User's Orgs have the feature - # flag enabled. - if any_org: - if not any_organization_has_feature( - feature, - Organization.objects.get_for_user_ids({request.user.id}), - actor=request.user, - ): - return Response(status=404) - - return func(self, request, *args, **kwargs) - # The Org in scope for the request must have the feature flag enabled. - else: - if "organization" not in kwargs: - return Response(status=404) - - if not features.has(feature, kwargs["organization"], actor=request.user): - return Response(status=404) - - return func(self, request, *args, **kwargs) + if "organization" not in kwargs: + return Response(status=404) + + if not features.has(feature, kwargs["organization"], actor=request.user): + return Response(status=404) + + return func(self, request, *args, **kwargs) return wrapped diff --git a/tests/sentry/features/test_helpers.py b/tests/sentry/features/test_helpers.py index 21721746ffb7a5..a2219995c9dd8a 100644 --- a/tests/sentry/features/test_helpers.py +++ b/tests/sentry/features/test_helpers.py @@ -56,19 +56,6 @@ def get(self, request, *args, **kwargs): response = get(None, self.request, organization=self.org) assert response.status_code == 200 - def test_any_org_true_when_users_other_org_has_flag_succeeds(self): - # The Org in scope of the request does not have the flag, but another - # Org the User belongs to does. - # - with org_with_feature(self.out_of_scope_org, "foo"): - - @requires_feature("foo", any_org=True) - def get(self, request, *args, **kwargs): - return Response() - - response = get(None, self.request, organization=self.org) - assert response.status_code == 200 - def test_any_org_false_when_users_other_org_has_flag_fails(self): with org_with_feature(self.out_of_scope_org, "foo"):