feat: implement task management module

Backend (FastAPI):
- Database migration for spaces, projects, task_statuses, tasks tables
- SQLAlchemy models with relationships
- Pydantic schemas for CRUD operations
- Spaces API: CRUD with soft delete
- Projects API: CRUD with auto-created default statuses
- Tasks API: CRUD, status change, assign, subtask support
- Permission middleware with Security Level filtering
- Subtask depth limit (max 2 levels)

Frontend (React + Vite):
- Layout component with navigation
- Spaces list page
- Projects list page
- Tasks list page with status management

Fixes:
- auth_client.py: use 'username' field for external API
- config.py: extend JWT expiry to 7 days
- auth/router.py: sync Redis session with JWT expiry

Tests: 36 passed (unit + integration)
E2E: All APIs verified with real authentication

OpenSpec: add-task-management 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 00:31:34 +08:00
parent 1fda7da2c2
commit daca7798e3
41 changed files with 3616 additions and 13 deletions

View File

@@ -0,0 +1,163 @@
# Tasks: add-task-management
## 1. 資料庫模型
- [x] 1.1 建立 `pjctrl_spaces` migration
- [x] 1.2 建立 `pjctrl_projects` migration
- [x] 1.3 建立 `pjctrl_task_statuses` migration
- [x] 1.4 建立 `pjctrl_tasks` migration
- [x] 1.5 建立 SQLAlchemy models (Space, Project, TaskStatus, Task)
- [x] 1.6 驗證 migration 可正確執行與回滾
## 2. Pydantic Schemas
- [x] 2.1 建立 Space schemas (Create, Update, Response)
- [x] 2.2 建立 Project schemas (Create, Update, Response)
- [x] 2.3 建立 TaskStatus schemas (Create, Update, Response)
- [x] 2.4 建立 Task schemas (Create, Update, Response)
## 3. 權限中間件
- [x] 3.1 實作 Space 權限檢查 (`check_space_access`)
- [x] 3.2 實作 Project 權限檢查 (`check_project_access`)
- [x] 3.3 實作 Security Level 過濾邏輯
- [x] 3.4 整合至現有 auth middleware
## 4. Spaces API
- [x] 4.1 實作 `GET /api/spaces` (列出可見空間)
- [x] 4.2 實作 `POST /api/spaces` (建立空間)
- [x] 4.3 實作 `GET /api/spaces/{id}` (取得詳情)
- [x] 4.4 實作 `PATCH /api/spaces/{id}` (更新空間)
- [x] 4.5 實作 `DELETE /api/spaces/{id}` (軟刪除)
## 5. Projects API
- [x] 5.1 實作 `GET /api/spaces/{space_id}/projects` (列出專案)
- [x] 5.2 實作 `POST /api/spaces/{space_id}/projects` (建立專案)
- [x] 5.3 實作 `GET /api/projects/{id}` (取得詳情)
- [x] 5.4 實作 `PATCH /api/projects/{id}` (更新專案)
- [x] 5.5 實作 `DELETE /api/projects/{id}` (刪除專案)
- [x] 5.6 建立專案時自動建立預設狀態
## 6. Tasks API
- [x] 6.1 實作 `GET /api/projects/{project_id}/tasks` (列出任務)
- [x] 6.2 實作 `POST /api/projects/{project_id}/tasks` (建立任務)
- [x] 6.3 實作 `GET /api/tasks/{id}` (取得詳情)
- [x] 6.4 實作 `PATCH /api/tasks/{id}` (更新任務)
- [x] 6.5 實作 `DELETE /api/tasks/{id}` (刪除任務)
- [x] 6.6 實作 `PATCH /api/tasks/{id}/status` (變更狀態)
- [x] 6.7 實作 `PATCH /api/tasks/{id}/assign` (指派任務)
- [x] 6.8 實作子任務建立 (parent_task_id)
## 7. 測試
- [x] 7.1 撰寫 Space API 單元測試
- [x] 7.2 撰寫 Project API 單元測試
- [x] 7.3 撰寫 Task API 單元測試
- [x] 7.4 撰寫權限檢查測試 (Security Level)
- [x] 7.5 撰寫子任務層級限制測試
- [x] 7.6 整合測試
## 8. 前端 (基礎)
- [x] 8.1 建立 Spaces 列表頁面
- [x] 8.2 建立 Projects 列表頁面
- [x] 8.3 建立 Tasks 列表視角 (ListView)
- [x] 8.4 建立任務建立/編輯表單
- [x] 8.5 實作任務狀態變更
- [x] 8.6 實作任務指派功能
## Dependencies
```
1.x (資料庫) → 2.x (Schemas) → 3.x (權限)
4.x (Spaces API)
5.x (Projects API)
6.x (Tasks API)
7.x (測試)
8.x (前端) 可與 4.x-6.x 並行開發
```
## Notes
- 所有資料表使用 `pjctrl_` 前綴
- 子任務深度限制為 2 層
- 每個新專案自動建立 4 個預設狀態
- Security Level 為 'confidential' 時需檢查專案成員資格
## Implementation Summary
完成日期: 2024-12-28
E2E 測試完成日期: 2024-12-29
### 已建立的檔案
**Backend:**
- `migrations/versions/002_task_management_tables.py` - 資料庫 migration
- `app/models/space.py` - Space model
- `app/models/project.py` - Project model
- `app/models/task_status.py` - TaskStatus model
- `app/models/task.py` - Task model
- `app/schemas/space.py` - Space schemas
- `app/schemas/project.py` - Project schemas
- `app/schemas/task_status.py` - TaskStatus schemas
- `app/schemas/task.py` - Task schemas
- `app/api/spaces/router.py` - Spaces API
- `app/api/projects/router.py` - Projects API
- `app/api/tasks/router.py` - Tasks API
- `tests/test_spaces.py` - Space 測試
- `tests/test_projects.py` - Project 測試
- `tests/test_tasks.py` - Task 測試
**Frontend:**
- `src/pages/Spaces.tsx` - Spaces 列表頁面
- `src/pages/Projects.tsx` - Projects 列表頁面
- `src/pages/Tasks.tsx` - Tasks 列表頁面
- `src/components/Layout.tsx` - 共用 Layout 元件
### 測試結果
36 tests passed (包含 user-auth 的 13 個測試)
### E2E 測試結果 (2024-12-29)
使用真實帳號 (ymirliu@panjit.com.tw) 進行端對端測試:
**Spaces API:**
- [x] POST /api/spaces - 建立空間
- [x] GET /api/spaces - 列出空間
- [x] GET /api/spaces/{id} - 取得空間詳情
- [x] PATCH /api/spaces/{id} - 更新空間
- [x] DELETE /api/spaces/{id} - 軟刪除空間
**Projects API:**
- [x] POST /api/spaces/{space_id}/projects - 建立專案
- [x] GET /api/spaces/{space_id}/projects - 列出專案
- [x] GET /api/projects/{id} - 取得專案詳情
- [x] PATCH /api/projects/{id} - 更新專案
- [x] DELETE /api/projects/{id} - 刪除專案
- [x] GET /api/projects/{id}/statuses - 驗證 4 個預設狀態自動建立
**Tasks API:**
- [x] POST /api/projects/{project_id}/tasks - 建立任務
- [x] GET /api/projects/{project_id}/tasks - 列出任務
- [x] GET /api/tasks/{id} - 取得任務詳情
- [x] PATCH /api/tasks/{id} - 更新任務
- [x] PATCH /api/tasks/{id}/status - 變更狀態
- [x] PATCH /api/tasks/{id}/assign - 指派任務
- [x] DELETE /api/tasks/{id} - 刪除任務
- [x] 子任務建立 (Level 1) - 成功
- [x] 子任務深度限制 (Level 2) - 正確拒絕
- [x] subtask_count 自動計算 - 正確
**權限控制:**
- [x] Admin 可存取 department 級別專案
- [x] Admin 可存取 confidential 級別專案
- [x] Security Level 過濾邏輯運作正常