Skip to content

ref(typing): Let shared helpers take a service account - #129413

Open
gricha wants to merge 1 commit into
ref/typing-serialize-principalfrom
ref/typing-shared-principal
Open

gricha wants to merge 1 commit into
ref/typing-serialize-principalfrom
ref/typing-shared-principal

Conversation

@gricha

@gricha gricha commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

The helpers that endpoints hand request.user to now take a RequestPrincipal: feature gates (get_excluded_detector_types, has_investigations_access, should_serve_action_log_activity), Seer agent access (SeerAgentClient, has_seer_agent_access_with_detail, collect_user_org_context, commit_author_for_user), is_demo_user, has_staff_option, TeamManager.get_for_user and the group activity serializers.

  • Most only pass the caller on to features.has() or serialize(), or already check has_user(): type-only.
  • SeerAgentClient reads the user id once through acting_user_id() instead of six hasattr(self.user, "id") checks. is_demo_user, collect_user_org_context and commit_author_for_user use acting_user_id() / has_user().

Users, agents and token callers get the same values as before. A service account now gets no user (no user_id on its Seer runs, org context without personal teams) instead of a ServiceAccountId that 403s when used as an int.

Without it, #129402's mypy check would flag 14 more files.

@gricha
gricha added this pull request to stack #129364 October 31, 2026 01:30
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 31, 2026
@gricha
gricha removed this pull request from stack #129364 November 1, 2026 04:24
@gricha
gricha force-pushed the ref/typing-shared-principal branch from e468a0c to 6365812 Compare November 1, 2026 04:24
@gricha
gricha added this pull request to stack #129440 November 1, 2026 04:24
gricha added a commit that referenced this pull request Nov 1, 2026
The SeerAgentClient change from #129413: read the caller's user id with
acting_user_id instead of request.user.id, so a service account gets None
instead of a 403 from the ServiceAccountId guard.
@gricha
gricha force-pushed the ref/typing-shared-principal branch from 6365812 to 246502d Compare November 2, 2026 19:55
@gricha
gricha marked this pull request as ready for review November 2, 2026 20:06
@gricha
gricha requested review from a team as code owners November 2, 2026 20:06
@gricha
gricha requested review from azulus, cvxluo and skaasten November 2, 2026 20:25
@gricha
gricha removed this pull request from stack #129440 November 2, 2026 21:45
@gricha
gricha added this pull request to stack #129572 November 2, 2026 21:45
Feature gates, Seer agent access, demo/staff checks, team lookup and activity serializers now take a RequestPrincipal. Most only pass the caller to features.has() or serialize(), so this is type-only. The rest read the user id through acting_user_id()/has_user(): users, agents and token callers get the same values, and a service account gets no user instead of a ServiceAccountId.
@gricha
gricha force-pushed the ref/typing-shared-principal branch from 246502d to 1e83cd4 Compare November 2, 2026 22:08

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