feat(audit): cover operational mutations

This commit is contained in:
2026-06-05 10:45:55 +08:00
parent 4597d404fd
commit 2ec5366d7c
8 changed files with 321 additions and 24 deletions
+28 -1
View File
@@ -21,7 +21,8 @@ import (
// SlaPolicyHandler handles SLA Policy CRUD + applied SLA metrics/download.
// Reference: Chatwoot app/controllers/api/v1/sla_policies_controller.rb
type SlaPolicyHandler struct {
svc *service.SlaPolicyService
svc *service.SlaPolicyService
auditSvc *service.AuditService
}
// NewSlaPolicyHandler creates a new SlaPolicy handler.
@@ -29,6 +30,11 @@ func NewSlaPolicyHandler(svc *service.SlaPolicyService) *SlaPolicyHandler {
return &SlaPolicyHandler{svc: svc}
}
func (h *SlaPolicyHandler) WithAuditService(auditSvc *service.AuditService) *SlaPolicyHandler {
h.auditSvc = auditSvc
return h
}
// Create creates a new SLA policy.
// POST /api/v1/accounts/:account_id/sla_policies
func (h *SlaPolicyHandler) Create(c *gin.Context) {
@@ -51,6 +57,13 @@ func (h *SlaPolicyHandler) Create(c *gin.Context) {
handleServiceError(c, svcErr)
return
}
recordAuditMutation(c, h.auditSvc, auditMutation{
AccountID: accountID,
AuditableType: "SlaPolicy",
AuditableID: policy.ID,
Action: "create",
AuditedChanges: serializeSlaPolicy(policy),
})
c.JSON(http.StatusOK, gin.H{"payload": serializeSlaPolicy(policy)})
}
@@ -127,6 +140,13 @@ func (h *SlaPolicyHandler) Update(c *gin.Context) {
handleServiceError(c, svcErr)
return
}
recordAuditMutation(c, h.auditSvc, auditMutation{
AccountID: accountID,
AuditableType: "SlaPolicy",
AuditableID: policy.ID,
Action: "update",
AuditedChanges: serializeSlaPolicy(policy),
})
c.JSON(http.StatusOK, gin.H{"payload": serializeSlaPolicy(policy)})
}
@@ -152,6 +172,13 @@ func (h *SlaPolicyHandler) Delete(c *gin.Context) {
handleServiceError(c, svcErr)
return
}
recordAuditMutation(c, h.auditSvc, auditMutation{
AccountID: accountID,
AuditableType: "SlaPolicy",
AuditableID: policyID,
Action: "destroy",
AuditedChanges: gin.H{"id": policyID},
})
// Chatwoot returns head :ok (200) on destroy.
c.Status(http.StatusOK)