refactor(core): the core's owner filters go through userscope, each held by a second account

Tokens, notifications, quota, debug sessions and the reset-link burn filtered
their owner inline. Ten of the fifteen filters had no test that noticed one
going missing; each now has a test where another account's rows must not
count, show or change.
This commit is contained in:
2026-10-19 23:36:01 +02:00
parent 531eb2eef1
commit ad6ccbac05
11 changed files with 164 additions and 15 deletions
+2 -1
View File
@@ -9,6 +9,7 @@ table can't grow without bound for a heavy user.
from sqlalchemy import delete, select
from sqlalchemy.orm import Session
from app.userscope import owned_by
from app.models import Notification
# Keep at most this many READ notifications per user; older read ones are pruned. Unread
@@ -52,7 +53,7 @@ def trim_read(db: Session, user_id: int, cap: int = READ_SOFT_CAP) -> int:
ids = (
db.execute(
select(Notification.id)
.where(Notification.user_id == user_id, Notification.read.is_(True))
.where(owned_by(Notification.user_id, user_id), Notification.read.is_(True))
.order_by(Notification.created_at.desc())
.offset(cap)
)