Skip to content

Commit fb70475

Browse files
Add exclude param to get explore saved queries endpoint
1 parent 79c646d commit fb70475

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/sentry/explore/endpoints/explore_saved_queries.py

+6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ def get(self, request: Request, organization) -> Response:
129129
else:
130130
order_by = ["lower_name"]
131131

132+
exclude = request.query_params.get("exclude")
133+
if exclude == "shared":
134+
queryset = queryset.filter(created_by_id=request.user.id)
135+
elif exclude == "owned":
136+
queryset = queryset.exclude(created_by_id=request.user.id)
137+
132138
queryset = queryset.order_by(*order_by)
133139

134140
def data_fn(offset, limit):

tests/sentry/explore/endpoints/test_explore_saved_queries.py

+21
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,27 @@ def test_get_expired_query(self):
222222
assert response.status_code == 200, response.content
223223
assert response.data[0]["expired"]
224224

225+
def test_get_my_queries(self):
226+
with self.feature(self.feature_name):
227+
response = self.client.get(self.url, data={"exclude": "shared"})
228+
assert response.status_code == 200, response.content
229+
assert len(response.data) == 1
230+
231+
def test_get_shared_queries(self):
232+
query = {"fields": ["span.op"], "mode": "samples"}
233+
model = ExploreSavedQuery.objects.create(
234+
organization=self.org,
235+
created_by_id=self.user.id + 1,
236+
name="Shared query",
237+
query=query,
238+
)
239+
model.set_projects(self.project_ids)
240+
241+
with self.feature(self.feature_name):
242+
response = self.client.get(self.url, data={"exclude": "owned"})
243+
assert response.status_code == 200, response.content
244+
assert len(response.data) == 1
245+
225246
def test_post_require_mode(self):
226247
with self.feature(self.feature_name):
227248
response = self.client.post(

0 commit comments

Comments
 (0)