06/16 Phase 6
This commit is contained in:
@@ -8,6 +8,7 @@ from app.models.enums import ListingStatus, Lang
|
||||
from app.utils.text import normalize
|
||||
from app.services.geo import geocode_zip, bounding_box, haversine_mi
|
||||
from app.services.field_schema import validate_attributes, hot_values
|
||||
from app.services.settings import get_setting
|
||||
|
||||
|
||||
class ListingError(ValueError):
|
||||
@@ -48,6 +49,15 @@ def _life_days(user):
|
||||
return _limit(user, "listing_life_days", 14)
|
||||
|
||||
|
||||
def _blocklist_hit(title, body):
|
||||
"""Accent-insensitive check against the admin-configured keyword blocklist."""
|
||||
blocklist = get_setting("keyword_blocklist", [])
|
||||
if not blocklist:
|
||||
return False
|
||||
hay = normalize(f"{title} {body}")
|
||||
return any(normalize(term) in hay for term in blocklist if term)
|
||||
|
||||
|
||||
# --- create / update ---
|
||||
def create_listing(user, category, *, title, body, lang, price_cents,
|
||||
zip_code, raw_attributes):
|
||||
@@ -71,6 +81,8 @@ def create_listing(user, category, *, title, body, lang, price_cents,
|
||||
expires_at=datetime.utcnow() + timedelta(days=_life_days(user)),
|
||||
**hot_values(cleaned),
|
||||
)
|
||||
if _blocklist_hit(title, body):
|
||||
listing.status = ListingStatus.flagged
|
||||
_apply_location(listing, zip_code)
|
||||
db.session.add(listing)
|
||||
db.session.commit()
|
||||
@@ -91,6 +103,8 @@ def update_listing(listing, category, *, title, body, lang, price_cents,
|
||||
listing.attributes = cleaned
|
||||
for col, val in hot_values(cleaned).items():
|
||||
setattr(listing, col, val)
|
||||
if listing.status == ListingStatus.active and _blocklist_hit(title, body):
|
||||
listing.status = ListingStatus.flagged
|
||||
_apply_location(listing, zip_code)
|
||||
db.session.commit()
|
||||
return listing
|
||||
|
||||
Reference in New Issue
Block a user