diff --git a/plugin-operation-audit/README.md b/plugin-operation-audit/README.md index ffbf12b..c33f1f4 100644 --- a/plugin-operation-audit/README.md +++ b/plugin-operation-audit/README.md @@ -19,6 +19,8 @@ Halo 2.x 操作审计插件:回答"**谁、在什么时候、对什么资源 中文操作描述由同一套推导生成,贯穿列表、详情与导出 CSV,历史记录同样适用。 - **审计日志查看**:Console 左侧菜单"操作审计"——列表 + 八维筛选(操作者/资源类型/动作/ 语义动作/结果/时间区间/关键字)+ 分页 + 只读详情抽屉(含原始 JSON)。不提供任何删除/修改入口。 + 有资源名称的记录行内提供「历史」快捷动作:一键预填资源类型 + 资源名关键字并刷新列表, + 直接回答"这个资源被谁改过"(功能评审 P1-1)。 - **导出 CSV**:列表页「导出」按钮按当前筛选条件导出全部记录——后端全量流式生成 (UTF-8 BOM + `\r\n`,Excel/WPS 双击打开中文不乱码),列与界面一致(操作时间、操作者、 尝试用户、动作、资源类型、资源名称、路径、操作描述、变更、结果、状态码、来源 IP、 diff --git a/plugin-operation-audit/ui/src/views/AuditLogList.resource-history.spec.ts b/plugin-operation-audit/ui/src/views/AuditLogList.resource-history.spec.ts new file mode 100644 index 0000000..ed811de --- /dev/null +++ b/plugin-operation-audit/ui/src/views/AuditLogList.resource-history.spec.ts @@ -0,0 +1,35 @@ +import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import { describe, expect, it } from 'vitest' + +// 结构性回归测试:不渲染组件,仅检查 SFC 源码中的资源历史快捷链路。 +// 「查看该资源历史」为列表行内快捷动作(功能评审 P1-1):产品定位第一个典型场景 +// ("这篇文章谁改过的")——点击预填 resourceType + 资源名关键字(关键字匹配资源 +// 名称/路径)并刷新列表;不新增后端参数,与现有筛选/导出条件共用同一套状态。 +const sfc = readFileSync(fileURLToPath(new URL('./AuditLogList.vue', import.meta.url)), 'utf-8') + +describe('AuditLogList 查看该资源历史', () => { + it('行内快捷动作:仅在有资源名称的记录上渲染,stop 冒泡避免触发详情抽屉', () => { + const rowStart = sfc.indexOf('', rowStart) + const row = sfc.slice(rowStart, rowEnd) + expect(row).toContain('v-if="log.spec.resourceName"') + expect(row).toContain('@click.stop="viewResourceHistory(log)"') + expect(row).toContain('查看该资源的历史操作') + }) + + it('预填筛选:资源类型 + 资源名关键字,并走统一查询入口刷新列表', () => { + const fnStart = sfc.indexOf('function viewResourceHistory(log: AuditLog)') + expect(fnStart).toBeGreaterThan(-1) + const fn = sfc.slice(fnStart, sfc.indexOf('', fnStart)) + expect(fn).toContain('filterResourceType.value = log.spec.resourceType') + expect(fn).toContain("filterKeyword.value = log.spec.resourceName ?? ''") + expect(fn).toContain('applyFilters()') + }) + + it('不新增后端参数:复用现有 resourceType fieldSelector 与 keyword 模糊匹配', () => { + // 与现有筛选/导出条件共用同一套状态——buildQuery 生成相同参数形态 + expect(sfc).toContain("params.append('fieldSelector', `spec.resourceType=${filterResourceType.value}`)") + expect(sfc).toContain("params.set('keyword', filterKeyword.value.trim())") + }) +}) diff --git a/plugin-operation-audit/ui/src/views/AuditLogList.vue b/plugin-operation-audit/ui/src/views/AuditLogList.vue index 5193ab2..aa6d0b1 100644 --- a/plugin-operation-audit/ui/src/views/AuditLogList.vue +++ b/plugin-operation-audit/ui/src/views/AuditLogList.vue @@ -176,6 +176,17 @@ function resetFilter() { filterEndTime.value = '' } +/** + * 查看该资源历史(功能评审 P1-1):行内快捷动作——预填资源类型 + 资源名关键字 + * (关键字匹配资源名称/路径)并刷新列表,与现有筛选/导出条件共用同一套状态, + * 不新增后端参数。仅在有资源名称的记录上提供(集合级/登录操作无可回溯的具体资源)。 + */ +function viewResourceHistory(log: AuditLog) { + filterResourceType.value = log.spec.resourceType + filterKeyword.value = log.spec.resourceName ?? '' + applyFilters() +} + watch([filterUsername, filterResourceType, filterMethod, filterAction, filterResult], () => { page.value = 1 fetchLogs() @@ -348,6 +359,14 @@ onMounted(fetchLogs) {{ log.spec.resourceType }} + + 历史