feat(audit): record enterprise mutations
This commit is contained in:
@@ -14,7 +14,8 @@ import (
|
||||
// CustomRoleHandler handles CustomRole CRUD operations.
|
||||
// Reference: Chatwoot enterprise/app/controllers/api/v1/custom_roles_controller.rb
|
||||
type CustomRoleHandler struct {
|
||||
svc *service.CustomRoleService
|
||||
svc *service.CustomRoleService
|
||||
auditSvc *service.AuditService
|
||||
}
|
||||
|
||||
// NewCustomRoleHandler creates a new CustomRole handler.
|
||||
@@ -22,6 +23,11 @@ func NewCustomRoleHandler(svc *service.CustomRoleService) *CustomRoleHandler {
|
||||
return &CustomRoleHandler{svc: svc}
|
||||
}
|
||||
|
||||
func (h *CustomRoleHandler) WithAuditService(auditSvc *service.AuditService) *CustomRoleHandler {
|
||||
h.auditSvc = auditSvc
|
||||
return h
|
||||
}
|
||||
|
||||
// List returns all custom roles for an account.
|
||||
// GET /api/v1/accounts/:account_id/custom_roles
|
||||
func (h *CustomRoleHandler) List(c *gin.Context) {
|
||||
@@ -66,6 +72,13 @@ func (h *CustomRoleHandler) Create(c *gin.Context) {
|
||||
handleServiceError(c, err)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "CustomRole",
|
||||
AuditableID: role.ID,
|
||||
Action: "create",
|
||||
AuditedChanges: role,
|
||||
})
|
||||
|
||||
response.Created(c, role)
|
||||
}
|
||||
@@ -125,6 +138,13 @@ func (h *CustomRoleHandler) Update(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "CustomRole",
|
||||
AuditableID: role.ID,
|
||||
Action: "update",
|
||||
AuditedChanges: role,
|
||||
})
|
||||
|
||||
response.OK(c, role)
|
||||
}
|
||||
@@ -149,6 +169,13 @@ func (h *CustomRoleHandler) Delete(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "CustomRole",
|
||||
AuditableID: id,
|
||||
Action: "destroy",
|
||||
AuditedChanges: gin.H{"id": id},
|
||||
})
|
||||
|
||||
response.NoContent(c)
|
||||
}
|
||||
@@ -163,4 +190,4 @@ func RegisterCustomRoleRoutes(rg *gin.RouterGroup, h *CustomRoleHandler) {
|
||||
customRoles.PUT("/:id", h.Update)
|
||||
customRoles.DELETE("/:id", h.Delete)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user