Skip to content

Commit

Permalink
🔧 chore(api): publish project filter endpoint (#81175)
Browse files Browse the repository at this point in the history
publishing an unowned endpoint

<img width="1521" alt="image"
src="https://github.com/user-attachments/assets/8671179c-ccd9-427d-a003-b6db554b86b1">

---------

Co-authored-by: Isabella Enriquez <[email protected]>
  • Loading branch information
iamrajjoshi and isabellaenriquez authored Nov 22, 2024
1 parent e0bfa93 commit 4e8a6ba
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/sentry/api/endpoints/project_filters.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
from typing import TypedDict

from drf_spectacular.utils import extend_schema
from rest_framework.request import Request
from rest_framework.response import Response

from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.project import ProjectEndpoint
from sentry.apidocs.constants import RESPONSE_FORBIDDEN
from sentry.apidocs.examples.project_examples import ProjectExamples
from sentry.apidocs.parameters import GlobalParams
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.ingest import inbound_filters


class ProjectFilterResponse(TypedDict):
id: str
active: bool | list[str]


@region_silo_endpoint
@extend_schema(tags=["Projects"])
class ProjectFiltersEndpoint(ProjectEndpoint):
owner = ApiOwner.UNOWNED
publish_status = {
"GET": ApiPublishStatus.UNKNOWN,
"GET": ApiPublishStatus.PUBLIC,
}

@extend_schema(
operation_id="List a Project's Data Filters",
parameters=[
GlobalParams.ORG_ID_OR_SLUG,
GlobalParams.PROJECT_ID_OR_SLUG,
],
responses={
200: inline_sentry_response_serializer(
"ProjectFilterResponse", list[ProjectFilterResponse]
),
403: RESPONSE_FORBIDDEN,
},
examples=ProjectExamples.GET_PROJECT_FILTERS,
)
def get(self, request: Request, project) -> Response:
"""
List a project's filters
Retrieve a list of filters for a given project.
{method} {path}
`active` will be either a boolean or a list for the legacy browser filters.
"""
results = []
for flt in inbound_filters.get_all_filter_specs():
Expand Down
27 changes: 27 additions & 0 deletions src/sentry/apidocs/examples/project_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,30 @@ class ProjectExamples:
response_only=True,
),
]

GET_PROJECT_FILTERS = [
OpenApiExample(
"List a project's filters",
value=[
{"id": "browser-extensions", "active": False},
{"id": "filtered-transaction", "active": True},
{
"id": "legacy-browsers",
"active": [
"opera",
"edge",
"safari",
"chrome",
"ie",
"opera_mini",
"firefox",
"android",
],
},
{"id": "localhost", "active": False},
{"id": "web-crawlers", "active": True},
],
status_codes=["200"],
response_only=True,
),
]

0 comments on commit 4e8a6ba

Please sign in to comment.