Fix infinite login redirect on admin site with AdminSiteOTPRequiredMixin #757
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.
When using AdminSiteOTPRequiredMixin, users who don't have 2FA set up will face an infinite login redirect, similar to the behaviour prior to #499/#500.
In #558, a change was made to fix a regression introduced by #500 by restricting when the 2FA setup login redirect will apply. But, the restriction logic only considers the use of OTPRequiredMixin. It doesn't consider the use of AdminSiteOTPRequiredMixin. Thus, users of AdminSiteOTPRequiredMixin on their admin site will still see the same broken infinite redirect behaviour from before.
This changes the logic added in #558 to also consider AdminSiteOTPRequiredMixin in addition to OTPRequiredMixin.
Description
Update the is_otp_view logic to additionally consider views that are part of an admin site with the AdminSiteOTPRequiredMixin as OTP views.
Motivation and Context
Fixes the infinite login redirect for admin sites, first described in #499, fixed in #500, then regressed for admin sites specifically in #558.
How Has This Been Tested?
I applied this change to my workplace's Django 4.2.20 app and tried it out by hand to confirm that the infinite redirect is fixed for our admin site. Additionally, I copied the test from #500 which tests the redirect flow for logged out users without OTP on OTP required views but applied it to the OTPAdminSite.
Before the change:
After the change:
Screenshots (if appropriate):
N/A
Types of changes
Checklist: