Files
devplacepy/devplacepy/routers/devrant/notifs.py
T
retoor 99ed5c4f15 feat: add audit logging for admin trash restore/purge and notification clear actions
- Record audit events in `admin_trash_restore` and `admin_trash_purge` endpoints with target metadata
- Log `notification.read.all` event when user clears devRant notification feed
- Include `devrant` as a valid origin in audit categories
- Add `admin_section` and `pagination_query` fields to audit and backup schemas for UI consistency
2026-06-16 05:08:58 +00:00

41 lines
1.1 KiB
Python

# retoor <retoor@molodetz.nl>
import logging
from fastapi import APIRouter, Request
from devplacepy.services.devrant.params import merge_params
from devplacepy.services.devrant.tokens import resolve_user
from devplacepy.services.devrant.notifications import build_notif_feed, clear_notifications
from devplacepy.routers.devrant._shared import dr_ok, unauthorized
from devplacepy.services.audit import record as audit
logger = logging.getLogger(__name__)
router = APIRouter()
@router.get("/users/me/notif-feed")
async def notif_feed(request: Request):
params = await merge_params(request)
user = resolve_user(params)
if not user:
return unauthorized()
return dr_ok(data=build_notif_feed(user))
@router.delete("/users/me/notif-feed")
async def clear_notif_feed(request: Request):
params = await merge_params(request)
user = resolve_user(params)
if not user:
return unauthorized()
clear_notifications(user)
audit.record(
request,
"notification.read.all",
user=user,
origin="devrant",
summary=f"{user['username']} cleared all notifications",
)
return dr_ok()