Repository navigation
Fix "Log in as guest" on the login page - #26
Merged
Merged
Conversation
bg-secondary-600 is not compiled into styles.css, so the guest button had no background. Use Unfold's secondary button, and only render it when an active staff 'guest' user exists (otherwise clicking it did nothing). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5
…lures
- get_guest_user() in base/utils replaces three hand-copied queries
(GuestLoginView, AutoGuestLoginMiddleware, login button)
- {% guest_login_available %} tag decides the button in the template itself, so
it works on any admin site rendering admin/login.html; hidden for
authenticated users (GuestLoginView only redirects them) and on lookup
errors (logged, never breaks the login page)
- GuestLoginView shows an error and returns to the login page instead of
silently bouncing; exceptions are logged rather than swallowed
- icon is aria-hidden; tests cover inactive/non-staff guest, authenticated
user, lookup error and the view itself
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5
…, log errors
- GuestLoginView is login_not_required (LoginRequiredMiddleware bounced the
POST to the login page without logging in)
- on failure, return to the login page with the original ?next
- next must match the request scheme (no HTTPS -> HTTP downgrade), as in
Django's LoginView and AutoGuestLoginMiddleware
- AutoGuestLoginMiddleware logs failures instead of swallowing them; drop the
now-unused User import
- guest_login_available reads RequestContext.request, so it works without the
request context processor and under {% include ... only %}
- tests build the form action with reverse() and cover each of the above
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5
- log_in_guest(): in read-only database (demo) mode saving last_login fails after the session is set; keep the login instead of bouncing to the login page with a readonly warning and losing next (main2.0 behaviour) - get_guest_user() handles DB errors itself (logged, None); the template tag and view no longer duplicate the try/except - GuestLoginView only short-circuits staff; a logged-in non-staff account on the login page may switch to guest, so the tag needs no request at all - AutoGuestLoginMiddleware redirects to ?next as a URL (redirect() reversed it as a route name: NoReverseMatch, now logged on every hit) - styles.css rebuilt: the old button's border-transparent, text-gray-900 and group-hover:-translate-x-1 are no longer used (CI assets check) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5
… stable CSS build - GuestLoginView no longer short-circuits authenticated users: the login page renders for staff too (after a failed password POST), and login() replaces the session, so the button never just bounces back - a DatabaseError inside login() (DB-backed sessions on a read-only DB) shows 'Guest login is not available.' instead of a 500 - safe_next_url() in base/utils replaces the two copies of the next check; helpers imported at module level - read-only test swaps update_last_login by its dispatch_uid (disconnect by function was a no-op and left a duplicate receiver) - tailwind no longer scans its own output, which kept removed utilities' theme variables alive so rebuilds were not reproducible (CI assets check) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5
…n on failure - log_in_guest() keeps the login only when the error is a read-only database write after the session is set (is_readonly_db_error); any other DatabaseError (e.g. IntegrityError from a user_logged_in receiver) is re-raised and shown as 'Guest login is not available.' instead of being logged as a read-only warning - on failure the previous session is restored in memory and not saved, so a logged-in user switching to guest on a read-only DB with DB-backed sessions stays logged in instead of hitting a 500 from SessionMiddleware Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5
…ailed login - after a non-read-only DatabaseError, request.user is reset to the previous user: it stayed the guest, so with AutoGuestLoginMiddleware the admin login page redirected to /admin/ and back, forever - the restored session is saved when flush() completed (old row deleted, no key), otherwise a logged-in user with DB-backed sessions was logged out; it is still not written when the old key survived (read-only delete) - tests use the real login() with a failing user_logged_in receiver Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5
- save the restored session whenever login() changed the key: cycle_key() (anonymous user) also deletes the old row, not only flush() - getattr() for request.user in the read-only check, so a request without .user re-raises the database error instead of AttributeError Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5
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
bg-secondary-600, which is not compiled intostyles.css, so it had no background and read as plain text.guestaccount. Clicking it then did nothing:GuestLoginViewswallowed every error and bounced back to the login page with no message.Changes
secondarybutton, the same style as the other login buttons. The icon isaria-hidden. The button renders only when{% guest_login_available %}(newwn_guesttag) finds an active staffguest. Because the check lives in the template, it works on any admin site that rendersadmin/login.html.base/utils.py, used by the view,AutoGuestLoginMiddlewareand the tag:get_guest_user(): logs DB errors and returnsNone, so it never breaks the login page.log_in_guest()keeps the login in only one failure case: a read-only database (demo mode) refuses thelast_loginwrite after the session is already set (is_readonly_db_error). That is also howmain2.0behaves.DatabaseErroris re-raised.SessionMiddleware.safe_next_url(): same host and same scheme, so there is no HTTPS→HTTP redirect.GuestLoginView:login_not_required, so it works with Django'sLoginRequiredMiddleware.?next.AutoGuestLoginMiddleware:?nextas a URL.redirect()treated it as a route name, so?next=fooraisedNoReverseMatch.except: pass.styles.cssis rebuilt; the old button's three utilities are gone.Testing
GuestLoginButtonTestsandAutoGuestLoginMiddlewareTests(13 tests). Each one was checked to fail without the change it covers.SKIP_GUEST_LOGIN=Trueand withFalse.django checkis clean.bash scripts/tailwind.shtwice in a row gives a byte-identicalstyles.css.SESSION_ENGINE=dband a read-only session store:Not changed
AutoGuestLoginMiddlewareis enabled whenSKIP_GUEST_LOGIN=True. That is the opposite of what the name anddocs/GUIDE.mdsay, but changing it would affect existing projects.admin:URL namespace is hard-coded, as everywhere else in the package.🤖 Generated with Claude Code
https://claude.ai/code/session_01YXGgGiATURgjVcvhP18qJ5