06/16 Phase 6 (continue)

This commit is contained in:
2026-06-17 17:06:43 -04:00
parent 479afde2fa
commit 68a842d6b6
26 changed files with 1027 additions and 61 deletions
+10 -2
View File
@@ -9,7 +9,9 @@ For the *sending* side we heuristic-flag high-contact-density messages so
moderators can spot scraping attempts.
"""
import re
from datetime import datetime
from app.models.enums import TrustTier
from app.services.settings import get_setting
# patterns
_PHONE_RE = re.compile(
@@ -25,8 +27,14 @@ def contact_revealed(user) -> bool:
"""True when this user's contact info may be shown unmasked."""
if user is None:
return False
return (user.email_verified and
user.trust_tier in (TrustTier.trusted, TrustTier.verified))
if not (user.email_verified and
user.trust_tier in (TrustTier.trusted, TrustTier.verified)):
return False
gate_days = get_setting("new_user_trust_gate_days", 0)
if gate_days and user.created_at:
if (datetime.utcnow() - user.created_at).days < gate_days:
return False
return True
def mask_body(text: str, reveal: bool = False) -> str:
+3 -4
View File
@@ -14,9 +14,7 @@ from app.extensions import db
from app.models.messaging import Conversation, Message
from app.services.contact import contact_density
from app.services.email import send_email
# Bodies with ≥ 3 contact signals get auto-flagged
_FLAG_THRESHOLD = 3
from app.services.settings import get_setting
class MessagingError(ValueError):
@@ -60,7 +58,8 @@ def send_message(conversation, sender, body: str) -> Message:
if sender.id not in (conversation.buyer_id, conversation.seller_id):
raise MessagingError("not a participant")
flagged = contact_density(body) >= _FLAG_THRESHOLD
threshold = get_setting("contact_density_threshold", 3)
flagged = contact_density(body) >= threshold
msg = Message(
conversation_id=conversation.id,
+1 -1
View File
@@ -19,7 +19,7 @@ def create_report(listing, reporter, reason: ReportReason, note=None):
reason=reason, note=(note or "").strip() or None)
db.session.add(report)
try:
db.session.commit()
db.session.flush()
except IntegrityError:
db.session.rollback()
raise ReportError("you have already reported this listing")