# Bugfix Session 2 SUMMARY — template-edit 驗收修補（接續 session 1）

> **時程**：2026-05-21（接續同日 session 1 SUMMARY：`2026-05-21-bugfix-SUMMARY.md`）
> **狀態**：BE + FE 各 1 commit ✅；working tree 乾淨（pyproject.toml dev path dep 未 commit，屬正常）
> **跨 repo**：compliance-manager-be + compliance-manager-fe

---

## 1. 這段時間在幹嘛（一句話）

Session 1 SUMMARY 後 user 繼續驗收，陸續發現 template-edit 參與人員 / 資訊系統 / 設備 picker UX 問題 + 新建專案自動帶入 SSP 資源失效 + AO 實施狀態不帶入新專案，本次統一修補。

---

## 2. Commit 清單

### BE (`feature/ssp-import-export-phase2`)
```
5adb550 fix(module-frame): template-edit bugfix session 2 — parties/AO/SSP resources/project prefill
```
（1 commit，接 5aac0d5 之後）

### FE (`feature/ssp-import-export-phase2`)
```
16faada fix(module-frame): template-edit bugfix session 2 — FE parties/devices/info-systems picker UX + project prefill
```
（1 commit，接 926dd34 之後）

---

## 3. 修補項目與根因

| # | Bug 描述 | 根因 | 修正位置 |
|---|---------|------|---------|
| 1 | 參與人員 picker 選帳號沒反應 | PrimeVue Dropdown 空 options 時不觸發 `@update:modelValue`；options 在 Dialog 開啟後才 lazy load | FE `ModuleFramePartiesPanel.vue` → `onMounted` 預載 |
| 2 | 參與人員 Email 沒帶入 | `UserMenuResponse` schema 缺 `email` 欄位 | BE `api/auth/serializers/user.py` |
| 3 | 單位鉤稽顯示 `#99` | `OrgUnitMenuRoute only=["uid","name"]` 排除 `id`；`apply=False` 無顯式 `.dump()` | BE `api/auth/routes/org_unit_route.py` |
| 4 | 新增參與人員 500 錯誤 | `ResponsiblePartyEntity` 無 `uid` 欄位，`BaseRepoImpl.update()` 引發 `AttributeError` | BE `module_frame_party_service._link_to_module_frame` → idempotent return |
| 5 | 資訊系統 picker 無法新增 | `InformationSystemMenuResponseSchema.id` 回傳 UUID，但 `system_characteristic_id` 為 integer FK | BE `api/information_system/serializers/information_system.py` → 加 `pk = Integer` |
| 6 | Picker 下拉無 loading 狀態 | 缺 `*Loading` ref，`Dropdown` placeholder 未提示 | FE 三個 panel 加 `*Loading` ref |
| 7 | Picker 顯示已鉤稽的選項 | 無過濾邏輯 | FE 三個 panel 加 `available*Options` computed |
| 8 | 設備 panel 設備 picker 空列表 | `ensureTenantDevices` 送 `pageSize` 但 BE schema 要 `page_size` | FE `ModuleFrameSspDevicesPanel.vue` |
| 9 | 新建專案設備/資訊系統不帶入 | `ssp-resources` response 缺 `matched_*_uid`；`ProjectCreateView` 沒呼叫 API | BE 加 uid 欄位 + FE `loadModuleFrameSspResources()` |
| 10 | 新建專案參與人員角色全是 'viewer' | `loadModuleFrameParties` 硬寫 `role: 'viewer'` | FE `ProjectCreateView.vue` → `role: p.role \|\| 'viewer'` |
| 11 | 設備/資訊系統「鉤稽」顯示「未鉤稽」 | `_batch_device_names` 用 `.get_by_id()`（不存在），silently returns `{}` | BE `module_frame_ssp_resources_service.py` → `get_devices_by_ids` / `InformationSystemQueryEntity(_in_id=...)` |
| 12 | 單位鉤稽名稱顯示 `#id` | `_enrich_user_org_names` 用 `OrgUnitQueryEntity(_in_id=...)` — 不存在參數，靜默失敗 | BE `module_frame_party_service.py` → `get_org_units_by_id_list()` |
| 13 | 新建專案 AO 實施狀態/現況說明不帶入 | 舊 copy SQL 只 JOIN `ccai.uid::text = mfod.statement_identifier`；Excel import 寫入 `(a)/(b)` letter key，UUID JOIN 零命中 | BE `module_frame_template_copy_service.py` → CTE task_map 雙格式 |
| 14 | FE 手動存 AO 驗證失敗 | `_validate_objective_in_profile` 只驗 UUID，但 FE 送 `(a)/(b)` letter key | BE `module_frame_control_objective_default_service.py` → 同時接受 letter key |

---

## 4. 架構改動摘要

### BE

- **`InformationSystemMenuResponseSchema`**：`id`（UUID，向後相容）+ `pk`（integer PK）雙欄位，不同 consumer 取不同欄位
- **`ResponsiblePartyEntity` 操作慣例**：link record 無 `uid`，一律用 idempotent return（查存在 → skip / add）
- **`module_frame_template_copy_service` AO copy SQL**：改 CTE 統一處理 UUID + `(a)/(b)` 兩種 statement_identifier 格式
- **`_validate_objective_in_profile`**：除 UUID 外，接受從 `description` 前綴 `[a]`/`[b]` 推導的 letter key

### FE

- **PartiesPanel**：Dropdown picker（替代 PartyLinkDialog）+ `onMounted` 預載 + `availablePickerOptions` filter + email auto-fill + DataTable 角色/Email 分欄
- **Devices / InfoSystems Panel**：`*Loading` ref + `available*Options` computed + 資訊系統 picker value 改 `s.pk`
- **ProjectCreateView**：`loadModuleFrameSspResources()` — 呼叫 ssp-resources API 取 `matched_*_uid`，merge 進 `selectedSystemIds` / `selectedDevices`

---

## 5. Changelog 清單

**BE (`docs/changelog/`)**
- `fix-user-org-menu-response-id-email.md`（#1/#2/#3）
- `fix-responsible-party-idempotent-and-info-system-pk.md`（#4/#5）
- `fix-party-org-unit-name-enrich.md`（#12）
- `fix-ssp-resources-matched-name-lookup.md`（#11）
- `feat-ssp-resources-matched-uid-and-project-prefill.md`（#9/#10）
- `fix-ao-copy-letter-key-and-validation.md`（#13/#14）

**FE (`docs/changelog/`)**
- `tweak-parties-link-to-dropdown.md`（基本 picker 改造）
- `fix-parties-picker-ux-and-datatable-columns.md`（#1/#7 + DataTable columns）
- `tweak-template-edit-panels-use-dialog.md`（Dialog 形式）
- `fix-devices-picker-page-size.md`（#8）
- `fix-ssp-panels-picker-loading-and-available-options.md`（#6/#7）

---

## 6. 已知 Follow-up

| 項目 | 說明 |
|------|------|
| BE 重啟提醒 | 所有 BE 修補需重啟生效（no hot reload）|
| 設備 Tab 「鉤稽」欄顯示 | session 1 SUMMARY 提到的 spinner fix（`fix: 拔 immediate watch`）已 commit；本次 batch lookup fix 讓名稱正確顯示 |
| `module_frame_control_objective_defaults` 資料遷移 | 現有 UUID 格式的 `statement_identifier` 資料可繼續使用（copy SQL 雙格式支援）；新資料一律寫 letter key |
| 新建專案自動帶入測試 | 需驗收：選有 AO 資料的資源庫 → 受評範圍設備/資訊系統正確帶入 → AO 實施狀態正確帶入 |
