forked from retoor/devplacepy
Implement a new `avatar_seed` column on the users table that overrides the username-based seed for Multiavatar generation. Introduce a null-safe `avatar_seed(user)` choke point in `avatar.py` that resolves `user.get("avatar_seed") or user.get("username")`, registered as a Jinja global so every render site (`_avatar_link.html`, `avatar_url(...)` calls, SEO `og_image`, issues ad-hoc dicts, devRant payload/PNG) propagates a regenerated seed. Add `POST /profile/{username}/regenerate-avatar` endpoint (owner-or-admin only) that writes a fresh `generate_uid()` to `avatar_seed`, invalidates the target's user cache, and audits `profile.avatar.regenerate`. The previous seed is overwritten and never stored, making regeneration irreversible. Document the feature in `AGENTS.md` and `README.md`, add the API endpoint to `docs_api.py`, and include the `regenerate_avatar` Devii tool in `CONFIRM_REQUIRED`.
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
from devplacepy.services.devrant import serializers
|
|
|
|
|
|
def _rant(author):
|
|
return serializers.serialize_rant(
|
|
{
|
|
"id": 1,
|
|
"uid": "post-1",
|
|
"user_uid": "u1",
|
|
"content": "hello",
|
|
"created_at": "2026-06-20T00:00:00+00:00",
|
|
},
|
|
authors={"u1": author},
|
|
comment_counts={},
|
|
user_scores={},
|
|
my_votes={},
|
|
)
|
|
|
|
|
|
def test_rant_avatar_uses_seed_when_present():
|
|
rant = _rant({"id": 7, "username": "neo", "avatar_seed": "seed-abc"})
|
|
assert rant["user_avatar"]["i"] == "u/seed-abc.png"
|
|
assert rant["user_avatar_lg"]["i"] == "u/seed-abc.png"
|
|
|
|
|
|
def test_rant_avatar_falls_back_to_username():
|
|
rant = _rant({"id": 7, "username": "neo"})
|
|
assert rant["user_avatar"]["i"] == "u/neo.png"
|
|
|
|
|
|
def test_comment_avatar_uses_seed_when_present():
|
|
comment = serializers.serialize_comment(
|
|
{
|
|
"id": 3,
|
|
"uid": "c1",
|
|
"user_uid": "u1",
|
|
"content": "reply",
|
|
"created_at": "2026-06-20T00:00:00+00:00",
|
|
},
|
|
rant_id=1,
|
|
authors={"u1": {"id": 7, "username": "neo", "avatar_seed": "seed-abc"}},
|
|
user_scores={},
|
|
my_votes={},
|
|
score_map={},
|
|
)
|
|
assert comment["user_avatar"]["i"] == "u/seed-abc.png"
|