Files
classifieds/app/models/audit.py
T
nngo 2e9025fe55 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.
2026-06-16 11:45:00 -04:00

25 lines
1.0 KiB
Python

"""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}>"