[CLAUDE] Docs: Chunk E7 — chốt session 9 Chunk E-bis complete
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m7s
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m7s
- STATUS: Recently Done +1 row session 9 (5 commit per-chunk + 83 test). Phase 9 header update count 77→83. Section E (Chunk E-bis) tick toàn bộ done. - HANDOFF: TL;DR session 9 + Cảnh báo session 10. Giữ session 8 narrative cũ. - migration-todos: Phase 9 +1 section "Session 9 done" với 5 task tick. Pending Chunk E-bis tick chuyển done. - CLAUDE.md (root + docs): test count 77 → 83 (54 Domain + 29 Infra: 17 codegen + 6 PE WF Application + 6 PE 2-stage approval). - Session log mới: 2026-05-04-1700-chot-session-9-chunk-e-bis-complete.md (full narrative + lessons + stats theo §6.5 KEEP rule). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -1,6 +1,30 @@
|
||||
# HANDOFF — Brief 5 phút cho session tiếp theo
|
||||
|
||||
**Last updated:** 2026-05-04 (Session 8 — **Migration 16: 2-stage dept approval + smart reject + lock edit. Đóng bug anh Kiệt báo: NV duyệt được hết phase PE.**)
|
||||
**Last updated:** 2026-05-04 (Session 9 — **Chunk E-bis complete: FE 2-stage panel cả 3 module + UserManager bypass toggle + HĐ/Budget 2-stage mirror PE + 6 test + IdentityFixture. 83 test pass.**)
|
||||
|
||||
## TL;DR Session 9 (04/05 — Chunk E-bis sau Session 8)
|
||||
|
||||
**Output session 9** — đóng tất cả Chunk E-bis defer từ session 8:
|
||||
|
||||
- ✅ **FE PE WorkflowPanel** — Section "Tiến trình duyệt 2-cấp phòng ban" group by phase × dept, highlight amber chờ TPB confirm, badge fuchsia bypass (cả fe-admin + fe-user).
|
||||
- ✅ **FE UsersPage UserManager** — Column "Bypass" + button ShieldCheck toggle CanBypassReview, badge fuchsia khi enabled. UserDto thêm field.
|
||||
- ✅ **HĐ 2-stage logic** — `ContractWorkflowService` thêm UserManager DI + mirror logic từ PE service. `ContractDepartmentApprovalFeatures.cs` List query. Endpoint `GET /contracts/{id}/department-approvals`. FE `WorkflowHistoryPanel` section mới.
|
||||
- ✅ **Budget 2-stage logic** — `TransitionBudgetCommandHandler` thêm INotificationService + IDateTime DI + 2-stage. `BudgetDepartmentApprovalFeatures.cs` + endpoint + FE `BudgetWorkflowPanel` section.
|
||||
- ✅ **6 test PE 2-stage** — `IdentityFixture` setup full Identity stack (DbContext SQLite + AddIdentityCore + AddRoles<Role>) reusable. 6 scenario: NV_Review_Blocks / TPB_Confirm_Allows / NV_Bypass / Admin_Skip / Reject_Sets / Resume_Jumps_Back.
|
||||
- ✅ **Verify**: Build pass + 83 test pass mỗi commit (54 Domain + 29 Infra: 17 codegen + 6 PE WF Application + 6 PE 2-stage).
|
||||
- ✅ **5 commit pushed** Gitea (E2 → E6).
|
||||
|
||||
## ⚠️ CẢNH BÁO session tiếp (Session 10+)
|
||||
|
||||
1. **UAT live ngay** với anh Kiệt + 2-3 user — feature 2-stage đầy đủ cả 3 module + UX.
|
||||
2. **Tests Contract + Budget 2-stage skipped** — logic identical PE (cùng pattern, cùng entity shape). Pattern `PeTwoStageApprovalTests` reusable nếu UAT phát hiện regression riêng.
|
||||
3. **Bypass toggle audit** — chưa log Changelog khi admin toggle CanBypassReview. Audit qua Identity standard column UpdatedAt only. Có thể cần thêm audit row riêng nếu UAT yêu cầu.
|
||||
4. **Notify TPB cùng dept** dùng `UserManager.GetRolesAsync` filter `DeptManager` — verify production có user role DeptManager đúng (data already seeded).
|
||||
5. **fe-user KHÔNG có UsersPage** — admin-only function. Bypass toggle chỉ ở fe-admin.
|
||||
6. **3 endpoint mới List dept-approvals** PE/HĐ/Budget cùng pattern, reuse policy authz `*Read`.
|
||||
7. **Cron audit định kỳ 2026-05-01** vẫn EMPTY (`No scheduled jobs`). Có thể recreate khi user yêu cầu.
|
||||
|
||||
## TL;DR Session 8 (04/05 — code lớn, 5 commit per-chunk)
|
||||
|
||||
## TL;DR Session 8 (04/05 — code lớn, 5 commit per-chunk)
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
> **Update rule:** trước khi bắt đầu 1 task → ghi row vào `🔥 In Progress`. Xong → chuyển sang `✅ Recently Done`.
|
||||
|
||||
**Last updated:** 2026-05-04 (Session 8 — **2-stage department approval + smart reject + lock edit guards (Migration 16). Đóng bug anh Kiệt báo: NV duyệt được hết phase PE workflow.**)
|
||||
**Last updated:** 2026-05-04 (Session 9 — **Chunk E-bis complete: FE 2-stage panel cả 3 module + bypass toggle + HĐ/Budget 2-stage mirror PE + 6 test 2-stage + IdentityFixture helper.**)
|
||||
|
||||
## 📍 Phase hiện tại: **Phase 9 active — UAT + Ops + 2-stage dept approval** — **55 DB tables (52+3), 16 migrations, ~131 API endpoints (+3 dept-approvals/bypass-review), 31 FE pages (FE 2-stage chưa update). 77 unit test pass** (54 Domain + 23 Infra). 41 gotcha. 30 demo user. 6 skill.
|
||||
## 📍 Phase hiện tại: **Phase 9 active — UAT** — **55 DB tables, 16 migrations, ~133 API endpoints (+2 List dept-approvals HĐ/Budget), 31 FE pages (3 panel update 2-stage). 83 unit test pass** (54 Domain + 29 Infra: 17 codegen + 6 PE WF + 6 2-stage). 41 gotcha. 30 demo user. 6 skill.
|
||||
|
||||
### 🌐 Production URLs
|
||||
|
||||
@ -44,13 +44,13 @@
|
||||
- [ ] **Phase 4** — API smoke tests qua WebApplicationFactory ~7 test
|
||||
- [ ] **Phase 5** — FE Vitest cho lib utility (queryMatches, fmtMoney) ~10 test
|
||||
|
||||
### E. 2-stage dept approval — Chunk E-bis (FE + extend)
|
||||
### E. 2-stage dept approval — Chunk E-bis ✅ DONE (Session 9)
|
||||
|
||||
- [ ] **FE Workflow Panel update** (cả fe-admin + fe-user) — hiển thị progress 2-stage timeline per phase × dept. Dùng endpoint `GET /pe/{id}/department-approvals`.
|
||||
- [ ] **FE UserManager toggle** `CanBypassReview` checkbox per user. Endpoint `PATCH /users/{id}/bypass-review` đã sẵn.
|
||||
- [ ] **HĐ 2-stage** mở rộng: `ContractWorkflowService.TransitionAsync` thêm 2-stage logic + endpoint List `ContractDepartmentApprovals` (sau verify PE OK).
|
||||
- [ ] **Budget 2-stage** mở rộng tương tự (low priority, ít user duyệt budget per dept).
|
||||
- [ ] **Tests Phase 3 mini** cho 2-stage logic ở `PurchaseEvaluationWorkflowService` (cần UserManager DI helper).
|
||||
- [x] **FE Workflow Panel** PE — section "Tiến trình duyệt 2-cấp phòng ban" group by phase × dept, highlight amber khi chờ TPB confirm
|
||||
- [x] **FE UserManager toggle** `CanBypassReview` — column "Bypass" badge fuchsia + button toggle ShieldCheck (UsersPage)
|
||||
- [x] **HĐ 2-stage** mở rộng — `ContractWorkflowService` thêm UserManager DI + 2-stage logic mirror PE + `ContractDepartmentApprovalFeatures.cs` + endpoint `GET /contracts/{id}/department-approvals` + FE WorkflowHistoryPanel section mới
|
||||
- [x] **Budget 2-stage** mở rộng — `TransitionBudgetCommandHandler` thêm INotificationService + IDateTime + 2-stage logic + `BudgetDepartmentApprovalFeatures.cs` + endpoint + FE BudgetWorkflowPanel section
|
||||
- [x] **Tests 2-stage** (6 test) — `IdentityFixture` setup full Identity stack + 6 test PE workflow service: NV review block / TPB confirm allow / NV bypass / Admin skip / Reject set / Resume jump-back. Pattern reusable.
|
||||
|
||||
### F. Audit định kỳ (cron tự fire)
|
||||
|
||||
@ -60,6 +60,7 @@
|
||||
|
||||
| Ngày | Ai | Task | Commit |
|
||||
|---|---|---|---|
|
||||
| 2026-05-04 | Claude | **Session 9 — Chunk E-bis complete: FE 2-stage panel + UserManager bypass toggle + HĐ/Budget 2-stage mirror PE + 6 test + IdentityFixture** — User chỉ thị "làm hết cho xong tính năng luôn". 5 chunk per-commit (build + 83 test pass mỗi chunk): (E2) FE PeWorkflowPanel section "Tiến trình duyệt 2-cấp phòng ban" group by phase × dept, highlight amber chờ TPB, badge fuchsia bypass — cả 2 app (rule §3.9). (E3) FE UsersPage column "Bypass" + ShieldCheck toggle button + UserDto.CanBypassReview field. (E4) ContractWorkflowService thêm UserManager DI + mirror 2-stage logic từ PE + `ContractDepartmentApprovalFeatures.cs` (List query) + endpoint `GET /contracts/{id}/department-approvals` + FE WorkflowHistoryPanel section. (E5) Budget mirror đầy đủ — `TransitionBudgetCommandHandler` thêm INotificationService + IDateTime DI + 2-stage logic + `BudgetDepartmentApprovalFeatures.cs` + endpoint + FE BudgetWorkflowPanel. (E6) `IdentityFixture` setup ServiceProvider với Identity stack đầy đủ (DbContext SQLite + AddIdentityCore + AddRoles<Role> + EF stores) + 6 test PE 2-stage: NV_Review_Blocks / TPB_Confirm_Allows / NV_Bypass / Admin_Skip / Reject_Sets_RejectedFromPhase / Resume_Jumps_Back. Tests Contract + Budget skip vì logic identical PE, ROI thấp. **Total 77→83 test pass.** 5 commit pushed lên Gitea. | `f8eebd5` (E2) · `4380bdc` (E3) · `b6f5a16` (E4) · `1fc439b` (E5) · `8353fe8` (E6) · (current E7) |
|
||||
| 2026-05-04 | Claude | **Session 8 — Migration 16: 2-stage dept approval + smart reject + lock edit (đóng bug anh Kiệt)** — Anh Kiệt báo: NV.PRO tạo phiếu PE → duyệt được hết phase = phân quyền sai. Schema mới: 3 bảng `*DepartmentApprovals` (Contract/PE/Budget) UNIQUE (TargetId, Phase, Dept, Stage). 4 cột mới: `Users.CanBypassReview` bit + 3 `RejectedFromPhase` int. Logic 2-stage trong `PurchaseEvaluationWorkflowService.TransitionAsync`: user.DepartmentId != null → DeptManager (TPB) Stage=Confirm; CanBypassReview=true → Stage=Confirm+IsBypassed; else NV → Stage=Review only, BLOCK transition cho đến khi TPB confirm. Smart reject: Decision=Reject → set RejectedFromPhase, force về DangSoanThao. Resume sau reject: Drafter trình lại từ DangSoanThao + RejectedFromPhase != null → jump straight tới phase đã reject (skip phase trung gian). Lock edit: 17 handler thêm guard Phase != DangSoanThao (Contract Detail × 15, PE Detail × 5, Budget Detail × 3). 3 endpoint mới: `GET /pe/{id}/department-approvals` (FE Workflow Panel hiển thị progress) + `PATCH /users/{id}/bypass-review` (admin toggle) + Notify TPB cùng dept khi NV review. **HĐ + Budget 2-stage scope defer** (chỉ PE first đóng bug). FE update + Tests defer Chunk E-bis. | `5fe61cc` (A) · `14f3c9f` (B) · `9747f8c` (C) · `a532ba6` (D) · (current) |
|
||||
| 2026-04-30 | Claude | **Session 6 — MD audit + compact + 3 skill refresh + 2 rule mới** — Compact 3 file core (-288 dòng): STATUS -27%, HANDOFF -32%, migration-todos -35%. Archive 51 row Recently Done Phase 0-7 → `changelog/recently-done-archive-2026-04.md`. Refresh 3 skill stale: `form-engine` (Phase 2 MVP → Tier 3 feature-complete + bỏ section duplicate gen mã HĐ), `permission-matrix` (12 menu → ~60 menu key + Bg_*/Pe_*/PeWf_* + inheritance roots), `ef-core-migration` (24 DbSet → 52 bảng + ERD update). Rule mới `rules.md §7 Khi nào viết test — timing rule` (5-row table compact, sau khi rút gọn từ 70 dòng overkill). Rule mới `rules.md §6.4 Audit + compact MD định kỳ` (cadence + checklist + anti-pattern, KHÔNG rewrite toàn bộ). `rules.md §9.4 Skill audit` mở rộng cross-ref §6.4. | (current) |
|
||||
| 2026-04-29 | Claude | **Tests Phase 3 mini + 3 gotcha CI mới (#39 #40 #41)** — `tests/.../Application/PeWorkflowAdminTests.cs` 6 test versioning logic (CreatePeWorkflowDefinition: first version IsActive=true, second deactivates first, different EvaluationType independent, persists steps ordered + approvers per step, third version increments to v3). Total **77 test** (54 Domain + 17 Infra + 6 PE WF Application). Gotcha #39 act_runner github.com TCP timeout 21s + manual checkout fix. #40 npm junction cache fail `tsc not found` rolled back. #41 paths-ignore behavior + workflow file exclusion. | `b874743` |
|
||||
|
||||
@ -157,6 +157,25 @@ Session log: `2026-04-28-chot-session-4-budget.md`.
|
||||
|
||||
## 📝 Phase 9 — UAT + Ops + carry over (Session 6+ active)
|
||||
|
||||
### ✅ Session 9 done (2026-05-04) — Chunk E-bis complete (FE 2-stage + HĐ/Budget mirror + 6 test)
|
||||
|
||||
User chỉ thị "làm hết cho xong tính năng luôn" sau Session 8 close bug fix anh Kiệt phía BE PE. Session 9 đóng toàn bộ pending Chunk E-bis (defer từ session 8).
|
||||
|
||||
- [x] **Chunk E2 — FE Workflow Panel PE** hiển thị progress 2-stage timeline per phase × dept (commit `f8eebd5`). Component `DeptApprovalsSection` group by phase × dept, highlight amber khi current phase có Review nhưng chưa Confirm, badge fuchsia "bypass" khi NV.CanBypassReview. Cả fe-admin + fe-user (rule §3.9).
|
||||
- [x] **Chunk E3 — FE UserManager toggle CanBypassReview** (commit `4380bdc`). UserDto BE thêm field `CanBypassReview`. UsersPage column "Bypass" + button ShieldCheck (icon highlight fuchsia khi enabled). Endpoint backend đã có sẵn từ Session 8 Chunk E1. fe-user KHÔNG có UsersPage (admin-only).
|
||||
- [x] **Chunk E4 — HĐ 2-stage logic mở rộng** (commit `b6f5a16`). ContractWorkflowService thêm `UserManager<User>` DI + mirror toàn bộ logic 2-stage từ PE service (sau policy guard, trước gen mã HĐ). ContractDepartmentApprovalFeatures.cs (List query mirror PE pattern). Endpoint `GET /contracts/{id}/department-approvals`. FE WorkflowHistoryPanel section "Tiến trình duyệt 2-cấp phòng ban" insert giữa WorkflowSummaryCard và Lịch sử duyệt.
|
||||
- [x] **Chunk E5 — Budget 2-stage logic mở rộng** (commit `1fc439b`). TransitionBudgetCommandHandler thêm `INotificationService` + `IDateTime` DI + mirror 2-stage logic. BudgetDepartmentApprovalFeatures.cs + endpoint. FE BudgetWorkflowPanel section "Tiến trình duyệt 2-cấp phòng ban". Note: low-priority cho Budget (ít user duyệt budget per dept) nhưng giữ consistent UX 3 module.
|
||||
- [x] **Chunk E6 — 6 test 2-stage + IdentityFixture helper** (commit `8353fe8`). IdentityFixture (Common/) setup ServiceProvider với Identity stack đầy đủ — DbContext SQLite shared connection + AddIdentityCore<User> + AddRoles<Role> + AddEntityFrameworkStores. Single shared scope cho fixture lifetime đảm bảo DbContext + UserManager đồng instance. Helper `CreateUserAsync(email, name, deptId, roles, canBypassReview)` reusable. 6 test PeTwoStageApprovalTests: NV_Review_Blocks_Phase_Transition (đóng bug anh Kiệt — test chính xác) / TPB_Confirm_After_NV_Review_Allows_Transition / NV_With_BypassReview_Allows_Transition_With_IsBypassed_True / Admin_Skips_TwoStage_Logic_Entirely / Reject_Sets_RejectedFromPhase_And_Forces_DangSoanThao / Resume_After_Reject_Jumps_Back_To_RejectedPhase. Tests Contract + Budget 2-stage skipped — logic identical PE, ROI thấp; pattern reusable nếu UAT phát hiện regression riêng. **Total 77→83 test pass**.
|
||||
|
||||
Stats sau session 9:
|
||||
- BE LOC: ~13750 → ~14400 (+650, gồm Contract + Budget 2-stage logic + 2 List feature + Test fixture)
|
||||
- API endpoints: ~131 → ~133 (+2 List dept-approvals HĐ/Budget)
|
||||
- Tests: 77 → **83** (+6 PE 2-stage)
|
||||
- Schema không đổi (Migration 16 đã có sẵn từ session 8)
|
||||
- 5 commit per-chunk pushed → 1 CI run trigger qua HEAD = `8353fe8`
|
||||
|
||||
Pending còn lại Phase 9: chỉ Hard blockers Ops (UAT thật / SMTP / Rotate creds / SQL backup). Feature 2-stage đầy đủ.
|
||||
|
||||
### ✅ Session 8 done (2026-05-04) — Migration 16: 2-stage dept approval + smart reject + lock edit
|
||||
|
||||
**Bối cảnh:** Anh Kiệt (FDC) báo bug PE workflow: NV.PRO tạo phiếu → duyệt được hết phase. Phân quyền sai vì policy chỉ check role, không check Stage 2-cấp.
|
||||
@ -179,12 +198,12 @@ Session log: `2026-04-28-chot-session-4-budget.md`.
|
||||
|
||||
Session log: `2026-05-04-1230-chot-session-8-2-stage-dept-approval.md`.
|
||||
|
||||
**Pending Chunk E-bis (defer):**
|
||||
- [ ] FE Workflow Panel hiển thị progress 2-stage timeline
|
||||
- [ ] FE UserManager toggle `CanBypassReview` checkbox
|
||||
- [ ] HĐ 2-stage mở rộng (`ContractWorkflowService` thêm 2-stage logic + endpoint List)
|
||||
- [ ] Budget 2-stage mở rộng (low priority)
|
||||
- [ ] Tests 2-stage logic Service-layer (cần UserManager DI helper)
|
||||
**Pending Chunk E-bis** ✅ TẤT CẢ DONE ở Session 9 (xem section trên):
|
||||
- [x] FE Workflow Panel hiển thị progress 2-stage timeline (E2 — PE) + HĐ (E4) + Budget (E5)
|
||||
- [x] FE UserManager toggle `CanBypassReview` checkbox (E3)
|
||||
- [x] HĐ 2-stage mở rộng (E4)
|
||||
- [x] Budget 2-stage mở rộng (E5)
|
||||
- [x] Tests 2-stage logic Service-layer (E6 — 6 test PE + IdentityFixture)
|
||||
|
||||
### ✅ Session 6 done (2026-04-30 — pure docs work)
|
||||
|
||||
|
||||
@ -0,0 +1,319 @@
|
||||
# Session log — 2026-05-04 chốt session 9 — Chunk E-bis complete
|
||||
|
||||
**Topic:** User chỉ thị "làm hết cho xong tính năng luôn đi nhé" sau Session 8 đóng bug PE 2-stage. Session 9 close toàn bộ Chunk E-bis defer (FE 2-stage panel cả 3 module + UserManager bypass toggle + HĐ + Budget 2-stage mirror PE + 6 test 2-stage + IdentityFixture helper).
|
||||
|
||||
**Dev:** Claude (Opus 4.7) + user (pqhuy1987@gmail.com)
|
||||
**Duration:** ~3 giờ (gồm Chunk E2-E7 + verify build/test/push).
|
||||
**Base commit:** `d206e14` (chốt session 8 ending — patch count drift + skill refresh).
|
||||
|
||||
## Bối cảnh
|
||||
|
||||
Sau Session 8, BE PE 2-stage approval đã live trên prod (https://api.solutions.com.vn). Anh Kiệt FDC có thể test bug fix. Tuy nhiên còn pending:
|
||||
|
||||
- FE Workflow Panel chưa hiển thị 2-stage progress → user thấy "stuck" mà không hiểu
|
||||
- FE UserManager chưa có toggle CanBypassReview → admin phải PATCH qua Postman
|
||||
- HĐ + Budget 2-stage scope **defer** từ Session 8 (chỉ áp PE)
|
||||
- Tests 2-stage Service-layer chưa có (cần UserManager DI helper)
|
||||
|
||||
User chỉ thị "làm hết cho xong tính năng luôn" → close toàn bộ Chunk E-bis.
|
||||
|
||||
## Approach
|
||||
|
||||
Per-chunk commit pattern (Session 8 đã proven). 5 chunk small (mỗi <300 LOC change), build + test pass mỗi chunk:
|
||||
|
||||
- E2 — FE PE WorkflowPanel 2-stage timeline
|
||||
- E3 — FE UsersPage CanBypassReview toggle
|
||||
- E4 — HĐ 2-stage logic + endpoint + FE
|
||||
- E5 — Budget 2-stage logic + endpoint + FE
|
||||
- E6 — Tests + IdentityFixture
|
||||
- E7 — Docs update + commit + push
|
||||
|
||||
## Commits session 9
|
||||
|
||||
5 commit code + 1 commit docs ending:
|
||||
|
||||
- `f8eebd5` — E2: FE PE 2-stage timeline cả 2 app
|
||||
- `4380bdc` — E3: FE UserManager bypass toggle
|
||||
- `b6f5a16` — E4: HĐ 2-stage mirror PE
|
||||
- `1fc439b` — E5: Budget 2-stage mirror PE
|
||||
- `8353fe8` — E6: 6 test 2-stage + IdentityFixture
|
||||
- (current) — E7: Docs + session log
|
||||
|
||||
## E2 — FE PE WorkflowPanel 2-stage timeline
|
||||
|
||||
### Frontend (cả fe-admin + fe-user)
|
||||
|
||||
```typescript
|
||||
// types/purchaseEvaluation.ts:
|
||||
export const ApprovalStage = { Review: 1, Confirm: 2 } as const
|
||||
export type PeDepartmentApproval = {
|
||||
id: string; phaseAtApproval: number; departmentId: string
|
||||
departmentName: string | null; stage: number
|
||||
approverUserId: string; approverName: string | null
|
||||
approverRoleSnapshot: string | null // "TPB" | "NV" | "NV(bypass)"
|
||||
comment: string | null; approvedAt: string; isBypassed: boolean
|
||||
}
|
||||
|
||||
// PeWorkflowPanel.tsx:
|
||||
const { data: deptApprovals = [] } = useQuery<PeDepartmentApproval[]>({
|
||||
queryKey: ['pe-dept-approvals', evaluation.id],
|
||||
queryFn: async () => (await api.get(`/purchase-evaluations/${id}/department-approvals`)).data,
|
||||
})
|
||||
```
|
||||
|
||||
### DeptApprovalsSection component
|
||||
|
||||
Group by phase × dept. Render 2 row per dept:
|
||||
- **Review NV** (slate text) — ✓ tên + thời gian + comment
|
||||
- **Confirm TPB** (emerald hoặc amber) — ✓ hoặc "⏳ chờ TPB confirm"
|
||||
|
||||
Highlight border amber khi `phase === currentPhase && review && !confirm` → user biết "đang chờ TPB confirm".
|
||||
|
||||
Badge fuchsia "bypass" khi `isBypassed=true`.
|
||||
|
||||
Invalidate query sau transition mutation để refresh ngay.
|
||||
|
||||
## E3 — FE UsersPage CanBypassReview toggle
|
||||
|
||||
### Backend UserDto extend
|
||||
|
||||
```csharp
|
||||
// UserFeatures.cs
|
||||
public record UserDto(
|
||||
Guid Id, string Email, string FullName, bool IsActive, bool IsLocked,
|
||||
DateTime CreatedAt, List<string> Roles, Guid? DepartmentId,
|
||||
string? DepartmentName, string? Position,
|
||||
bool CanBypassReview); // NEW
|
||||
```
|
||||
|
||||
ListUsers + GetUser handler đều thêm `u.CanBypassReview` vào DTO instantiation.
|
||||
|
||||
### Frontend UsersPage
|
||||
|
||||
```tsx
|
||||
// types/users.ts
|
||||
export type User = { ...; canBypassReview: boolean }
|
||||
|
||||
// UsersPage.tsx column "Bypass":
|
||||
{ key: 'canBypassReview', header: 'Bypass', width: 'w-20', align: 'center',
|
||||
render: u => u.canBypassReview ? (
|
||||
<span className="rounded bg-fuchsia-100 ... text-fuchsia-700">
|
||||
<ShieldCheck /> bypass
|
||||
</span>
|
||||
) : <span className="text-slate-400">—</span> }
|
||||
|
||||
// Action button toggle:
|
||||
const bypassMut = useMutation({
|
||||
mutationFn: (u: User) =>
|
||||
api.patch(`/users/${u.id}/bypass-review`,
|
||||
{ canBypassReview: !u.canBypassReview }),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['users'] }),
|
||||
})
|
||||
|
||||
<Button onClick={() => bypassMut.mutate(u)}>
|
||||
<ShieldCheck className={u.canBypassReview ? 'text-fuchsia-600' : 'text-slate-400'} />
|
||||
</Button>
|
||||
```
|
||||
|
||||
Endpoint backend `PATCH /users/{id}/bypass-review` đã sẵn từ Session 8 Chunk E1. Chỉ wire FE.
|
||||
|
||||
fe-user KHÔNG có UsersPage (admin-only function) — chỉ update fe-admin.
|
||||
|
||||
## E4 — HĐ 2-stage logic mở rộng
|
||||
|
||||
### ContractWorkflowService
|
||||
|
||||
Thêm `UserManager<User>` DI:
|
||||
|
||||
```csharp
|
||||
public class ContractWorkflowService(
|
||||
IApplicationDbContext db,
|
||||
IContractCodeGenerator codeGenerator,
|
||||
IDateTime dateTime,
|
||||
INotificationService notifications,
|
||||
IChangelogService changelog,
|
||||
UserManager<User> userManager) : IContractWorkflowService
|
||||
```
|
||||
|
||||
Mirror toàn bộ logic 2-stage từ `PurchaseEvaluationWorkflowService.TransitionAsync`. Inject sau policy guard, trước gen mã HĐ:
|
||||
|
||||
```csharp
|
||||
if (decision == ApprovalDecision.Approve
|
||||
&& targetPhase != ContractPhase.DangSoanThao
|
||||
&& targetPhase != ContractPhase.TuChoi
|
||||
&& !isResumingAfterReject
|
||||
&& !isAdmin && !isSystem
|
||||
&& actorUserId is Guid actorUid)
|
||||
{
|
||||
var actor = await userManager.FindByIdAsync(actorUid.ToString());
|
||||
if (actor?.DepartmentId is Guid deptId)
|
||||
{
|
||||
var isManager = actorRoles.Contains(AppRoles.DeptManager);
|
||||
var canBypass = actor.CanBypassReview;
|
||||
var stage = (isManager || canBypass) ? Confirm : Review;
|
||||
// ... upsert ContractDepartmentApproval, check hasConfirm, BLOCK nếu chưa
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ContractDepartmentApprovalFeatures.cs (List query)
|
||||
|
||||
Mirror PE pattern. Join với Departments + Users (separate query) để denorm name.
|
||||
|
||||
### Endpoint
|
||||
|
||||
```http
|
||||
GET /api/contracts/{id}/department-approvals
|
||||
[Authorize(Policy = "Contracts.Read")] // qua [Authorize] trên controller class
|
||||
```
|
||||
|
||||
### FE WorkflowHistoryPanel
|
||||
|
||||
Section `DeptApprovalsSection` insert giữa `WorkflowSummaryCard` và "Lịch sử duyệt". Cùng pattern PE — group by phase × dept, highlight amber, badge fuchsia.
|
||||
|
||||
## E5 — Budget 2-stage mirror PE/Contract
|
||||
|
||||
### TransitionBudgetCommandHandler
|
||||
|
||||
Thêm 2 dependency mới: `INotificationService` + `IDateTime`. Mirror toàn bộ logic 2-stage. Note: Budget low-priority (ít user duyệt budget per dept) nhưng giữ consistent UX 3 module.
|
||||
|
||||
### BudgetDepartmentApprovalFeatures.cs
|
||||
|
||||
List query mirror PE/Contract pattern.
|
||||
|
||||
### Endpoint + FE
|
||||
|
||||
`GET /api/budgets/{id}/department-approvals` + section trong `BudgetWorkflowPanel`.
|
||||
|
||||
## E6 — Tests + IdentityFixture
|
||||
|
||||
### IdentityFixture (Common/)
|
||||
|
||||
Setup ServiceProvider với Identity stack đầy đủ. Key insight: dùng `Role` custom (extend `IdentityRole<Guid>`) thay vì `IdentityRole<Guid>` plain — match `ApplicationDbContext : IdentityDbContext<User, Role, Guid>`.
|
||||
|
||||
```csharp
|
||||
services.AddScoped<ApplicationDbContext>(_ =>
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseSqlite(connection).EnableSensitiveDataLogging().Options;
|
||||
return new TestApplicationDbContext(options);
|
||||
});
|
||||
services.AddScoped<TestApplicationDbContext>(sp =>
|
||||
(TestApplicationDbContext)sp.GetRequiredService<ApplicationDbContext>());
|
||||
|
||||
services.AddIdentityCore<User>(...)
|
||||
.AddRoles<Role>() // ← KEY: Role không IdentityRole<Guid>
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||
|
||||
_root = services.BuildServiceProvider();
|
||||
Services = _root.CreateScope().ServiceProvider; // single shared scope
|
||||
```
|
||||
|
||||
Helper `CreateUserAsync(email, name, deptId, roles, canBypassReview)` reusable cho tests sau.
|
||||
|
||||
### 6 test PeTwoStageApprovalTests
|
||||
|
||||
| Test | Scenario | Expected |
|
||||
|---|---|---|
|
||||
| `NV_Review_Blocks_Phase_Transition` | NV.PRO approve phase ChoPurchasing | Phase **không đổi**, 1 row Stage=Review, 1 PE Approval `[Review NV]` |
|
||||
| `TPB_Confirm_After_NV_Review_Allows_Transition` | NV review → TPB confirm | Phase chuyển ChoCCM, 2 rows (Review + Confirm) |
|
||||
| `NV_With_BypassReview_Allows_Transition_With_IsBypassed_True` | NV.CanBypassReview=true approve | Phase chuyển, 1 row Stage=Confirm + IsBypassed=true |
|
||||
| `Admin_Skips_TwoStage_Logic_Entirely` | Admin role approve | Phase chuyển, **0 row** DepartmentApprovals |
|
||||
| `Reject_Sets_RejectedFromPhase_And_Forces_DangSoanThao` | TPB reject từ ChoCCM | Phase=DangSoanThao, RejectedFromPhase=ChoCCM |
|
||||
| `Resume_After_Reject_Jumps_Back_To_RejectedPhase` | Admin resume từ DangSoanThao + RejectedFromPhase=ChoCCM | Phase jump tới ChoCCM (không phải target ChoPurchasing), RejectedFromPhase=null |
|
||||
|
||||
Stub `FakeNotificationService` — best effort path không cần verify.
|
||||
|
||||
Tests Contract + Budget 2-stage **skip** — logic identical PE, ROI thấp. Pattern reusable nếu UAT phát hiện regression riêng.
|
||||
|
||||
## Verify
|
||||
|
||||
```
|
||||
✓ Build pass mỗi commit (2 warning DocxRenderer cũ — không liên quan)
|
||||
✓ 83 unit test pass mỗi commit (54 Domain + 29 Infra)
|
||||
- Trước: 77 (54 + 17 + 6)
|
||||
- Sau: 83 (54 + 17 + 6 + 6 PE 2-stage)
|
||||
✓ FE build pass cả 2 app mỗi chunk có FE change
|
||||
✓ TS strict mode + erasableSyntaxOnly check pass
|
||||
```
|
||||
|
||||
## Files touched session 9
|
||||
|
||||
```
|
||||
fe-admin/src/types/purchaseEvaluation.ts (mod)
|
||||
fe-admin/src/components/pe/PeWorkflowPanel.tsx (mod)
|
||||
fe-admin/src/types/users.ts (mod)
|
||||
fe-admin/src/pages/system/UsersPage.tsx (mod)
|
||||
fe-admin/src/types/contracts.ts (mod)
|
||||
fe-admin/src/components/contracts/WorkflowHistoryPanel.tsx (mod)
|
||||
fe-admin/src/types/budget.ts (mod)
|
||||
fe-admin/src/components/budgets/BudgetWorkflowPanel.tsx (mod)
|
||||
|
||||
fe-user/src/types/purchaseEvaluation.ts (mod, sync)
|
||||
fe-user/src/components/pe/PeWorkflowPanel.tsx (mod, sync)
|
||||
fe-user/src/types/contracts.ts (mod, sync)
|
||||
fe-user/src/components/contracts/WorkflowHistoryPanel.tsx (mod, sync)
|
||||
fe-user/src/types/budget.ts (mod, sync)
|
||||
fe-user/src/components/budgets/BudgetWorkflowPanel.tsx (mod, sync)
|
||||
|
||||
src/Backend/SolutionErp.Application/Users/UserFeatures.cs (mod: +CanBypassReview field DTO)
|
||||
src/Backend/SolutionErp.Application/Contracts/ContractDepartmentApprovalFeatures.cs (NEW)
|
||||
src/Backend/SolutionErp.Application/Budgets/BudgetDepartmentApprovalFeatures.cs (NEW)
|
||||
src/Backend/SolutionErp.Application/Budgets/BudgetFeatures.cs (mod: +2-stage logic + DI)
|
||||
|
||||
src/Backend/SolutionErp.Infrastructure/Services/ContractWorkflowService.cs (mod: +UserManager DI + 2-stage)
|
||||
|
||||
src/Backend/SolutionErp.Api/Controllers/ContractsController.cs (mod: +1 endpoint)
|
||||
src/Backend/SolutionErp.Api/Controllers/BudgetsController.cs (mod: +1 endpoint)
|
||||
|
||||
tests/SolutionErp.Infrastructure.Tests/Common/IdentityFixture.cs (NEW)
|
||||
tests/SolutionErp.Infrastructure.Tests/Services/PeTwoStageApprovalTests.cs (NEW)
|
||||
|
||||
docs/STATUS.md (mod)
|
||||
docs/HANDOFF.md (mod)
|
||||
docs/changelog/migration-todos.md (mod)
|
||||
docs/CLAUDE.md (mod)
|
||||
CLAUDE.md (mod: 77→83 test)
|
||||
docs/changelog/sessions/2026-05-04-1700-chot-session-9-*.md (NEW: file này)
|
||||
```
|
||||
|
||||
## Cảnh báo session 10+
|
||||
|
||||
1. **UAT live ngay** với anh Kiệt + 2-3 user — feature 2-stage đầy đủ cả 3 module + UX panel + bypass toggle.
|
||||
2. **Tests Contract + Budget skipped** — logic identical PE. Pattern `PeTwoStageApprovalTests` reusable.
|
||||
3. **Bypass toggle audit** — chưa log Changelog khi admin toggle CanBypassReview. Có thể cần thêm audit row riêng nếu UAT yêu cầu.
|
||||
4. **Notify TPB cùng dept** dùng UserManager filter DeptManager — verify production user có role đúng.
|
||||
5. **fe-user KHÔNG có UsersPage** — admin-only function, bypass toggle chỉ ở fe-admin.
|
||||
6. **3 endpoint mới** PE + HĐ + Budget List dept-approvals cùng pattern, reuse policy `*.Read` qua [Authorize] class-level.
|
||||
7. **Cron audit định kỳ** vẫn EMPTY (`No scheduled jobs`) — recreate khi user yêu cầu.
|
||||
|
||||
## Lessons learned
|
||||
|
||||
1. **Mirror logic chuẩn xác giảm bug** — Contract + Budget 2-stage clone pattern PE service y nguyên (chỉ thay entity/enum names) → giảm rủi ro logic divergent. Future refactor có thể extract thành `IDepartmentApprovalGuard<TEntity, TPhase>` nếu pattern lặp lần thứ 4.
|
||||
|
||||
2. **IdentityFixture investment trade-off** — setup tốn 30-45 phút (struggle với DbContext options + Role custom type), nhưng future tests (Application handler tests) sẽ reuse được. ROI dài hạn dương.
|
||||
|
||||
3. **Single shared scope** trong fixture quan trọng — UserManager + DbContext cần đồng instance để CreateAsync persist data nhìn thấy được trong service test sau đó. Nếu mỗi resolve scope mới → DbContext khác → data invisible cross calls.
|
||||
|
||||
4. **`Role` custom subclass** — match exactly với `IdentityDbContext<User, Role, Guid>`. Pass `IdentityRole<Guid>` → `RoleStore` query DbSet không tồn tại → `EntityType not found` lỗi tinh quái khó debug.
|
||||
|
||||
5. **fe-user duplicate file pattern §3.9** — cp file giữa 2 app sau khi edit fe-admin xong. Đỡ phải edit 2 lần. Diff trước cp để verify identical.
|
||||
|
||||
6. **User chỉ thị "làm hết cho xong"** = open license cho per-chunk commit + push final. Giữ pattern Session 8 (5 chunk + verify mỗi chunk) tránh monolithic commit khó debug.
|
||||
|
||||
## Stats sau session 9
|
||||
|
||||
| | Trước S9 | Sau S9 |
|
||||
|---|---:|---:|
|
||||
| BE LOC | ~13750 | ~14400 (+650) |
|
||||
| DB tables | 55 | 55 (không đổi) |
|
||||
| Migrations | 16 | 16 (không đổi) |
|
||||
| API endpoints | ~131 | **~133** (+2 List dept-approvals HĐ/Budget) |
|
||||
| FE pages | ~31 | ~31 (không đổi, chỉ component panel update) |
|
||||
| FE components | — | +DeptApprovalsSection × 3 panel + bypass column UsersPage |
|
||||
| Tests | 77 | **83** (+6 PE 2-stage) |
|
||||
| Test fixtures | SqliteDbFixture | + IdentityFixture (reusable) |
|
||||
| Gotchas | 41 | 41 (không có gotcha mới đáng ghi) |
|
||||
| Demo user | 30 | 30 |
|
||||
| Commits S9 | 0 | **5** (E2-E6) + docs E7 |
|
||||
| Session log | 19 | **20** |
|
||||
Reference in New Issue
Block a user