Description
In multi-user organizations, multiple sales agents can import leads, delete campaigns, or modify settings. Currently, there is no history log of who did what. We need to build an audit log system.
User & Contributor Value
- Contributors: Database logging model design, request middleware extraction, and audit log list APIs.
- Users: Essential security feature. Allows workspace admins to track user actions and troubleshoot modifications.
Code Locations
- backend/tenants/models.py
- backend/campaigns/views.py
Implementation Guide
- Create AuditLog Model:
class AuditLog(TenantModel):
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
action = models.CharField(max_length=255) # e.g. "Campaign launched"
target_id = models.CharField(max_length=255, null=True)
ip_address = models.GenericIPAddressField(null=True)
- Record Actions: Hook signals or add log creation lines inside view actions (create lead, delete campaign, change settings).
- Audit Log Panel: Build an audit logs view inside Settings for organization administrators.
Description
In multi-user organizations, multiple sales agents can import leads, delete campaigns, or modify settings. Currently, there is no history log of who did what. We need to build an audit log system.
User & Contributor Value
Code Locations
Implementation Guide