mirror of
https://github.com/complexcaresolutions/dak.c2s.git
synced 2026-03-17 21:53:41 +00:00
Add audit_service for compliance logging, admin endpoints (user CRUD, invitation management, audit log), notification endpoints (list, mark read), and interactive create_admin script. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
31 lines
820 B
Python
31 lines
820 B
Python
"""Audit logging service -- records user actions for compliance and debugging."""
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models.audit import AuditLog
|
|
|
|
|
|
def log_action(
|
|
db: Session,
|
|
user_id: int | None,
|
|
action: str,
|
|
entity_type: str | None = None,
|
|
entity_id: int | None = None,
|
|
old_values: dict | None = None,
|
|
new_values: dict | None = None,
|
|
ip_address: str | None = None,
|
|
user_agent: str | None = None,
|
|
) -> None:
|
|
"""Persist a single audit-log entry and commit immediately."""
|
|
entry = AuditLog(
|
|
user_id=user_id,
|
|
action=action,
|
|
entity_type=entity_type,
|
|
entity_id=entity_id,
|
|
old_values=old_values,
|
|
new_values=new_values,
|
|
ip_address=ip_address,
|
|
user_agent=user_agent,
|
|
)
|
|
db.add(entry)
|
|
db.commit()
|