Skip to content

Commit 8c51db5

Browse files
committed
Hide the Gravatar text on the profile page when Gravatar is off
Document SIMPLEAUDIT_GRAVATAR in both env examples.
1 parent 28d8017 commit 8c51db5

5 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎.env.dev.example‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ VISUALIZER_RESULTS_DIR=./results
4444
# VISUALIZER_MAX_TREE_DEPTH=8
4545
# VISUALIZER_MAX_FILE_SIZE_MB=100
4646

47+
# --- Gravatar avatars -----------------------------------------------------------
48+
# Off by default: the user's initial is shown. Set to "true" to load avatars
49+
# from gravatar.com (the browser sends the MD5 hash of the user's email there).
50+
# SIMPLEAUDIT_GRAVATAR=true
51+
4752
# --- Chat (Open WebUI) ----------------------------------------------------------
4853
# On by default in dev; no line needed. To force it off:
4954
# SIMPLEAUDIT_CHAT=off (env)

‎.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ SIMPLEAUDIT_STUDIO_URL=http://localhost:8000
123123
# management) on or off. ON by default (preserves existing behavior). Set to
124124
# "off" to 404 the /otlp/* and /api/otlp/* routes and hide the OTLP button.
125125
#SIMPLEAUDIT_OTLP=off
126+
# Optional: show Gravatar avatars. OFF by default (the user's initial is shown).
127+
# Set to "true" to load them from gravatar.com; the browser then sends the MD5
128+
# hash of the user's email there.
129+
#SIMPLEAUDIT_GRAVATAR=true
126130

127131
# --- Optional observability -----------------------------------------------------
128132

‎infra/context_processors.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ def gravatar_for(user) -> str | None:
2222

2323

2424
def gravatar_url(request):
25-
"""Expose the current user's Gravatar URL (or ``None``) to templates."""
26-
return {"gravatar_url": gravatar_for(getattr(request, "user", None))}
25+
"""Expose the current user's Gravatar URL (or ``None``) and the setting."""
26+
return {
27+
"gravatar_url": gravatar_for(getattr(request, "user", None)),
28+
"gravatar_enabled": settings.SIMPLEAUDIT_GRAVATAR,
29+
}
2730

2831

2932
def admin_status(request):

‎infra/tests/test_gravatar.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def test_off_by_default(self):
1717
content = self.client.get("/profile/").content.decode()
1818
self.assertNotIn("gravatar.com/avatar/", content)
1919

20+
def test_off_shows_no_gravatar_text_on_the_profile(self):
21+
content = self.client.get("/profile/").content.decode()
22+
self.assertNotIn("Add an email address to get a Gravatar avatar.", content)
23+
self.assertNotIn("Update image on Gravatar", content)
24+
2025
@override_settings(SIMPLEAUDIT_GRAVATAR=True)
2126
def test_on_renders_the_gravatar_url(self):
2227
# MD5 of the trimmed, lower-cased email "jane@x.com".

‎templates/profile.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ <h2 class="text-sm font-semibold text-gray-300 mb-4">Profile image</h2>
1818
<div class="w-16 h-16 rounded-full bg-accent/20 flex items-center justify-center text-xl font-bold text-accent">{{ profile_user.username|first|upper }}</div>
1919
{% endif %}
2020
<div class="text-sm">
21+
{% if gravatar_enabled %}
2122
<p class="text-gray-400">
2223
{% if gravatar_url %}
2324
Your avatar comes from <a href="https://gravatar.com" target="_blank" rel="noopener" class="text-accent hover:underline">Gravatar</a>, matched to your email.
@@ -29,6 +30,7 @@ <h2 class="text-sm font-semibold text-gray-300 mb-4">Profile image</h2>
2930
class="inline-block mt-2 px-3 py-1.5 rounded-lg text-xs bg-surface-overlay border border-gray-700 text-gray-200 hover:border-accent/40 transition-colors">
3031
Update image on Gravatar ↗
3132
</a>
33+
{% endif %}
3234
</div>
3335
</div>
3436
</div>

0 commit comments

Comments
 (0)