06/16 Phase 6 foundation: admin blueprint, audit log, user management
Adds the admin backend foundation: AuditLog + Setting models/migration, an admin-only dashboard with KPI cards, and user management (search, ban/suspend/activate, tier override, trust adjust) with audit logging on every write action. Smoke suite extended to 64 checks.
This commit is contained in:
@@ -9,8 +9,10 @@ from app.models.messaging import Conversation, Message
|
||||
from app.models.favorite import Favorite
|
||||
from app.models.payments import Subscription, Transaction, Boost
|
||||
from app.models.ads import Ad, Sponsor, PromotedKeyword
|
||||
from app.models.audit import AuditLog
|
||||
from app.models.setting import Setting
|
||||
|
||||
__all__ = ["Plan", "User", "TrustEvent", "Category", "Listing",
|
||||
"ListingImage", "ZipGeo", "Metro", "Conversation", "Message",
|
||||
"Favorite", "Subscription", "Transaction", "Boost",
|
||||
"Ad", "Sponsor", "PromotedKeyword"]
|
||||
"Ad", "Sponsor", "PromotedKeyword", "AuditLog", "Setting"]
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
"""Append-only audit trail for admin write actions."""
|
||||
from datetime import datetime
|
||||
from sqlalchemy import JSON
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class AuditLog(db.Model):
|
||||
__tablename__ = "audit_logs"
|
||||
|
||||
id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"),
|
||||
primary_key=True, autoincrement=True)
|
||||
actor_id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"),
|
||||
db.ForeignKey("users.id"), nullable=True, index=True)
|
||||
action = db.Column(db.String(60), nullable=False, index=True)
|
||||
target_type = db.Column(db.String(40), nullable=False)
|
||||
target_id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"),
|
||||
nullable=True, index=True)
|
||||
meta = db.Column(JSON, nullable=True)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
actor = db.relationship("User", backref=db.backref("audit_logs", lazy="dynamic"))
|
||||
|
||||
def __repr__(self):
|
||||
return f"<AuditLog {self.action} {self.target_type}:{self.target_id}>"
|
||||
@@ -0,0 +1,16 @@
|
||||
"""Admin-editable runtime settings (registration_open, flag_threshold, etc.)."""
|
||||
from datetime import datetime
|
||||
from sqlalchemy import JSON
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class Setting(db.Model):
|
||||
__tablename__ = "settings"
|
||||
|
||||
key = db.Column(db.String(80), primary_key=True)
|
||||
value = db.Column(JSON, nullable=True)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.utcnow,
|
||||
onupdate=datetime.utcnow, nullable=False)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Setting {self.key}>"
|
||||
Reference in New Issue
Block a user