feat(audit): cover operational mutations
This commit is contained in:
@@ -16,7 +16,8 @@ import (
|
||||
// AgentCapacityHandler handles AgentCapacityPolicy CRUD operations.
|
||||
// Reference: Chatwoot enterprise/app/controllers/api/v1/agent_capacity_policies_controller.rb
|
||||
type AgentCapacityHandler struct {
|
||||
svc *service.AgentCapacityPolicyService
|
||||
svc *service.AgentCapacityPolicyService
|
||||
auditSvc *service.AuditService
|
||||
}
|
||||
|
||||
// NewAgentCapacityHandler creates a new AgentCapacityPolicy handler.
|
||||
@@ -24,6 +25,11 @@ func NewAgentCapacityHandler(svc *service.AgentCapacityPolicyService) *AgentCapa
|
||||
return &AgentCapacityHandler{svc: svc}
|
||||
}
|
||||
|
||||
func (h *AgentCapacityHandler) WithAuditService(auditSvc *service.AuditService) *AgentCapacityHandler {
|
||||
h.auditSvc = auditSvc
|
||||
return h
|
||||
}
|
||||
|
||||
// List returns all agent capacity policies for an account.
|
||||
// GET /api/v1/accounts/:account_id/agent_capacity_policies
|
||||
func (h *AgentCapacityHandler) List(c *gin.Context) {
|
||||
@@ -69,6 +75,13 @@ func (h *AgentCapacityHandler) Create(c *gin.Context) {
|
||||
handleAgentCapacityError(c, err)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "AgentCapacityPolicy",
|
||||
AuditableID: policy.ID,
|
||||
Action: "create",
|
||||
AuditedChanges: serializeAgentCapacityPolicy(policy),
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, serializeAgentCapacityPolicy(policy))
|
||||
}
|
||||
@@ -125,6 +138,13 @@ func (h *AgentCapacityHandler) Update(c *gin.Context) {
|
||||
handleAgentCapacityError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "AgentCapacityPolicy",
|
||||
AuditableID: policy.ID,
|
||||
Action: "update",
|
||||
AuditedChanges: serializeAgentCapacityPolicy(policy),
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, serializeAgentCapacityPolicy(policy))
|
||||
}
|
||||
@@ -149,6 +169,13 @@ func (h *AgentCapacityHandler) Delete(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "AgentCapacityPolicy",
|
||||
AuditableID: id,
|
||||
Action: "destroy",
|
||||
AuditedChanges: gin.H{"id": id},
|
||||
})
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
@@ -174,6 +201,13 @@ func (h *AgentCapacityHandler) CreateInboxLimit(c *gin.Context) {
|
||||
handleAgentCapacityError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "InboxCapacityLimit",
|
||||
AuditableID: limit.ID,
|
||||
Action: "create",
|
||||
AuditedChanges: serializeInboxCapacityLimit(limit, false),
|
||||
})
|
||||
c.JSON(http.StatusOK, serializeInboxCapacityLimit(limit, false))
|
||||
}
|
||||
|
||||
@@ -203,6 +237,13 @@ func (h *AgentCapacityHandler) UpdateInboxLimit(c *gin.Context) {
|
||||
handleAgentCapacityError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "InboxCapacityLimit",
|
||||
AuditableID: limit.ID,
|
||||
Action: "update",
|
||||
AuditedChanges: serializeInboxCapacityLimit(limit, true),
|
||||
})
|
||||
c.JSON(http.StatusOK, serializeInboxCapacityLimit(limit, true))
|
||||
}
|
||||
|
||||
@@ -226,6 +267,13 @@ func (h *AgentCapacityHandler) DeleteInboxLimit(c *gin.Context) {
|
||||
handleAgentCapacityError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "InboxCapacityLimit",
|
||||
AuditableID: limitID,
|
||||
Action: "destroy",
|
||||
AuditedChanges: gin.H{"id": limitID, "agent_capacity_policy_id": policyID},
|
||||
})
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
@@ -273,6 +321,16 @@ func (h *AgentCapacityHandler) CreateUser(c *gin.Context) {
|
||||
handleAgentCapacityError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "AgentCapacityPolicyUser",
|
||||
AuditableID: user.ID,
|
||||
Action: "create",
|
||||
AuditedChanges: gin.H{
|
||||
"agent_capacity_policy_id": policyID,
|
||||
"user_id": user.ID,
|
||||
},
|
||||
})
|
||||
c.JSON(http.StatusOK, serializeAgentCapacityUser(user, accountID))
|
||||
}
|
||||
|
||||
@@ -296,6 +354,16 @@ func (h *AgentCapacityHandler) DeleteUser(c *gin.Context) {
|
||||
handleAgentCapacityError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "AgentCapacityPolicyUser",
|
||||
AuditableID: userID,
|
||||
Action: "destroy",
|
||||
AuditedChanges: gin.H{
|
||||
"agent_capacity_policy_id": policyID,
|
||||
"user_id": userID,
|
||||
},
|
||||
})
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user