feat: add per-user avatar seed regeneration with irreversible random avatar replacement
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`.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
# 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"
|
||||
Reference in New Issue
Block a user