fix: Header shows Admin when logged in (v2.3.2)
Public pages never checked the session, so they always showed Log in. Set g.me in before_request when a session cookie is present. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2616ef5060
commit
c080975f4e
4 files changed
+37
-2
No files matched your search
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [2.3.2] - 2026-10-31
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Header link reads "Admin" (was "Dashboard") when logged in
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Public pages never knew you were logged in (only `/admin` routes checked the session), so the header always said "Log in"
|
||||||
|
|
||||||
## [2.3.1] - 2026-10-31
|
## [2.3.1] - 2026-10-31
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
+16
-1
@@ -280,6 +280,21 @@ def create_app(config=None):
|
|||||||
"""Add correlation ID to request context for tracing"""
|
"""Add correlation ID to request context for tracing"""
|
||||||
add_correlation_id()
|
add_correlation_id()
|
||||||
|
|
||||||
|
# Know who is logged in on every page, not just /admin (v2.3.2), so
|
||||||
|
# the header can say "Admin" instead of "Log in". Only requests that
|
||||||
|
# carry a session cookie touch the database.
|
||||||
|
from flask import g, request
|
||||||
|
token = request.cookies.get("starpunk_session")
|
||||||
|
if token:
|
||||||
|
from starpunk.auth import verify_session
|
||||||
|
try:
|
||||||
|
info = verify_session(token)
|
||||||
|
except Exception:
|
||||||
|
info = None
|
||||||
|
if info:
|
||||||
|
g.user = info
|
||||||
|
g.me = info["me"]
|
||||||
|
|
||||||
# Response middleware - Add webmention Link header (v1.6.0)
|
# Response middleware - Add webmention Link header (v1.6.0)
|
||||||
@app.after_request
|
@app.after_request
|
||||||
def add_webmention_headers(response):
|
def add_webmention_headers(response):
|
||||||
@@ -449,5 +464,5 @@ def create_app(config=None):
|
|||||||
|
|
||||||
# Package version (Semantic Versioning 2.0.0)
|
# Package version (Semantic Versioning 2.0.0)
|
||||||
# See docs/standards/versioning-strategy.md for details
|
# See docs/standards/versioning-strategy.md for details
|
||||||
__version__ = "2.3.1"
|
__version__ = "2.3.2"
|
||||||
__version_info__ = (2, 1, 0)
|
__version_info__ = (2, 1, 0)
|
||||||
+1
-1
@@ -40,7 +40,7 @@
|
|||||||
<a href="/">Home</a>
|
<a href="/">Home</a>
|
||||||
<a href="{{ url_for('public.feed') }}">RSS</a>
|
<a href="{{ url_for('public.feed') }}">RSS</a>
|
||||||
{% if g.me %}
|
{% if g.me %}
|
||||||
<a href="{{ url_for('admin.dashboard') }}">Dashboard</a>
|
<a href="{{ url_for('admin.dashboard') }}">Admin</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ url_for('auth.login_form') }}">Log in</a>
|
<a href="{{ url_for('auth.login_form') }}">Log in</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -57,3 +57,13 @@ def test_note_page_meta_line(app):
|
|||||||
html = app.test_client().get(f"/note/{note.slug}").data.decode()
|
html = app.test_client().get(f"/note/{note.slug}").data.decode()
|
||||||
assert "<title>Hello · My Notes</title>" in html
|
assert "<title>Hello · My Notes</title>" in html
|
||||||
assert 'class="u-url u-uid"' in html
|
assert 'class="u-url u-uid"' in html
|
||||||
|
|
||||||
|
|
||||||
|
def test_nav_shows_admin_when_logged_in(app):
|
||||||
|
from starpunk.auth import create_session
|
||||||
|
client = app.test_client()
|
||||||
|
with app.test_request_context():
|
||||||
|
client.set_cookie("starpunk_session", create_session("https://example.com"))
|
||||||
|
nav = client.get("/").data.decode().split('class="site-nav"', 1)[1].split("</nav>", 1)[0]
|
||||||
|
assert ">Admin</a>" in nav
|
||||||
|
assert "/auth/login" not in nav
|
||||||
Reference in new issue
Block a user