feat(api): 审计查询支持按结果筛选

- AuditFilter 增加 Result 字段,Query 按 result 精确过滤
- GET /audit 接口解析 result 查询参数(success/failed)
This commit is contained in:
2026-08-30 17:27:49 +08:00
parent 13c21dfd7e
commit 7340a3dd48
2 changed files with 5 additions and 0 deletions
+1
View File
@@ -53,6 +53,7 @@ func (h *AuditHandler) List(c *gin.Context) {
Action: c.Query("action"),
ResourceType: c.Query("resource_type"),
ResourceID: c.Query("resource_id"),
Result: c.Query("result"),
Since: since,
Until: until,
Page: page,
+4
View File
@@ -53,6 +53,7 @@ type AuditFilter struct {
Action string // 动作精确匹配
ResourceType string // 资源类型(user / ssh_key / approval ...
ResourceID string // 资源 ID
Result string // 结果(success / failed
Since *time.Time // 起始时间(含)
Until *time.Time // 结束时间(含)
Page int
@@ -74,6 +75,9 @@ func (s *AuditService) Query(ctx context.Context, f AuditFilter) ([]model.AuditL
if f.ResourceID != "" {
q = q.Where("resource_id = ?", f.ResourceID)
}
if f.Result != "" {
q = q.Where("result = ?", f.Result)
}
if f.Since != nil {
q = q.Where("created_at >= ?", *f.Since)
}