Skip to content

ref(auth): Add acting_user(), is_acting_user() and owned_by_acting_user() - #129400

Open
gricha wants to merge 1 commit into
ref/sa-codemod-integrationsfrom
ref/principal-ownership-helpers
Open

gricha wants to merge 1 commit into
ref/sa-codemod-integrationsfrom
ref/principal-ownership-helpers

Conversation

@gricha

@gricha gricha commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Adds three helpers to sentry.auth.principal for the remaining request.user.id reads, so every call site is one line and none branches on the caller type:

  • acting_user(principal): the user behind the caller as an object, or None. For APIs that take a user, like as_user=, which can't take a principal across RPC.
  • is_acting_user(principal, user_id): "is this mine?". False when no user is behind the caller, so a missing user id never matches.
  • owned_by_acting_user(principal, field="user_id"): a Q for "mine" (filter) or "not mine" (exclude). With no user it matches nothing, so filter(user_id=None) can't match rows that have no user.

src/AGENTS.md lists them, with a short owned_by_acting_user example (filter, exclude, a custom column, combining with other Qs), plus request.access.role for the caller's org role. With acting_user_id, require_user, requires_user, get_creator_reference and request.access, every remaining kind of read maps to one helper; #129401 shows them on real endpoints.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 30, 2026
@gricha
gricha changed the base branch from master to ref/sa-codemod-integrations October 31, 2026 01:29
@gricha
gricha force-pushed the ref/principal-ownership-helpers branch from 344c697 to a8a781b Compare October 31, 2026 01:29
@gricha
gricha added this pull request to stack #129364 October 31, 2026 01:30
@gricha
gricha removed this pull request from stack #129364 November 1, 2026 04:24
@gricha
gricha added this pull request to stack #129440 November 1, 2026 04:24
…er()

Helpers for the remaining request.user.id reads that ask whether something belongs to the caller, or hand the caller to an API that takes a user, so call sites never branch on the caller type or pass a possibly-None user id:

- acting_user(principal): the user behind the caller as an object, or None. For APIs like as_user= that take a user and can't take a principal across RPC.
- is_acting_user(principal, user_id): "is this mine?", False when no user is behind the caller.
- owned_by_acting_user(principal, field="user_id"): a Q for "mine" (filter) or "not mine" (exclude). With no user it matches nothing, so filter(user_id=None) can't match rows that have no user.

src/AGENTS.md lists them, and request.access.role for the caller's org role.
@gricha
gricha marked this pull request as ready for review November 2, 2026 19:38
@gricha
gricha requested review from a team as code owners November 2, 2026 19:38
@gricha
gricha requested a review from azulus November 2, 2026 19:39
@gricha
gricha force-pushed the ref/principal-ownership-helpers branch from a8a781b to 77f6288 Compare November 2, 2026 19:55
@sentry

sentry Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Sentry Snapshot Testing

Name Added Removed Changed Renamed Unchanged Skipped Status
sentry-frontend
sentry-frontend
0 0 0 0 780 0 ✅ Unchanged

⚙️ sentry-frontend Snapshot Settings

@gricha
gricha requested review from cvxluo and skaasten November 2, 2026 20:25

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.

2 participants