feat: implement document management module

- Backend (FastAPI):
  - Attachment and AttachmentVersion models with migration
  - FileStorageService with SHA-256 checksum validation
  - File type validation (whitelist/blacklist)
  - Full CRUD API with version control support
  - Audit trail integration for upload/download/delete
  - Configurable upload directory and file size limit

- Frontend (React + Vite):
  - AttachmentUpload component with drag & drop
  - AttachmentList component with download/delete
  - TaskAttachments combined component
  - Attachments service for API calls

- Testing:
  - 12 tests for storage service and API endpoints

- OpenSpec:
  - add-document-management change archived

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2025-12-29 22:03:05 +08:00
parent 0ef78e13ff
commit 3108fe1dff
21 changed files with 2027 additions and 1 deletions

View File

@@ -0,0 +1,71 @@
## Phase 1: Basic Attachments
### 1.1 Database Schema
- [x] 1.1.1 建立 Attachment model (`pjctrl_attachments`)
- [x] 1.1.2 建立 AttachmentVersion model (`pjctrl_attachment_versions`)
- [x] 1.1.3 建立 Alembic migration
- [x] 1.1.4 新增 Task model 的 attachments relationship
### 1.2 File Storage Service
- [x] 1.2.1 建立 FileStorageService 類別
- [x] 1.2.2 實作 save_file() 方法(串流處理)
- [x] 1.2.3 實作 get_file() 方法
- [x] 1.2.4 實作 delete_file() 方法
- [x] 1.2.5 新增檔案存儲路徑配置 (UPLOAD_DIR)
- [x] 1.2.6 實作 checksum 計算 (SHA-256)
### 1.3 Attachment API
- [x] 1.3.1 建立 Attachment schemas (request/response)
- [x] 1.3.2 實作 POST `/api/tasks/{task_id}/attachments` - 上傳
- [x] 1.3.3 實作 GET `/api/tasks/{task_id}/attachments` - 列表
- [x] 1.3.4 實作 GET `/api/attachments/{id}` - 詳情
- [x] 1.3.5 實作 GET `/api/attachments/{id}/download` - 下載
- [x] 1.3.6 實作 DELETE `/api/attachments/{id}` - 軟刪除
- [x] 1.3.7 整合 Audit Trail - 記錄上傳/下載/刪除操作
### 1.4 Frontend - Basic
- [x] 1.4.1 建立 attachments.ts service
- [x] 1.4.2 建立 AttachmentList 元件
- [x] 1.4.3 建立 AttachmentUpload 元件(支援拖放)
- [x] 1.4.4 整合至 Task 詳情頁 (TaskAttachments 元件)
### 1.5 Testing - Phase 1
- [x] 1.5.1 FileStorageService 單元測試
- [x] 1.5.2 Attachment API 端點測試
- [x] 1.5.3 上傳/下載整合測試
## Phase 2: Version Control
### 2.1 Version Logic
- [x] 2.1.1 修改上傳邏輯支援版本控制
- [x] 2.1.2 實作 GET `/api/attachments/{id}/versions` - 版本歷史
- [x] 2.1.3 實作 POST `/api/attachments/{id}/restore/{version}` - 回復版本
- [x] 2.1.4 實作 GET `/api/attachments/{id}/download?version=N` - 下載特定版本
### 2.2 Frontend - Version
- [x] 2.2.1 建立 VersionHistory 元件 (integrated in AttachmentList)
- [x] 2.2.2 新增版本選擇下載功能 (in attachments service)
- [x] 2.2.3 新增版本回復功能 (in attachments service)
### 2.3 Testing - Phase 2
- [x] 2.3.1 版本控制邏輯測試
- [x] 2.3.2 版本 API 端點測試
## Phase 3: Security Features (Optional)
### 3.1 Encryption
- [ ] 3.1.1 建立 EncryptionService 類別
- [ ] 3.1.2 實作 encrypt_file() / decrypt_file() 方法
- [ ] 3.1.3 新增 Project security_level 欄位(如不存在)
- [ ] 3.1.4 修改上傳邏輯:機密專案自動加密
- [ ] 3.1.5 修改下載邏輯:自動解密
### 3.2 Watermarking
- [ ] 3.2.1 建立 WatermarkService 類別
- [ ] 3.2.2 實作圖片浮水印Pillow
- [ ] 3.2.3 實作 PDF 浮水印PyMuPDF
- [ ] 3.2.4 整合至下載流程
### 3.3 Testing - Phase 3
- [ ] 3.3.1 加密/解密測試
- [ ] 3.3.2 浮水印生成測試