Skip to content

ref(explore): Narrow request.user in saved queries and dashboards - #129415

Draft
gricha wants to merge 1 commit into
ref/sa-narrow-api-afrom
ref/sa-narrow-explore
Draft

gricha wants to merge 1 commit into
ref/sa-narrow-api-afrom
ref/sa-narrow-explore

Conversation

@gricha

@gricha gricha commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Explore and Discover saved queries, the homepage query, stars and dashboards read the caller through sentry.auth.principal, following the issue-views pattern from #129401: shared rows for everyone, personal state (stars, last visited, "created by me") only for a user.

  • A service account can list saved queries and Discover's myqueries (shared rows, nothing starred), the homepage GET returns 204, visits count without a last-visited row, and a query created with starred is created unstarred. Stars, favorites and homepage PUT are 403 user-required. Lists and creates skip personal state up front instead of reporting a caught UserRequired to Sentry on every call. New tests cover each; they fail on the old code.
  • Token callers: Discover sortBy=myqueries no longer sorts creator-less queries first, and Explore's visit endpoint returns 204 instead of a 500 (NOT NULL write): the visit counts, with no last-visited row, as Discover and dashboard visits already did.
  • Users and agents see no change.

Left: organization_dashboards.py calls has_edit_permissions(request.user.id), which needs to take the caller; and DashboardListSerializer still reads user.id, so a service account listing a non-empty set of dashboards still gets 403. Both are in the serializer follow-up.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 31, 2026
@gricha
gricha added this pull request to stack #129364 October 31, 2026 02:27
@gricha
gricha removed this pull request from stack #129364 November 1, 2026 04:24
@gricha
gricha force-pushed the ref/sa-narrow-explore branch from 6d91bbc to 51071bb Compare November 1, 2026 04:24
@gricha
gricha added this pull request to stack #129440 November 1, 2026 04:24
Explore and Discover saved queries, the homepage query, stars and dashboards read the caller through `sentry.auth.principal`, following the issue-views pattern from #129401: shared rows for everyone, personal state (stars, last visited, "created by me") only for a user.

- A service account can list saved queries and Discover's `myqueries` (shared rows, nothing starred), the homepage GET returns 204, visits count without a last-visited row, and a query created with `starred` is created unstarred. Stars, favorites and homepage PUT are 403 `user-required`. Lists and creates skip personal state up front instead of reporting a caught `UserRequired` to Sentry on every call. New tests cover each; they fail on the old code.
- Token callers: Discover `sortBy=myqueries` no longer sorts creator-less queries first, and Explore's visit endpoint returns 204 instead of a 500 (NOT NULL write): the visit counts, with no last-visited row, as Discover and dashboard visits already did.
- Users and agents see no change.

Left: `organization_dashboards.py` calls `has_edit_permissions(request.user.id)`, which needs to take the caller; and `DashboardListSerializer` still reads `user.id`, so a service account listing a non-empty set of dashboards still gets 403. Both are in the serializer follow-up.
@gricha
gricha force-pushed the ref/sa-narrow-explore branch from 51071bb to e09a478 Compare November 1, 2026 04:57
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

decision-model-linter

api

src/sentry/explore/endpoints/explore_saved_queries.py

  • warn readsRequestBodyOutsideSerializer = TRUE (0.93): Request body values should be read from a serializer's validated_data. This file reads a value directly from request.data or request.POST.

decision-model-linter: 36 calls on 12 files, 79,785 input tokens, $0.0034, model typesafe/jev-1.13-20260917

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant