06/16 Phase 6
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""Admin listing moderation: flag queue + approve/hide/remove actions.
|
||||
|
||||
Each action mutates the listing + calls audit.log_action; caller commits
|
||||
(mirrors services/admin_users.py).
|
||||
"""
|
||||
from app.extensions import db
|
||||
from app.models.listing import Listing
|
||||
from app.models.enums import ListingStatus
|
||||
from app.services import audit
|
||||
|
||||
# A listing is in the moderation queue if it's already flagged, or it's
|
||||
# still active but has accumulated reports below the auto-flag threshold.
|
||||
QUEUE_FILTER = db.or_(
|
||||
Listing.status == ListingStatus.flagged,
|
||||
db.and_(Listing.status == ListingStatus.active, Listing.flag_count > 0),
|
||||
)
|
||||
|
||||
|
||||
def flag_queue(*, page=1, per_page=25):
|
||||
return (Listing.query.filter(QUEUE_FILTER)
|
||||
.order_by(Listing.flag_count.desc(), Listing.updated_at.desc())
|
||||
.paginate(page=page, per_page=per_page, error_out=False))
|
||||
|
||||
|
||||
def approve(listing, *, actor):
|
||||
"""Clear flags, restore to active. Caller commits."""
|
||||
old = listing.flag_count
|
||||
listing.status = ListingStatus.active
|
||||
listing.flag_count = 0
|
||||
audit.log_action(actor, "listing.approved", "listing", listing.id,
|
||||
meta={"cleared_flags": old})
|
||||
|
||||
|
||||
def hide(listing, *, actor):
|
||||
"""Manually flag for review without removing. Caller commits."""
|
||||
listing.status = ListingStatus.flagged
|
||||
audit.log_action(actor, "listing.hidden", "listing", listing.id)
|
||||
|
||||
|
||||
def remove(listing, *, actor):
|
||||
"""Permanently remove from the marketplace (status flip, not a hard delete). Caller commits."""
|
||||
listing.status = ListingStatus.removed
|
||||
audit.log_action(actor, "listing.removed", "listing", listing.id)
|
||||
Reference in New Issue
Block a user