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:
@@ -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}>"
|
||||
Reference in New Issue
Block a user