Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/sentry/api/endpoints/project_custom_inbound_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,19 @@ class ProjectCustomInboundFilterEndpoint(ProjectEndpoint):
owner = ApiOwner.TELEMETRY_EXPERIENCE
permission_classes = (ProjectSettingPermission,)

def has_feature(self, request: Request, project: Project) -> bool:
def require_inbound_filters_v2(self, request: Request, project: Project) -> None:
if not features.has(
"organizations:inbound-filters-v2", project.organization, actor=request.user
):
raise ResourceDoesNotExist

def has_feature(self, request: Request, project: Project) -> bool:
"""
Whether the project may change its filters. Reads do not need the plan feature:
Relay stops applying the filters without it, but an organization that left the
plan still sees what it has, and gets it back on upgrade.
"""
self.require_inbound_filters_v2(request, project)
return features.has("projects:custom-inbound-filters", project, actor=request.user)

def get_custom_inbound_filter(self, project: Project, filter_id: str) -> CustomInboundFilter:
Expand Down Expand Up @@ -317,8 +324,7 @@ def get(
"""
List the custom inbound filters configured for a project.
"""
if not self.has_feature(request, project):
return Response({"detail": "You do not have that feature enabled"}, status=400)
self.require_inbound_filters_v2(request, project)

filters = _user_filters(project)
return self.paginate(
Expand Down Expand Up @@ -419,8 +425,7 @@ def get(
"""
Retrieve a single custom inbound filter.
"""
if not self.has_feature(request, project):
return Response({"detail": "You do not have that feature enabled"}, status=400)
self.require_inbound_filters_v2(request, project)

custom_filter = self.get_custom_inbound_filter(project, filter_id)
return Response(serialize_custom_inbound_filter(custom_filter))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ def test_without_inbound_filters_v2_feature(self) -> None:
with self.feature(["projects:custom-inbound-filters"]):
self.get_error_response(self.organization.slug, self.project.slug, status_code=404)

def test_without_custom_inbound_filters_plan_feature(self) -> None:
def test_lists_without_custom_inbound_filters_plan_feature(self) -> None:
custom_filter = self.create_project_custom_inbound_filter(project=self.project)

with self.feature(["organizations:inbound-filters-v2"]):
response = self.get_error_response(
self.organization.slug, self.project.slug, status_code=400
)
response = self.get_success_response(self.organization.slug, self.project.slug)

assert response.data["detail"] == "You do not have that feature enabled"
assert [f["id"] for f in response.data] == [str(custom_filter.id)]

def test_rejects_condition_the_data_type_does_not_carry(self) -> None:
cases = [
Expand Down Expand Up @@ -882,13 +882,22 @@ def test_without_inbound_filters_v2_feature(self) -> None:
status_code=404,
)

def test_without_custom_inbound_filters_plan_feature(self) -> None:
def test_reads_without_custom_inbound_filters_plan_feature(self) -> None:
with self.feature(["organizations:inbound-filters-v2"]):
response = self.get_success_response(
self.organization.slug, self.project.slug, self.custom_filter.id, method="get"
)

assert response.data["id"] == str(self.custom_filter.id)

def test_refuses_writes_without_custom_inbound_filters_plan_feature(self) -> None:
with self.feature(["organizations:inbound-filters-v2"]):
response = self.get_error_response(
self.organization.slug,
self.project.slug,
self.custom_filter.id,
method="get",
method="put",
active=False,
status_code=400,
)

Expand Down
5 changes: 5 additions & 0 deletions tests/sentry/ingest/test_inbound_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,11 @@ def test_custom_inbound_filters_stop_at_the_project_cap(default_project, factori
["ip-address"],
id="generic_ip_filter_needs_no_plan_feature",
),
pytest.param(
InboundFilterFeatures(custom_inbound_filters_v2=True),
[],
id="custom_inbound_filters_v2_need_plan_feature",
),
pytest.param(
InboundFilterFeatures(True, True, True, True, True),
["ip-address", "log-message", "trace-metric-name", "cif"],
Expand Down
Loading