Repository navigation
Commit 13afa94
authored
feat(audit): 审计异常文件到期自动移入回收站 (#2877)
## What
F088 审计异常文件到期自动移入回收站:
- 知识空间源文件中,加密、结构损坏、格式不支持、内容违规、归属已更新记录,终态满自然 24 小时后由 hourly 任务自动软删除进回收站。
- 迁移 `v2_6_0_f125_abnormal_auto_delete` 增加
`knowledgefile.abnormal_auto_delete_exempt`,并把上线时已有的状态 3/6/7
记录标记为豁免;历史异常永不自动删除。
- 复用现有
`KnowledgeSpaceService.delete_file`,保留版本/分发/收藏/纠错保护;带版本链/分发入口的记录跳过并记日志。
- 删除写 `abnormal_upload.auto_delete` 审计;任务记录
scanned/deleted/skipped/failed。
- 异常列表新增 `auto_delete_exempt`;历史豁免记录不展示“1个工作日自动删除”文案;归属已更新记录补齐提示。
## Why
F087 的提示承诺“1 个工作日后自动删除”,但平台没有对应任务;用户要求实现定时删除,并最终选择**删除进回收站**而非立即物理删除。
需求/设计/用例/验收交接见 `features/v2.5.0-sg/088-abnormal-file-auto-delete/`。
## How
- 候选查询在 SQL 中过滤源文件、状态 3/7、未豁免、到期、非分发/版本链,避免受保护记录饥饿。
- 行锁复核状态/类别/豁免/时间后调用现有删除路径,文件进入回收站;不立即 purge,不改变回收站保留期。
- Beat 根任务按租户 fanout,子任务设置租户上下文;每租户每轮最多 200 条。
## Test
- [x] 本地测试通过
- [ ] 114/171 测试服务器验证通过
本地:
- 后端:`pytest test/knowledge/test_abnormal_auto_delete.py
test/knowledge/test_abnormal_upload_retry_batch.py
test/knowledge/test_knowledge_recycle_bin.py
test/knowledge/test_source_file_validation.py
test/knowledge/test_unreadable_sync_file_cleanup.py` → **68 passed**
- 平台:`vitest run test/abnormalTerminalNotice.test.tsx
test/abnormalPreviewLifecycle.test.ts test/abnormalFilePreview.test.ts`
→ **72 passed**
- `ruff` 新文件、`git diff --check`、`arch-guard.sh` 通过;平台 tsc 仅既有 TS2802。
**未验证:** MySQL/DM8 实库迁移、真实 24h 任务窗口、回收站恢复/保留期与后续物理清理、多租户实库、版本/分发入口拒绝。
## Known limits
- 版本链/分发入口记录按用户决定跳过并记日志,不自动回收。
- 到期后进入回收站,不是立即物理删除;物理清理由现有回收站保留期任务处理。
- 界面仍显示“1个工作日”,实际按用户选择自然 24 小时执行。
- 历史豁免记录提示不展示删除说明,且永不自动删除。
## Related
- F087:`features/v2.5.0-sg/087-audit-unparseable-file-notice`
-
验收交接:`features/v2.5.0-sg/088-abnormal-file-auto-delete/acceptance-handoff.md`
🤖 Generated with [Claude Code](https://claude.com/claude-code)27 files changed
Lines changed: 1352 additions & 174 deletions
File tree
- features/v2.5.0-sg/088-abnormal-file-auto-delete
- reviews
- src
- backend
- bisheng
- core
- config
- database/alembic/versions
- knowledge/domain
- models
- repositories
- implementations
- interfaces
- services
- worker
- knowledge
- test
- fixtures
- knowledge
- frontend/platform
- public/locales
- en-US
- ja
- zh-Hans
- src
- controllers/API
- pages/LogPage/abnormalUpload
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
0 commit comments