Skip to content

feat(auth): add passkey-2fa toggle to user admin#60568

Merged
a-lider merged 2 commits into
masterfrom
feat/passkey-2fa-admin-toggle
May 29, 2026
Merged

feat(auth): add passkey-2fa toggle to user admin#60568
a-lider merged 2 commits into
masterfrom
feat/passkey-2fa-admin-toggle

Conversation

@a-lider
Copy link
Copy Markdown
Contributor

@a-lider a-lider commented May 28, 2026

Problem

Follow-up to #60503. While debugging that one, I had to flip passkeys_enabled_for_2fa for a stuck user via the prod Django shell — impersonation blocks all /api/users/ writes, and the toggle wasn't surfaced anywhere in admin. Adding it so support can unblock similar cases.

Changes

  • Expose passkeys_enabled_for_2fa as an editable field on UserAdmin.
  • Mirror the API-side guard (UserSerializer.validate_passkeys_enabled_for_2fa) in UserChangeForm.clean_passkeys_enabled_for_2fa: refuse to enable when the user has no verified passkey.
Screenshot 2026-05-29 at 00 09 30 Screenshot 2026-05-29 at 00 09 38

Publish to changelog?

no

Expose passkeys_enabled_for_2fa as an editable field on the Django admin
user change form and add a UserChangeForm.clean_passkeys_enabled_for_2fa
guard that mirrors the API-side validation — refuses to flip the flag on
unless the user has at least one verified WebauthnCredential, since the
backend enforce_two_factor check needs both to accept the passkey as a
second factor.

The existing two_factor_status read-only display already shows whether a
user has TOTP and/or passkeys configured, so no additional surfacing is
needed there.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 28, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
posthog/admin/test_admin.py:126-152
**Prefer parameterised tests for `clean_passkeys_enabled_for_2fa`**

The four new tests all exercise the same method with different setups — no passkey, unverified passkey, verified passkey, and disabling. This is exactly the pattern the team collapses into a single parameterised test, keeping the boilerplate DRY and making the case table easy to extend. The two `from django.core.exceptions import ValidationError` inline imports are also a symptom of the same duplication; a module-level import shared by a single parameterised test would resolve both at once.

Reviews (1): Last reviewed commit: "feat(auth): add passkey-2fa toggle to us..." | Re-trigger Greptile

Comment thread posthog/admin/test_admin.py Outdated
@a-lider a-lider requested a review from a team May 28, 2026 22:10
@a-lider a-lider enabled auto-merge (squash) May 28, 2026 22:10
Keep only the rejection case for clean_passkeys_enabled_for_2fa. The
other branches are either covered by it (unverified passkey ⇒ no
verified passkey) or have no logic to assert (happy path, disable
regardless). Matches the existing convention in posthog/admin/, where
clean_* methods on admin forms (clean_is_staff, clean_test_account_filters,
clean_team_ids, …) are not unit-tested.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@a-lider a-lider added the stamphog Request AI review from stamphog label May 28, 2026
Copy link
Copy Markdown

@stamphog stamphog Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates denied this PR because it touches authentication logic (passkeys/2FA admin toggle). Auth changes require human review regardless of size. Additionally, there's an unresolved bot comment recommending parameterized tests that hasn't been addressed.

@stamphog stamphog Bot removed the stamphog Request AI review from stamphog label May 28, 2026
@a-lider a-lider merged commit 5ac3152 into master May 29, 2026
250 checks passed
@a-lider a-lider deleted the feat/passkey-2fa-admin-toggle branch May 29, 2026 13:43
@deployment-status-posthog
Copy link
Copy Markdown

deployment-status-posthog Bot commented May 29, 2026

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-05-29 14:09 UTC Run
prod-us ✅ Deployed 2026-05-29 14:26 UTC Run
prod-eu ✅ Deployed 2026-05-29 14:37 UTC Run

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants