06/15 Phase 1 + 2 codes

This commit is contained in:
2026-06-15 11:23:05 -04:00
commit c2064b84b4
62 changed files with 2937 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
"""Trust scoring. Append events, recompute score + tier.
Phase 1 wiring: email verification grants trust. Listing-survival and flag
penalties hook in during Phase 2/3. Thresholds are intentionally simple here.
"""
from app.extensions import db
from app.models.trust import TrustEvent
from app.models.enums import TrustEventType, TrustTier
# tier thresholds by cumulative score
_TIER_THRESHOLDS = [
(50, TrustTier.verified),
(20, TrustTier.trusted),
(5, TrustTier.basic),
(0, TrustTier.new),
]
def record_event(user, event_type: TrustEventType, delta: int):
"""Append a trust event, bump score, recompute tier. Caller commits."""
db.session.add(TrustEvent(user_id=user.id, type=event_type, delta=delta))
user.trust_score = max(0, (user.trust_score or 0) + delta)
user.trust_tier = _tier_for(user.trust_score)
return user
def _tier_for(score: int) -> TrustTier:
for threshold, tier in _TIER_THRESHOLDS:
if score >= threshold:
return tier
return TrustTier.new