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:
2026-06-27 22:31:34 +00:00
parent e773067106
commit 6f340a6818
60 changed files with 1626 additions and 97 deletions
+42
View File
@@ -168,3 +168,45 @@ def _seed_feed_posts(count):
def test_missing_profile_returns_404(app_server):
r = requests.get(f"{BASE_URL}/profile/no-such-user-xyz", allow_redirects=False)
assert r.status_code == 404
def test_viewing_profile_marks_notification_read(app_server):
import time
from datetime import datetime, timezone
from devplacepy.database import get_table, refresh_snapshot
from devplacepy.utils import generate_uid
name = f"nmark{int(time.time() * 1000)}"
session = requests.Session()
session.post(
f"{BASE_URL}/auth/signup",
data={
"username": name,
"email": f"{name}@t.dev",
"password": "secret123",
"confirm_password": "secret123",
},
allow_redirects=True,
)
refresh_snapshot()
user = get_table("users").find_one(username=name)
notif_uid = generate_uid()
get_table("notifications").insert(
{
"uid": notif_uid,
"user_uid": user["uid"],
"type": "follow",
"message": "someone followed you",
"related_uid": generate_uid(),
"target_url": f"/profile/{name}",
"read": False,
"created_at": datetime.now(timezone.utc).isoformat(),
}
)
refresh_snapshot()
r = session.get(f"{BASE_URL}/profile/{name}", allow_redirects=True)
assert r.status_code == 200
refresh_snapshot()
assert bool(get_table("notifications").find_one(uid=notif_uid)["read"]) is True