feat(auth): add passkey-2fa toggle to user admin#60568
Merged
Merged
Conversation
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>
Contributor
Prompt To Fix All With AIFix 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 |
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>
ReeceJones
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #60503. While debugging that one, I had to flip
passkeys_enabled_for_2fafor 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
passkeys_enabled_for_2faas an editable field onUserAdmin.UserSerializer.validate_passkeys_enabled_for_2fa) inUserChangeForm.clean_passkeys_enabled_for_2fa: refuse to enable when the user has no verified passkey.Publish to changelog?
no