fix: 初验针对修改
This commit is contained in:
@@ -24,6 +24,7 @@ type Record struct {
|
||||
ActorID string `json:"actor_id,omitempty"`
|
||||
ActorName string `json:"actor_name,omitempty"`
|
||||
Action string `json:"action,omitempty"`
|
||||
LogCategory string `json:"log_category,omitempty"`
|
||||
ObjectType string `json:"object_type,omitempty"`
|
||||
ObjectID string `json:"object_id,omitempty"`
|
||||
OperationRisk string `json:"operation_risk,omitempty"`
|
||||
@@ -61,12 +62,20 @@ func NormalizeRecord(record Record) Record {
|
||||
record.ActorID = strings.TrimSpace(record.ActorID)
|
||||
record.ActorName = strings.TrimSpace(record.ActorName)
|
||||
record.Action = strings.TrimSpace(record.Action)
|
||||
record.LogCategory = strings.TrimSpace(strings.ToLower(record.LogCategory))
|
||||
record.ObjectType = strings.TrimSpace(record.ObjectType)
|
||||
record.ObjectID = strings.TrimSpace(record.ObjectID)
|
||||
record.OperationRisk = strings.TrimSpace(strings.ToLower(record.OperationRisk))
|
||||
record.ApprovalID = strings.TrimSpace(record.ApprovalID)
|
||||
record.RequestMethod = strings.TrimSpace(strings.ToUpper(record.RequestMethod))
|
||||
record.RequestPath = strings.TrimSpace(record.RequestPath)
|
||||
if record.LogCategory == "" {
|
||||
if record.RequestMethod == "GET" || record.RequestMethod == "HEAD" {
|
||||
record.LogCategory = "data"
|
||||
} else {
|
||||
record.LogCategory = "operation"
|
||||
}
|
||||
}
|
||||
record.ClientIP = strings.TrimSpace(record.ClientIP)
|
||||
record.Result = strings.TrimSpace(record.Result)
|
||||
if record.Result == "" {
|
||||
@@ -99,6 +108,9 @@ func ValidateRecord(record Record) error {
|
||||
if record.ObjectID == "" {
|
||||
return errors.New("object_id is required")
|
||||
}
|
||||
if record.LogCategory != "operation" && record.LogCategory != "data" {
|
||||
return errors.New("log_category must be operation or data")
|
||||
}
|
||||
if record.OperationRisk != RiskNormal && record.OperationRisk != RiskDangerous {
|
||||
return errors.New("operation_risk must be normal or dangerous")
|
||||
}
|
||||
@@ -139,6 +151,7 @@ func SaveRecord(record Record) (models.AuditLog, error) {
|
||||
ActorID: record.ActorID,
|
||||
ActorName: record.ActorName,
|
||||
Action: record.Action,
|
||||
LogCategory: record.LogCategory,
|
||||
ObjectType: record.ObjectType,
|
||||
ObjectID: record.ObjectID,
|
||||
OperationRisk: record.OperationRisk,
|
||||
|
||||
@@ -25,6 +25,13 @@ func ListAuditLogs(ctx *gin.Context) {
|
||||
if v := strings.TrimSpace(ctx.Query("action")); v != "" {
|
||||
q = q.Where("action = ?", v)
|
||||
}
|
||||
if v := strings.TrimSpace(ctx.Query("log_category")); v != "" {
|
||||
if v != "operation" && v != "data" {
|
||||
infra.Response.Error(ctx, fmt.Errorf("log_category 参数无效"))
|
||||
return
|
||||
}
|
||||
q = q.Where("log_category = ?", v)
|
||||
}
|
||||
if v := strings.TrimSpace(ctx.Query("object_type")); v != "" {
|
||||
q = q.Where("object_type = ?", v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user