feat(audit): cover operational mutations
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
type ConversationHandler struct {
|
||||
conversationSvc *service.ConversationService
|
||||
messageSvc *service.MessageService
|
||||
auditSvc *service.AuditService
|
||||
}
|
||||
|
||||
// NewConversationHandler creates a new ConversationHandler.
|
||||
@@ -28,6 +29,11 @@ func NewConversationHandler(conversationSvc *service.ConversationService, messag
|
||||
return &ConversationHandler{conversationSvc: conversationSvc, messageSvc: messageSvc}
|
||||
}
|
||||
|
||||
func (h *ConversationHandler) WithAuditService(auditSvc *service.AuditService) *ConversationHandler {
|
||||
h.auditSvc = auditSvc
|
||||
return h
|
||||
}
|
||||
|
||||
// @Summary List conversations for an account
|
||||
// @Description Retrieves all conversations for an account with pagination, optionally filtered by status query param
|
||||
// @Tags Conversations
|
||||
@@ -99,6 +105,13 @@ func (h *ConversationHandler) Create(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "Conversation",
|
||||
AuditableID: conversation.ID,
|
||||
Action: "update",
|
||||
AuditedChanges: gin.H{"status": conversation.Status, "priority": conversation.Priority, "sla_policy_id": conversation.SlaPolicyID},
|
||||
})
|
||||
c.JSON(http.StatusOK, serializeConversation(c.Request.Context(), h.conversationSvc.DB(), conversation))
|
||||
}
|
||||
|
||||
@@ -193,6 +206,13 @@ func (h *ConversationHandler) Delete(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "Conversation",
|
||||
AuditableID: conversation.ID,
|
||||
Action: "destroy",
|
||||
AuditedChanges: gin.H{"id": conversation.ID, "display_id": conversation.DisplayID},
|
||||
})
|
||||
response.NoContent(c)
|
||||
}
|
||||
|
||||
@@ -238,6 +258,13 @@ func (h *ConversationHandler) AssignAgent(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "Conversation",
|
||||
AuditableID: conversation.ID,
|
||||
Action: "update",
|
||||
AuditedChanges: gin.H{"assignee_id": conversation.AssigneeID},
|
||||
})
|
||||
c.JSON(http.StatusOK, serializeUserFromDB(c.Request.Context(), h.conversationSvc.DB(), req.AssigneeID, accountID))
|
||||
}
|
||||
|
||||
@@ -286,6 +313,13 @@ func (h *ConversationHandler) ToggleStatus(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "Conversation",
|
||||
AuditableID: conversation.ID,
|
||||
Action: "update",
|
||||
AuditedChanges: gin.H{"status": conversation.Status, "snoozed_until": conversation.SnoozedUntil},
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"meta": gin.H{}, "payload": gin.H{
|
||||
"success": true,
|
||||
"conversation_id": conversationDisplayID(conversation),
|
||||
|
||||
Reference in New Issue
Block a user