diff --git a/README.md b/README.md index 63643df..237be8a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ Halo 2.x **操作审计插件**:回答"**谁、在什么时候、对什么资 | 能力 | 说明 | |---|---| | 自动捕获 | 已登录用户对 `/apis/**` 的 POST/PUT/DELETE/PATCH,另捕获 `/login`、`/logout`(含登录失败) | -| Console 查看页 | 列表 + 七维筛选(操作者 / 资源类型 / 动作 / 结果 / 时间区间 / 关键字)+ 分页 + 只读详情抽屉(含原始 JSON) | +| 语义动作标注 | 捕获时标注语义动作键(登录/发布/恢复…),支持按其筛选;中文操作描述贯穿列表、详情与导出 | +| Console 查看页 | 列表 + 八维筛选(操作者 / 资源类型 / 动作 / 语义动作 / 结果 / 时间区间 / 关键字)+ 分页 + 只读详情抽屉(含原始 JSON) | | 导出 CSV | 按当前筛选条件一键导出全部记录(后端全量流式生成 UTF-8 BOM CSV,Excel/WPS 直开不乱码) | | 保留与清理 | 可配置保留天数(7 ~ ∞,默认 90),每日凌晨自动清理过期记录 | | 权限 | 默认仅超级管理员可见;附带只读角色模板 `role-template-audit-view`(verbs 仅 `get`/`list`) | diff --git a/docs/operation-audit-design.md b/docs/operation-audit-design.md index 4dad835..455cbb8 100644 --- a/docs/operation-audit-design.md +++ b/docs/operation-audit-design.md @@ -39,6 +39,7 @@ Halo 博客后台缺少操作追溯能力:文章被改、设置被动、评论 | 时间 | 操作发生时间 | | 操作者 | 用户名(登录失败暂记"未知用户") | | 动作 | HTTP 方法 | +| 语义动作 | 捕获时由方法与路径推导的语义动作键(如 `publish`),支持按其筛选 | | 资源 | 从路径解析出的资源类型与名称(如 `Posts/xxx`) | | 路径 | 完整请求路径 | | 结果 | 响应状态码(成功/失败) | @@ -48,8 +49,8 @@ Halo 博客后台缺少操作追溯能力:文章被改、设置被动、评论 Console 左侧菜单新增"操作审计"页: -- 列表:时间、操作者、动作、资源、结果、IP,索引分页查询 -- 筛选:按操作者、资源类型、动作、结果、时间范围;关键字可模糊匹配资源名称/路径 +- 列表:时间、操作者、动作、资源、描述、结果、IP,索引分页查询 +- 筛选:按操作者、资源类型、动作、语义动作、结果、时间范围;关键字可模糊匹配资源名称/路径 - 详情:单条记录完整字段 - 只读:不提供任何删除/修改入口 @@ -69,14 +70,14 @@ Console 左侧菜单新增"操作审计"页: 审计日志作为 Halo 自定义模型(Extension)存储,注册后自动获得存储与查询 API。 - 模型:`AuditLog`(group 用自有域名反写,如 `audit.<你的域名>`) -- 索引:操作者、资源类型、动作、结果、创建时间(支撑筛选与分页,避免内存分页);另含资源名称、完整路径两个索引,支撑关键字模糊筛选(4.2) +- 索引:操作者、资源类型、动作、语义动作、结果、创建时间(支撑筛选与分页,避免内存分页);另含资源名称、完整路径两个索引,支撑关键字模糊筛选(4.2) - 存储由 Halo 统一管理 ## 6. 非目标(V2+ 展望) | 功能 | 说明 | 阶段 | |---|---|---| -| 语义动作标注 | 区分"发布/编辑/恢复"等中文动作 | V2 | +| 语义动作标注 | 区分"发布/编辑/恢复"等中文动作:捕获时由方法/路径推导语义动作键落库(`spec.action`,含索引),Console 按语义动作筛选,中文操作描述贯穿列表、详情与导出 CSV | V2 已实现 | | 字段级变更 diff | 记录改了什么(需缓存请求体) | V2 | | 系统内部变更 | 定时发布等非 HTTP 触发的变更,执行者记"system" | V2 | | 导出 CSV | 按筛选条件导出(后端全量流式生成 UTF-8 BOM CSV,Console 页一键下载) | V2 已实现 | @@ -87,6 +88,7 @@ Console 左侧菜单新增"操作审计"页: - 登录失败时无法得知尝试的用户名(解析请求体留到 V2) - 系统内部触发的资源变更(如定时发布)暂不记录 +- 按语义动作筛选仅覆盖标注落库后的记录:升级前写入的历史记录可正常展示(描述现场推导),但不会被语义动作筛选命中 - 超级管理员技术上仍可通过 API 删除审计记录(产品上不提供入口) - 审计写入失败静默降级为运行日志,不阻塞业务操作 diff --git a/docs/operation-audit-tech-design.md b/docs/operation-audit-tech-design.md index 9dff2d3..f558f61 100644 --- a/docs/operation-audit-tech-design.md +++ b/docs/operation-audit-tech-design.md @@ -106,6 +106,7 @@ public class AuditLog extends AbstractExtension { | `spec.username` | 按操作者筛选 | | `spec.resourceType` | 按资源类型筛选 | | `spec.method` | 按动作筛选(POST/PUT/DELETE/PATCH) | +| `spec.action` | 按语义动作筛选(语义动作标注,捕获时由 method/path 推导落库,如 publish/restore) | | `spec.statusCode` | 按结果筛选 | ### D4 权限:只读 verbs 收紧 @@ -165,7 +166,7 @@ public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { | 更深层子资源 | 取前两段,完整路径由 `path` 字段兜底 | | `/login`、`/logout` | `resourceType = "auth"` | -例:`/apis/api.content.halo.run/v1alpha1/posts/xyz` → `Posts / xyz`。完整性靠 `path` 字段保证,语义化标注留待 V2。 +例:`/apis/api.content.halo.run/v1alpha1/posts/xyz` → `Posts / xyz`。完整性靠 `path` 字段保证;语义化标注已按 V2 规划实现——捕获时由 method/path 推导语义动作键落库(`spec.action`,`OperationDescription.actionOf`,与前端 `deriveAction` 同一套映射规则),展示描述(`describe`)与语义动作键共用同一推导,历史记录无标注时现场推导不受影响。 ### 5.3 查询链路 diff --git a/plugin-operation-audit/README.md b/plugin-operation-audit/README.md index 0eaf27e..876e1c6 100644 --- a/plugin-operation-audit/README.md +++ b/plugin-operation-audit/README.md @@ -10,8 +10,11 @@ Halo 2.x 操作审计插件:回答"**谁、在什么时候、对什么资源 - **操作记录**:已登录用户对后台 API(`/apis/**`)的全部写操作(POST/PUT/DELETE/PATCH), 一条通用规则覆盖文章、页面、评论、用户、设置、主题、插件启停、附件等所有管理面操作; 另捕获 `/login`、`/logout`(登录成功/失败/登出)。 -- **审计日志查看**:Console 左侧菜单"操作审计"——列表 + 七维筛选(操作者/资源类型/动作/结果/ - 时间区间/关键字)+ 分页 + 只读详情抽屉(含原始 JSON)。不提供任何删除/修改入口。 +- **语义动作标注**:捕获时由方法/路径推导语义动作键落库(`spec.action`,如 + 登录/新建/修改/删除/发布/恢复/启用),注册索引后支持按语义动作筛选; + 中文操作描述由同一套推导生成,贯穿列表、详情与导出 CSV,历史记录同样适用。 +- **审计日志查看**:Console 左侧菜单"操作审计"——列表 + 八维筛选(操作者/资源类型/动作/ + 语义动作/结果/时间区间/关键字)+ 分页 + 只读详情抽屉(含原始 JSON)。不提供任何删除/修改入口。 - **导出 CSV**:列表页「导出」按钮按当前筛选条件导出全部记录——后端全量流式生成 (UTF-8 BOM + `\r\n`,Excel/WPS 双击打开中文不乱码),列与界面一致(操作时间、操作者、 动作、资源类型、资源名称、路径、操作描述、结果、状态码、来源 IP、User-Agent), @@ -57,6 +60,8 @@ Console「插件 → 操作审计 → 设置」: - 登录失败时无法得知尝试的用户名(解析请求体留到 V2),记为"未知用户"。 - 系统内部触发的资源变更(如定时发布)暂不记录。 +- 按语义动作筛选仅覆盖标注落库后的记录:升级前写入的历史记录可正常展示(描述现场推导), + 但不会被语义动作筛选命中。 - 超级管理员技术上仍可通过 API 删除审计记录(产品上不提供入口;角色模板已对普通授权 角色收紧到 `get`/`list`)。 - 审计写入失败静默降级为运行日志,不阻塞业务操作。 @@ -75,9 +80,10 @@ Console「插件 → 操作审计 → 设置」: 遍历全量,流式输出 CSV——升序保证导出期间并发写入不打乱分页边界。 - 定时清理采用 Reactor 调度方案(技术方案风险项 #3 预案),不依赖 `@Scheduled` 在插件上下文的可用性。 -- 关于测试:`./gradlew test`(当前 71 个用例)覆盖捕获规则、资源解析、快照、直写降级、 +- 关于测试:`./gradlew test`(当前 81 个用例)覆盖捕获规则、资源解析、快照、直写降级、 过滤器行为、查询端点参数校验、导出 CSV(BOM/表头/转义/注入防护/分批取数)、 - 操作描述推导(与前端 describeOperation 用例一一对应)、设置缓存与保留期清理;Console UI 以 vitest 断言 + 操作描述与语义动作标注推导(与前端 describeOperation / deriveAction 用例一一对应)、 + 设置缓存与保留期清理;Console UI 以 vitest 断言 路由注册形态(必须挂在 `Root` 布局路由下,否则页面会全屏渲染)+ 类型检查 + 构建通过为准 (技术方案 §7,MVP 不引入组件测试)。 diff --git a/plugin-operation-audit/src/main/java/run/halo/operationaudit/OperationAuditPlugin.java b/plugin-operation-audit/src/main/java/run/halo/operationaudit/OperationAuditPlugin.java index 036bf9e..2f6fcb4 100644 --- a/plugin-operation-audit/src/main/java/run/halo/operationaudit/OperationAuditPlugin.java +++ b/plugin-operation-audit/src/main/java/run/halo/operationaudit/OperationAuditPlugin.java @@ -15,8 +15,8 @@ import run.halo.app.plugin.PluginContext; * *

负责插件生命周期: *

*/ @@ -39,6 +39,7 @@ public class OperationAuditPlugin extends BasePlugin { addIndex(indexSpecs, "spec.username", String.class, log -> log.getSpec().getUsername()); addIndex(indexSpecs, "spec.resourceType", String.class, log -> log.getSpec().getResourceType()); addIndex(indexSpecs, "spec.method", String.class, log -> log.getSpec().getMethod()); + addIndex(indexSpecs, "spec.action", String.class, log -> log.getSpec().getAction()); addIndex(indexSpecs, "spec.statusCode", Integer.class, log -> log.getSpec().getStatusCode()); addIndex(indexSpecs, "spec.resourceName", String.class, log -> log.getSpec().getResourceName()); addIndex(indexSpecs, "spec.path", String.class, log -> log.getSpec().getPath()); diff --git a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditLogFilters.java b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditLogFilters.java index 8d14521..a320080 100644 --- a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditLogFilters.java +++ b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditLogFilters.java @@ -22,8 +22,8 @@ import run.halo.app.extension.index.query.Queries; final class AuditLogFilters { /** fieldSelector 支持等值筛选的字段白名单(与已注册索引一一对应)。 */ - static final Set FILTERABLE_FIELDS = - Set.of("spec.username", "spec.resourceType", "spec.method", "spec.statusCode"); + static final Set FILTERABLE_FIELDS = Set.of("spec.username", "spec.resourceType", + "spec.method", "spec.action", "spec.statusCode"); private AuditLogFilters() { } diff --git a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditLogSpec.java b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditLogSpec.java index 2ad63ce..6f14f48 100644 --- a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditLogSpec.java +++ b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditLogSpec.java @@ -16,6 +16,13 @@ public class AuditLogSpec { /** HTTP 方法(动作),如 POST/PUT/DELETE/PATCH。 */ private String method; + /** + * 语义动作键(语义动作标注,产品设计 V2):捕获时由 method/path 推导落库 + * (如 login/logout/create/update/delete/publish/restore),注册索引后支持 + * 按语义动作筛选。升级前写入的历史记录无此字段,展示不受影响(现场推导)。 + */ + private String action; + /** 资源类型(复数形式,如 posts/comments/users/auth)。 */ private String resourceType; diff --git a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditQueryEndpoint.java b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditQueryEndpoint.java index fa947c8..7a15268 100644 --- a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditQueryEndpoint.java +++ b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditQueryEndpoint.java @@ -48,8 +48,8 @@ public class AuditQueryEndpoint implements CustomEndpoint { return org.springdoc.webflux.core.fn.SpringdocRouteBuilder.route() .GET("auditlogs/-/query", this::query, builder -> builder .operationId("ListAuditLogs") - .description("分页查询审计日志:支持等值筛选(fieldSelector)、" - + "关键字(resourceName/path 模糊)、结果(success/failure)、" + .description("分页查询审计日志:支持等值筛选(fieldSelector,含 spec.action " + + "语义动作)、关键字(resourceName/path 模糊)、结果(success/failure)、" + "时间区间(含边界)") .build()) .GET("auditlogs/-/export", this::export, builder -> builder diff --git a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditRecorder.java b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditRecorder.java index 85a17aa..aaef87c 100644 --- a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditRecorder.java +++ b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/AuditRecorder.java @@ -69,6 +69,9 @@ public class AuditRecorder { spec.setUsername(username != null ? username : AuditLogSpec.UNKNOWN_USERNAME); spec.setMethod(snapshot.getMethod()); spec.setResourceType(resolved.resourceType()); + // 语义动作标注(产品设计 V2):捕获时推导落库,供按语义动作筛选 + spec.setAction(OperationDescription.actionOf( + snapshot.getMethod(), resolved.resourceType(), snapshot.getPath())); spec.setResourceName(resolved.optionalName().orElse(null)); spec.setPath(snapshot.getFullPath()); spec.setStatusCode(statusCode); diff --git a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/OperationDescription.java b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/OperationDescription.java index 4b0ced2..4fc80cb 100644 --- a/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/OperationDescription.java +++ b/plugin-operation-audit/src/main/java/run/halo/operationaudit/audit/OperationDescription.java @@ -7,11 +7,15 @@ import java.util.Map; * 操作描述(这条操作真正干了什么):由 method / resourceType / path 推导中文短语, * 如 登录、登出、新建用户、修改文章、发布文章、启用插件、修改密码。 * - *

与前端 {@code ui/src/utils/audit.ts} 的 {@code describeOperation} 保持一致 - * (同一套 RESOURCE_LABELS / METHOD_VERBS / SUB_ACTION_VERBS / SUB_ACTION_PHRASES - * 映射与子动作解析规则),两处需同步修改。推导纯用于展示/导出,不落库: - * 历史记录同样适用;未识别的子动作回退为「动词 + 资源名」, - * 未识别的资源类型直接使用原始 resourceType。 + *

语义动作标注(产品设计 V2):捕获时由 {@link #actionOf} 推导语义动作键落库 + * ({@code spec.action},如 login/create/publish,可空),注册索引后支持按语义动作筛选; + * 展示/导出由 {@link #describe} 推导中文短语,历史记录(无 action 字段)同样按 + * method/path 现场推导,不受影响。 + * + *

与前端 {@code ui/src/utils/audit.ts} 的 {@code deriveAction} / {@code describeOperation} + * 保持一致(同一套 RESOURCE_LABELS / METHOD_ACTIONS / SEGMENT_ACTIONS / ACTION_PHRASES / + * ACTION_VERBS 映射与子动作解析规则),两处需同步修改。未识别的子动作回退为 + * 「method 动词 + 资源名」,未识别的资源类型直接使用原始 resourceType。 */ final class OperationDescription { @@ -32,19 +36,48 @@ final class OperationDescription { Map.entry("categories", "分类"), Map.entry("tags", "标签")); - /** 动作方法的基础动词(未知方法回退原始值)。 */ - private static final Map METHOD_VERBS = Map.of( - "POST", "新建", - "PUT", "修改", - "PATCH", "修改", - "DELETE", "删除", - "GET", "查看"); + /** 动作方法 → 语义动作键(未知方法无键)。 */ + private static final Map METHOD_ACTIONS = Map.of( + "POST", "create", + "PUT", "update", + "PATCH", "update", + "DELETE", "delete", + "GET", "view"); /** - * 子资源动作段({@code /apis/.../{plural}/{name}/{action}} 的 action)→ 动词, - * 与资源名拼接成短语,如 publish + 文章 = 发布文章。 + * 子资源动作段({@code /apis/.../{plural}/{name}/{action}} 的 action)→ 语义动作键。 + * activation 与 enable 语义相同(激活/启用),归并为同一动作键便于统一筛选。 */ - private static final Map SUB_ACTION_VERBS = Map.ofEntries( + private static final Map SEGMENT_ACTIONS = Map.ofEntries( + Map.entry("publish", "publish"), + Map.entry("unpublish", "unpublish"), + Map.entry("recycle", "recycle"), + Map.entry("restore", "restore"), + Map.entry("enable", "enable"), + Map.entry("activation", "enable"), + Map.entry("disable", "disable"), + Map.entry("upgrade", "upgrade"), + Map.entry("uninstall", "uninstall"), + Map.entry("reload", "reload"), + Map.entry("reply", "reply"), + Map.entry("recalculate", "recalculate"), + Map.entry("password", "password"), + Map.entry("resetpassword", "resetpassword")); + + /** 语义动作键 → 完整短语(不拼接资源名)。 */ + private static final Map ACTION_PHRASES = Map.ofEntries( + Map.entry("login", "登录"), + Map.entry("logout", "登出"), + Map.entry("auth", "认证操作"), + Map.entry("password", "修改密码"), + Map.entry("resetpassword", "重置密码")); + + /** 语义动作键 → 动词(与资源中文名拼接成短语,如 publish + 文章 = 发布文章)。 */ + private static final Map ACTION_VERBS = Map.ofEntries( + Map.entry("create", "新建"), + Map.entry("update", "修改"), + Map.entry("delete", "删除"), + Map.entry("view", "查看"), Map.entry("publish", "发布"), Map.entry("unpublish", "取消发布"), Map.entry("recycle", "移入回收站"), @@ -54,51 +87,70 @@ final class OperationDescription { Map.entry("upgrade", "升级"), Map.entry("uninstall", "卸载"), Map.entry("reload", "重载"), - Map.entry("activation", "启用"), Map.entry("reply", "回复"), Map.entry("recalculate", "重新统计")); - /** 子资源动作段 → 完整短语(不拼接资源名)。 */ - private static final Map SUB_ACTION_PHRASES = Map.of( - "password", "修改密码", - "resetpassword", "重置密码"); - private OperationDescription() { } - /** 推导操作中文描述。 */ - static String describe(String method, String resourceType, String path) { + /** + * 推导语义动作键(捕获时落库标注,供筛选):登录/登出/认证操作由路径判定, + * 子动作段优先于 HTTP 方法,其余方法归为 create/update/delete/view; + * 无法识别(未知方法等)返回 null,记录不标注。 + */ + static String actionOf(String method, String resourceType, String path) { var cleanPath = pathWithoutQuery(path); - if ("auth".equals(resourceType) || "/login".equals(cleanPath) - || "/logout".equals(cleanPath)) { - if ("/login".equals(cleanPath)) { - return "登录"; - } - if ("/logout".equals(cleanPath)) { - return "登出"; - } - return "认证操作"; + if ("/login".equals(cleanPath)) { + return "login"; + } + if ("/logout".equals(cleanPath)) { + return "logout"; + } + if ("auth".equals(resourceType)) { + return "auth"; } - var label = RESOURCE_LABELS.getOrDefault(resourceType, resourceType); - var verb = METHOD_VERBS.getOrDefault(method, method); // /apis/{group}/{version}/{plural}/{name}/{action}: // 去掉空段后 segments 为 [apis, group, version, plural, name, action], // 子动作段为 segments[5] var segments = Arrays.stream(cleanPath.split("/")) .filter(segment -> !segment.isEmpty()) .toArray(String[]::new); - var action = segments.length >= 6 ? segments[5].toLowerCase() : null; - if (action != null) { - var phrase = SUB_ACTION_PHRASES.get(action); - if (phrase != null) { - return phrase; - } - var subVerb = SUB_ACTION_VERBS.get(action); - if (subVerb != null) { - return subVerb + label; + if (segments.length >= 6) { + var action = SEGMENT_ACTIONS.get(segments[5].toLowerCase()); + if (action != null) { + return action; } } - return verb + label; + return METHOD_ACTIONS.get(method); + } + + /** 由语义动作键推导中文描述;键为 null 或未识别返回 null(调用方回退 method 推导)。 */ + static String describeAction(String action, String resourceType) { + if (action == null) { + return null; + } + var phrase = ACTION_PHRASES.get(action); + if (phrase != null) { + return phrase; + } + var verb = ACTION_VERBS.get(action); + return verb == null ? null : verb + resourceLabel(resourceType); + } + + /** + * 推导操作中文描述(展示/导出用):优先语义动作键,识别失败回退为 + * 「method 动词 + 资源名」。 + */ + static String describe(String method, String resourceType, String path) { + var phrase = describeAction(actionOf(method, resourceType, path), resourceType); + if (phrase != null) { + return phrase; + } + return method + resourceLabel(resourceType); + } + + private static String resourceLabel(String resourceType) { + return RESOURCE_LABELS.getOrDefault(resourceType, resourceType); } /** 剥离路径的查询串(spec.path 存的是含查询串的完整路径)。 */ diff --git a/plugin-operation-audit/src/test/java/run/halo/operationaudit/OperationAuditPluginTest.java b/plugin-operation-audit/src/test/java/run/halo/operationaudit/OperationAuditPluginTest.java index c748cbc..ef5f878 100644 --- a/plugin-operation-audit/src/test/java/run/halo/operationaudit/OperationAuditPluginTest.java +++ b/plugin-operation-audit/src/test/java/run/halo/operationaudit/OperationAuditPluginTest.java @@ -47,6 +47,7 @@ class OperationAuditPluginTest { "spec.username", "spec.resourceType", "spec.method", + "spec.action", "spec.statusCode", "spec.resourceName", "spec.path"); diff --git a/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/AuditQueryEndpointTest.java b/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/AuditQueryEndpointTest.java index d0f8924..9476809 100644 --- a/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/AuditQueryEndpointTest.java +++ b/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/AuditQueryEndpointTest.java @@ -80,6 +80,22 @@ class AuditQueryEndpointTest { .contains("500"); } + @Test + void shouldApplySemanticActionFieldSelector() { + webClient.get() + .uri("/apis/audit.guichumo.com/v1alpha1/auditlogs/-/query" + + "?fieldSelector=spec.action=publish") + .exchange() + .expectStatus().isOk(); + + var captor = ArgumentCaptor.forClass(ListOptions.class); + verify(client).listBy(eq(AuditLog.class), captor.capture(), any(PageRequest.class)); + var condition = captor.getValue().toCondition().toString(); + assertThat(condition) + .contains("spec.action") + .contains("publish"); + } + @Test void shouldApplyResultFilter() { webClient.get() diff --git a/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/AuditRecorderTest.java b/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/AuditRecorderTest.java index f9b437f..dd9a4b9 100644 --- a/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/AuditRecorderTest.java +++ b/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/AuditRecorderTest.java @@ -60,6 +60,8 @@ class AuditRecorderTest { assertThat(auditLog.getSpec().getUsername()).isEqualTo("admin"); assertThat(auditLog.getSpec().getMethod()).isEqualTo("DELETE"); + // 语义动作标注(产品设计 V2):捕获时推导落库 + assertThat(auditLog.getSpec().getAction()).isEqualTo("delete"); assertThat(auditLog.getSpec().getResourceType()).isEqualTo("posts"); assertThat(auditLog.getSpec().getResourceName()).isEqualTo("xyz"); assertThat(auditLog.getSpec().getPath()).isEqualTo( @@ -80,9 +82,22 @@ class AuditRecorderTest { assertThat(captor.getValue().getSpec().getUsername()) .isEqualTo(AuditLogSpec.UNKNOWN_USERNAME); assertThat(captor.getValue().getSpec().getResourceType()).isEqualTo("auth"); + assertThat(captor.getValue().getSpec().getAction()).isEqualTo("login"); assertThat(captor.getValue().getSpec().getStatusCode()).isEqualTo(401); } + @Test + void shouldAnnotateSubActionSemanticAction() { + recorder.record(RequestSnapshot.of(MockServerHttpRequest + .put("http://localhost/apis/api.console.halo.run/v1alpha1/posts/xyz/publish") + .build()), 200, "admin"); + + var captor = ArgumentCaptor.forClass(AuditLog.class); + verify(client).create(captor.capture()); + assertThat(captor.getValue().getSpec().getAction()).isEqualTo("publish"); + assertThat(captor.getValue().getSpec().getResourceType()).isEqualTo("posts"); + } + @Test void shouldSkipRecordingWhenAuditDisabled() { when(settingProvider.get()).thenReturn(Mono.just(new AuditSettings(false, 30))); diff --git a/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/OperationDescriptionTest.java b/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/OperationDescriptionTest.java index 184a725..da2e6b5 100644 --- a/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/OperationDescriptionTest.java +++ b/plugin-operation-audit/src/test/java/run/halo/operationaudit/audit/OperationDescriptionTest.java @@ -100,4 +100,119 @@ class OperationDescriptionTest { assertThat(OperationDescription.describe("POST", "workflows", null)) .isEqualTo("新建workflows"); } + + @Test + void shouldDeriveLoginLogoutAuthActions() { + assertThat(OperationDescription.actionOf("POST", "auth", "/login")).isEqualTo("login"); + // GET /login?redirect_uri=... 也应识别为登录(path 含查询串) + assertThat(OperationDescription.actionOf("GET", "auth", + "/login?redirect_uri=https%3A%2F%2Fwww.guichumo.com%2Fconsole")).isEqualTo("login"); + assertThat(OperationDescription.actionOf("POST", "auth", "/logout")).isEqualTo("logout"); + assertThat(OperationDescription.actionOf("POST", "auth", "/auth/other")) + .isEqualTo("auth"); + } + + @Test + void shouldDeriveMethodActions() { + assertThat(OperationDescription.actionOf("POST", "users", + "/apis/api.console.halo.run/v1alpha1/users")).isEqualTo("create"); + assertThat(OperationDescription.actionOf("PUT", "posts", + "/apis/content.halo.run/v1alpha1/posts/post-abc")).isEqualTo("update"); + assertThat(OperationDescription.actionOf("PATCH", "themes", + "/apis/api.console.halo.run/v1alpha1/themes/theme-abc")).isEqualTo("update"); + assertThat(OperationDescription.actionOf("DELETE", "plugins", + "/apis/api.console.halo.run/v1alpha1/plugins/plugin-abc")).isEqualTo("delete"); + assertThat(OperationDescription.actionOf("GET", "posts", + "/apis/content.halo.run/v1alpha1/posts/post-abc")).isEqualTo("view"); + } + + @Test + void shouldDeriveSubActionFromPathSegment() { + assertThat(OperationDescription.actionOf("POST", "posts", + "/apis/api.console.halo.run/v1alpha1/posts/post-abc/publish")).isEqualTo("publish"); + assertThat(OperationDescription.actionOf("PUT", "posts", + "/apis/api.console.halo.run/v1alpha1/posts/post-abc/unpublish")) + .isEqualTo("unpublish"); + assertThat(OperationDescription.actionOf("PUT", "posts", + "/apis/api.console.halo.run/v1alpha1/posts/post-abc/recycle")) + .isEqualTo("recycle"); + assertThat(OperationDescription.actionOf("PUT", "posts", + "/apis/api.console.halo.run/v1alpha1/posts/post-abc/restore")).isEqualTo("restore"); + assertThat(OperationDescription.actionOf("PUT", "plugins", + "/apis/api.console.halo.run/v1alpha1/plugins/plugin-abc/enable")) + .isEqualTo("enable"); + assertThat(OperationDescription.actionOf("PUT", "plugins", + "/apis/api.console.halo.run/v1alpha1/plugins/plugin-abc/disable")) + .isEqualTo("disable"); + assertThat(OperationDescription.actionOf("PUT", "plugins", + "/apis/api.console.halo.run/v1alpha1/plugins/plugin-abc/upgrade")) + .isEqualTo("upgrade"); + assertThat(OperationDescription.actionOf("PUT", "plugins", + "/apis/api.console.halo.run/v1alpha1/plugins/plugin-abc/uninstall")) + .isEqualTo("uninstall"); + assertThat(OperationDescription.actionOf("PUT", "plugins", + "/apis/api.console.halo.run/v1alpha1/plugins/plugin-abc/reload")) + .isEqualTo("reload"); + assertThat(OperationDescription.actionOf("POST", "comments", + "/apis/api.comment.halo.run/v1alpha1/comments/comment-abc/reply")) + .isEqualTo("reply"); + assertThat(OperationDescription.actionOf("PUT", "posts", + "/apis/api.content.halo.run/v1alpha1/posts/post-abc/recalculate")) + .isEqualTo("recalculate"); + } + + @Test + void shouldNormalizeActivationToEnable() { + // 激活与启用语义相同(主题/插件 activation 与 enable),归并为同一动作键便于统一筛选 + assertThat(OperationDescription.actionOf("PUT", "themes", + "/apis/api.console.halo.run/v1alpha1/themes/theme-abc/activation")) + .isEqualTo("enable"); + } + + @Test + void shouldDerivePasswordSubActions() { + assertThat(OperationDescription.actionOf("PUT", "users", + "/apis/api.console.halo.run/v1alpha1/users/admin/password")).isEqualTo("password"); + assertThat(OperationDescription.actionOf("PUT", "users", + "/apis/api.console.halo.run/v1alpha1/users/admin/resetpassword")) + .isEqualTo("resetpassword"); + } + + @Test + void shouldStripQueryBeforeDerivingAction() { + assertThat(OperationDescription.actionOf("PUT", "posts", + "/apis/api.console.halo.run/v1alpha1/posts/post-abc/publish?async=true")) + .isEqualTo("publish"); + } + + @Test + void shouldFallbackToNullActionForUnknownMethod() { + assertThat(OperationDescription.actionOf("TRACE", "posts", + "/apis/content.halo.run/v1alpha1/posts/post-abc")).isNull(); + // 未识别的子动作回退到方法推导 + assertThat(OperationDescription.actionOf("PUT", "posts", + "/apis/content.halo.run/v1alpha1/posts/post-abc/content")).isEqualTo("update"); + } + + @Test + void shouldDescribeFromActionKey() { + assertThat(OperationDescription.describeAction("login", "auth")).isEqualTo("登录"); + assertThat(OperationDescription.describeAction("logout", "auth")).isEqualTo("登出"); + assertThat(OperationDescription.describeAction("auth", "auth")).isEqualTo("认证操作"); + assertThat(OperationDescription.describeAction("create", "users")).isEqualTo("新建用户"); + assertThat(OperationDescription.describeAction("update", "posts")).isEqualTo("修改文章"); + assertThat(OperationDescription.describeAction("delete", "plugins")) + .isEqualTo("删除插件"); + assertThat(OperationDescription.describeAction("publish", "posts")) + .isEqualTo("发布文章"); + assertThat(OperationDescription.describeAction("restore", "posts")) + .isEqualTo("恢复文章"); + assertThat(OperationDescription.describeAction("enable", "themes")) + .isEqualTo("启用主题"); + assertThat(OperationDescription.describeAction("password", "users")) + .isEqualTo("修改密码"); + // 未识别的键回退 null(调用方回退 method 推导) + assertThat(OperationDescription.describeAction(null, "posts")).isNull(); + assertThat(OperationDescription.describeAction("bogus", "posts")).isNull(); + } } diff --git a/plugin-operation-audit/ui/src/utils/audit.spec.ts b/plugin-operation-audit/ui/src/utils/audit.spec.ts index 2acd70e..48065d4 100644 --- a/plugin-operation-audit/ui/src/utils/audit.spec.ts +++ b/plugin-operation-audit/ui/src/utils/audit.spec.ts @@ -1,9 +1,10 @@ import { describe, expect, it } from 'vitest' import type { AuditLogSpec } from './audit' -import { describeOperation } from './audit' +import { deriveAction, describeOperation, SEMANTIC_ACTIONS } from './audit' -// 操作描述推导(这条操作真正干了什么):由 method / resourceType / path 推导中文短语。 -// 历史记录不落库新字段,描述纯展示层推导,因此必须覆盖所有回退路径,防止出现英文原始值。 +// 操作描述推导(这条操作真正干了什么):由落库的语义动作标注或 +// method / resourceType / path 推导中文短语。 +// 描述必须覆盖所有回退路径,防止出现英文原始值。 function spec(overrides: Partial): AuditLogSpec { return { username: 'admin', @@ -133,3 +134,107 @@ describe('describeOperation', () => { }))).toBe('删除other') }) }) + +describe('deriveAction 语义动作推导', () => { + it('登录/登出/认证操作由路径判定(含查询串剥离)', () => { + expect(deriveAction('POST', 'auth', '/login')).toBe('login') + expect(deriveAction('GET', 'auth', '/login?redirect_uri=https%3A%2F%2Fwww.guichumo.com')) + .toBe('login') + expect(deriveAction('POST', 'auth', '/logout')).toBe('logout') + expect(deriveAction('POST', 'auth', '/auth/other')).toBe('auth') + }) + + it('子动作段优先于 HTTP 方法', () => { + expect(deriveAction('PUT', 'posts', + '/apis/api.console.halo.run/v1alpha1/posts/post-abc/publish')).toBe('publish') + expect(deriveAction('POST', 'posts', + '/apis/api.console.halo.run/v1alpha1/posts/post-abc/restore')).toBe('restore') + // 激活与启用归并为同一动作键 + expect(deriveAction('PUT', 'themes', + '/apis/api.console.halo.run/v1alpha1/themes/theme-abc/activation')).toBe('enable') + expect(deriveAction('PUT', 'users', + '/apis/api.console.halo.run/v1alpha1/users/admin/password')).toBe('password') + }) + + it('无子动作段时由 HTTP 方法归为 create/update/delete/view', () => { + expect(deriveAction('POST', 'users', '/apis/api.console.halo.run/v1alpha1/users')) + .toBe('create') + expect(deriveAction('PUT', 'posts', '/apis/content.halo.run/v1alpha1/posts/post-abc')) + .toBe('update') + expect(deriveAction('DELETE', 'plugins', + '/apis/api.console.halo.run/v1alpha1/plugins/plugin-abc')).toBe('delete') + expect(deriveAction('GET', 'posts', '/apis/content.halo.run/v1alpha1/posts/post-abc')) + .toBe('view') + }) + + it('未知方法与未识别子动作回退为方法键或 null', () => { + expect(deriveAction('TRACE', 'posts', '/apis/content.halo.run/v1alpha1/posts/post-abc')) + .toBeNull() + expect(deriveAction('PUT', 'posts', + '/apis/content.halo.run/v1alpha1/posts/post-abc/content')).toBe('update') + }) +}) + +describe('describeOperation 落库标注优先', () => { + it('spec.action 存在时直接由动作键推导(历史记录无 action 仍走 method/path 推导)', () => { + expect(describeOperation(spec({ + method: 'PUT', + resourceType: 'posts', + path: '/apis/content.halo.run/v1alpha1/posts/post-abc', + action: 'publish', + }))).toBe('发布文章') + expect(describeOperation(spec({ + method: 'POST', + resourceType: 'auth', + path: '/login', + action: 'login', + }))).toBe('登录') + // 与 method/path 现场推导结果一致(同一套推导规则) + expect(describeOperation(spec({ + method: 'PUT', + resourceType: 'posts', + path: '/apis/api.console.halo.run/v1alpha1/posts/post-abc/publish', + action: 'publish', + }))).toBe(describeOperation(spec({ + method: 'PUT', + resourceType: 'posts', + path: '/apis/api.console.halo.run/v1alpha1/posts/post-abc/publish', + }))) + }) + + it('动作键未知时回退为 method 动词 + 资源名', () => { + expect(describeOperation(spec({ + method: 'PUT', + resourceType: 'posts', + path: '/somewhere/odd', + action: 'bogus', + }))).toBe('修改文章') + }) +}) + +describe('SEMANTIC_ACTIONS 筛选选项', () => { + it('值唯一且标签非空', () => { + const values = SEMANTIC_ACTIONS.map((a) => a.value) + expect(new Set(values).size).toBe(values.length) + for (const a of SEMANTIC_ACTIONS) { + expect(a.label).not.toBe('') + } + }) + + it('覆盖全部可落库的语义动作键(view 不会被捕获规则记录,除外)', () => { + // 全量枚举:登录/登出/认证 + 方法动作 + 全部子动作段(含 activation 归并) + const storable = new Set([ + 'login', 'logout', 'auth', + 'create', 'update', 'delete', + 'publish', 'unpublish', 'recycle', 'restore', 'enable', 'disable', + 'upgrade', 'uninstall', 'reload', 'reply', 'recalculate', + 'password', 'resetpassword', + ]) + expect(new Set(SEMANTIC_ACTIONS.map((a) => a.value))).toEqual(storable) + // 每个选项都能由 describeOperation 从动作键推出非空短语(下拉与描述保持一致) + for (const a of SEMANTIC_ACTIONS) { + expect(describeOperation(spec({ resourceType: 'posts', action: a.value }))) + .not.toBe('') + } + }) +}) diff --git a/plugin-operation-audit/ui/src/utils/audit.ts b/plugin-operation-audit/ui/src/utils/audit.ts index 77c286b..a96519a 100644 --- a/plugin-operation-audit/ui/src/utils/audit.ts +++ b/plugin-operation-audit/ui/src/utils/audit.ts @@ -8,6 +8,8 @@ export interface AuditLogSpec { resourceType: string resourceName?: string | null path: string + /** 语义动作键(语义动作标注,如 login/create/publish);旧版本写入的历史记录可能缺失。 */ + action?: string | null statusCode: number remoteIp: string userAgent?: string | null @@ -78,7 +80,7 @@ const RESOURCE_LABELS: Record = { tags: '标签', } -/** 动作方法的基础动词(未知方法回退原始值)。 */ +/** 动作方法的基础动词(未知方法回退原始值,用于未知动作键的展示回退)。 */ const METHOD_VERBS: Record = { POST: '新建', PUT: '修改', @@ -87,11 +89,51 @@ const METHOD_VERBS: Record = { GET: '查看', } +/** 动作方法 → 语义动作键(未知方法无键)。 */ +const METHOD_ACTIONS: Record = { + POST: 'create', + PUT: 'update', + PATCH: 'update', + DELETE: 'delete', + GET: 'view', +} + /** - * 子资源动作段({@code /apis/.../{plural}/{name}/{action}} 的 action)→ 动词, - * 与资源名拼接成短语,如 publish + 文章 = 发布文章。 + * 子资源动作段({@code /apis/.../{plural}/{name}/{action}} 的 action)→ 语义动作键。 + * activation 与 enable 语义相同(激活/启用),归并为同一动作键便于统一筛选。 */ -const SUB_ACTION_VERBS: Record = { +const SEGMENT_ACTIONS: Record = { + publish: 'publish', + unpublish: 'unpublish', + recycle: 'recycle', + restore: 'restore', + enable: 'enable', + activation: 'enable', + disable: 'disable', + upgrade: 'upgrade', + uninstall: 'uninstall', + reload: 'reload', + reply: 'reply', + recalculate: 'recalculate', + password: 'password', + resetpassword: 'resetpassword', +} + +/** 语义动作键 → 完整短语(不拼资源名)。 */ +const ACTION_PHRASES: Record = { + login: '登录', + logout: '登出', + auth: '认证操作', + password: '修改密码', + resetpassword: '重置密码', +} + +/** 语义动作键 → 动词(与资源中文名拼接成短语,如 publish + 文章 = 发布文章)。 */ +const ACTION_VERBS: Record = { + create: '新建', + update: '修改', + delete: '删除', + view: '查看', publish: '发布', unpublish: '取消发布', recycle: '移入回收站', @@ -101,16 +143,35 @@ const SUB_ACTION_VERBS: Record = { upgrade: '升级', uninstall: '卸载', reload: '重载', - activation: '启用', reply: '回复', recalculate: '重新统计', } -/** 子资源动作段 → 完整短语(不拼接资源名)。 */ -const SUB_ACTION_PHRASES: Record = { - password: '修改密码', - resetpassword: '重置密码', -} +/** + * 语义动作筛选选项(键 → 中文标签,与后端 OperationDescription 保持一致): + * view(查看)不会被捕获规则记录,不列入。 + */ +export const SEMANTIC_ACTIONS: Array<{ value: string; label: string }> = [ + { value: 'login', label: '登录' }, + { value: 'logout', label: '登出' }, + { value: 'auth', label: '认证操作' }, + { value: 'create', label: '新建' }, + { value: 'update', label: '修改' }, + { value: 'delete', label: '删除' }, + { value: 'publish', label: '发布' }, + { value: 'unpublish', label: '取消发布' }, + { value: 'recycle', label: '移入回收站' }, + { value: 'restore', label: '恢复' }, + { value: 'enable', label: '启用' }, + { value: 'disable', label: '停用' }, + { value: 'upgrade', label: '升级' }, + { value: 'uninstall', label: '卸载' }, + { value: 'reload', label: '重载' }, + { value: 'reply', label: '回复' }, + { value: 'recalculate', label: '重新统计' }, + { value: 'password', label: '修改密码' }, + { value: 'resetpassword', label: '重置密码' }, +] /** 剥离路径的查询串(spec.path 存的是含查询串的完整路径)。 */ function pathWithoutQuery(path?: string | null): string { @@ -122,42 +183,69 @@ function pathWithoutQuery(path?: string | null): string { } /** - * 操作描述(这条操作真正干了什么):由 method / resourceType / path 推导中文短语, - * 如 登录、登出、新建用户、修改文章、发布文章、启用插件、修改密码。 - * - *

纯展示层推导,不落库:历史记录同样适用;未识别的子动作回退为「动词 + 资源名」, - * 未识别的资源类型直接使用原始 resourceType。 + * 推导语义动作键(语义动作标注,与后端 OperationDescription.actionOf 保持一致): + * 登录/登出/认证操作由路径判定,子动作段优先于 HTTP 方法,其余方法归为 + * create/update/delete/view;无法识别返回 null。 */ -export function describeOperation( - spec: Pick, -): string { - const cleanPath = pathWithoutQuery(spec.path) - if (spec.resourceType === 'auth' || cleanPath === '/login' || cleanPath === '/logout') { - if (cleanPath === '/login') { - return '登录' - } - if (cleanPath === '/logout') { - return '登出' - } - return '认证操作' +export function deriveAction( + method: string, + resourceType: string, + path?: string | null, +): string | null { + const cleanPath = pathWithoutQuery(path) + if (cleanPath === '/login') { + return 'login' + } + if (cleanPath === '/logout') { + return 'logout' + } + if (resourceType === 'auth') { + return 'auth' } - const label = RESOURCE_LABELS[spec.resourceType] ?? spec.resourceType - const verb = METHOD_VERBS[spec.method] ?? spec.method // /apis/{group}/{version}/{plural}/{name}/{action}: // filter(Boolean) 去掉首段空串后,segments 为 [apis, group, version, plural, name, action], // 子动作段为 segments[5] const segments = cleanPath.split('/').filter(Boolean) - const action = segments.length >= 6 ? segments[5].toLowerCase() : null - if (action) { - const phrase = SUB_ACTION_PHRASES[action] - if (phrase) { - return phrase - } - const subVerb = SUB_ACTION_VERBS[action] - if (subVerb) { - return `${subVerb}${label}` + if (segments.length >= 6) { + const action = SEGMENT_ACTIONS[segments[5].toLowerCase()] + if (action) { + return action } } + return METHOD_ACTIONS[method] ?? null +} + +/** 由语义动作键推导中文短语;键为 null 或未识别返回 null(调用方回退 method 推导)。 */ +function describeFromAction(action: string | null, resourceType: string): string | null { + if (!action) { + return null + } + const phrase = ACTION_PHRASES[action] + if (phrase) { + return phrase + } + const verb = ACTION_VERBS[action] + return verb ? `${verb}${RESOURCE_LABELS[resourceType] ?? resourceType}` : null +} + +/** + * 操作描述(这条操作真正干了什么):推导中文短语, + * 如 登录、登出、新建用户、修改文章、发布文章、启用插件、修改密码。 + * + *

优先使用落库的语义动作标注(spec.action);历史记录(无 action 字段)由 + * method/path 现场推导,同样适用。识别失败回退为「method 动词 + 资源名」, + * 未识别的资源类型直接使用原始 resourceType。 + */ +export function describeOperation( + spec: Pick, +): string { + const action = spec.action ?? deriveAction(spec.method, spec.resourceType, spec.path) + const fromAction = describeFromAction(action, spec.resourceType) + if (fromAction) { + return fromAction + } + const label = RESOURCE_LABELS[spec.resourceType] ?? spec.resourceType + const verb = METHOD_VERBS[spec.method] ?? spec.method return `${verb}${label}` } diff --git a/plugin-operation-audit/ui/src/views/AuditLogList.appearance.spec.ts b/plugin-operation-audit/ui/src/views/AuditLogList.appearance.spec.ts index 88b9a73..7fbaf05 100644 --- a/plugin-operation-audit/ui/src/views/AuditLogList.appearance.spec.ts +++ b/plugin-operation-audit/ui/src/views/AuditLogList.appearance.spec.ts @@ -37,9 +37,9 @@ describe('AuditLogList 页面外观', () => { expect(sfc.match(/ { + it('.audit-filter .filter-grid 筛选字段与操作按钮排成一行(8 列 + auto 按钮)', () => { const rule = styleRule('.filter-grid') - expect(rule).toMatch(/grid-template-columns:\s*repeat\(7,\s*minmax\(0,\s*1fr\)\)\s+auto/) + expect(rule).toMatch(/grid-template-columns:\s*repeat\(8,\s*minmax\(0,\s*1fr\)\)\s+auto/) }) it('.audit-pagination 白底铺满整行(不再左右缩进 1rem),仅以 1px 分隔线与列表相接', () => { diff --git a/plugin-operation-audit/ui/src/views/AuditLogList.vue b/plugin-operation-audit/ui/src/views/AuditLogList.vue index 71fcaa4..5193ab2 100644 --- a/plugin-operation-audit/ui/src/views/AuditLogList.vue +++ b/plugin-operation-audit/ui/src/views/AuditLogList.vue @@ -22,6 +22,7 @@ import { isSuccessful, localDateTimeToInstant, methodBadgeClass, + SEMANTIC_ACTIONS, } from '@/utils/audit' import AuditLogDetail from './AuditLogDetail.vue' @@ -51,6 +52,7 @@ const size = ref(20) const filterUsername = ref('') const filterResourceType = ref('') const filterMethod = ref('') +const filterAction = ref('') const filterResult = ref('') const filterKeyword = ref('') const filterStartTime = ref('') @@ -64,6 +66,7 @@ const hasActiveFilter = computed( filterUsername.value || filterResourceType.value || filterMethod.value || + filterAction.value || filterResult.value || filterKeyword.value || filterStartTime.value || @@ -84,6 +87,10 @@ function buildQuery(): string { if (filterMethod.value) { params.append('fieldSelector', `spec.method=${filterMethod.value}`) } + // 语义动作筛选(spec.action,捕获时标注落库;历史记录无标注不会被筛出) + if (filterAction.value) { + params.append('fieldSelector', `spec.action=${filterAction.value}`) + } if (filterResult.value) { params.set('result', filterResult.value) } @@ -162,13 +169,14 @@ function resetFilter() { filterUsername.value = '' filterResourceType.value = '' filterMethod.value = '' + filterAction.value = '' filterResult.value = '' filterKeyword.value = '' filterStartTime.value = '' filterEndTime.value = '' } -watch([filterUsername, filterResourceType, filterMethod, filterResult], () => { +watch([filterUsername, filterResourceType, filterMethod, filterAction, filterResult], () => { page.value = 1 fetchLogs() }) @@ -246,6 +254,15 @@ onMounted(fetchLogs) +