Files
alla-tms/plans/approval-workflow.md
2026-07-16 09:53:14 +07:00

1109 lines
10 KiB
Markdown

# Prompt: Implement Approval Workflow for Online Lessons & Announcements
## Objective
ออกแบบและพัฒนาระบบ Approval Workflow สำหรับ
- Online Lessons
- Announcements
โดยใช้ Workflow เดียวกันทั้งสอง Module
Workflow นี้ต้องรองรับ
- Draft
- Submit for Review
- Review
- Approve
- Publish
- Reject
- Return for Revision
และทำงานตาม Permission ของผู้ใช้งาน
---
# Background
ปัจจุบัน Staff สามารถสร้างบทเรียนออนไลน์และประกาศได้
แต่ยังไม่มี Approval Workflow
ระบบต้องเปลี่ยนเป็น
Staff
สร้างข้อมูล
ส่งตรวจสอบ
Manager / IT Admin ตรวจสอบ
อนุมัติ
เผยแพร่
โดยห้ามเผยแพร่ได้ทันที
---
# IMPORTANT
ก่อนแก้ไข
AI ต้องตรวจสอบ Architecture เดิมของ Project ก่อน
ต้อง Audit
- Existing Status
- Existing Permission
- Existing Workflow
- Existing Components
- Existing API
- Existing Validation
ห้ามสร้าง Pattern ใหม่ หากระบบมี Pattern อยู่แล้ว
ต้อง Reuse
- Shared Dialog
- Shared Form
- Shared Badge
- Shared Table
- Shared Status Component
- Shared Permission Helper
- Shared Audit
- Shared Notification
- Shared Toast
- Shared Query Pattern
---
# Scope
ครอบคลุม Module
- Online Lessons
- Announcements
ทั้ง
Frontend
Backend
Database
Workflow
Permission
Notification
Audit
Testing
Documentation
---
# Phase 0 — Architecture Audit
ก่อนแก้ไข
ตรวจสอบ
## Database
ตรวจสอบ Model
OnlineLesson
Announcement
ว่ามี field
เช่น
```
status
publishedAt
approvedAt
approvedBy
reviewedBy
```
อยู่แล้วหรือไม่
ห้ามเดา
อ้างอิงจาก Schema จริง
---
## Frontend
ตรวจสอบ
- Create Form
- Edit Form
- List
- Detail
- Badge
- Action Menu
---
## Backend
ตรวจสอบ
- Route Handler
- Server Action
- Service
- Validation
- Query
---
## Permission
ตรวจสอบว่า
Project ใช้
Permission Template First
หรือ
Business Role
หรือ Compatibility Mode
หากมี Permission แล้ว
ห้ามใช้
```
isHRD()
businessRole
```
---
# Phase 1 — Workflow Design
Workflow ใหม่
```
Draft
Pending Review
Approved
Published
```
หรือ
```
Draft
Pending Review
Rejected
```
หรือ
```
Draft
Pending Review
Returned For Revision
Draft
Pending Review
```
Workflow Diagram
```
Create
Save Draft
Submit For Review
Pending Review
Approve
Approved
Publish
Published
```
หรือ
```
Pending Review
Return For Revision
Draft
```
หรือ
```
Pending Review
Reject
```
---
# Status Design
ระบบต้องรองรับอย่างน้อย
```
DRAFT
PENDING_REVIEW
APPROVED
PUBLISHED
RETURNED
REJECTED
```
หากระบบมี Status เดิม
ให้ Reuse
ห้ามสร้าง Status ซ้ำ
---
# Phase 2 — Permission Matrix
## Staff
สามารถ
✅ Create
✅ Save Draft
✅ Edit Draft
✅ Delete Draft
✅ Submit For Review
❌ Approve
❌ Publish
❌ Reject
---
## Manager
สามารถ
✅ View Pending
✅ Approve
✅ Return
✅ Reject
✅ Publish
---
## IT Admin
สามารถ
ทำได้ทั้งหมด
รวมถึง
Approve
Publish
Return
Reject
Edit
Delete
Manage
---
## Super Admin
ทำได้ทั้งหมด
---
# Phase 3 — Create Page
Module
Online Lessons
หน้า
```
/dashboard/online-lessons/manage/new
```
ต้องปรับ
---
## Staff
ปุ่ม
เดิม
```
สร้างบทเรียน
```
เปลี่ยนเป็น
```
บันทึกฉบับร่าง
```
และ
```
ส่งตรวจสอบ
```
เมื่อกด
ส่งตรวจสอบ
Status
```
PENDING_REVIEW
```
---
## Manager / IT
สามารถ
```
บันทึกฉบับร่าง
```
หรือ
```
อนุมัติ
```
หรือ
```
เผยแพร่
```
ตาม Workflow
---
# Phase 4 — Review Page
สร้างหรือใช้หน้าปัจจุบัน
สำหรับ
```
Pending Review
```
ต้องแสดง
- Title
- Author
- Organization
- Created Date
- Status
Action
```
Approve
Return
Reject
```
---
# Approve
เมื่อกด
Approve
Status
```
APPROVED
```
ยังไม่เผยแพร่
---
# Publish
เมื่อกด
Publish
Status
```
PUBLISHED
```
และ
```
publishedAt
publishedBy
```
ต้องถูกบันทึก
---
# Return
เมื่อกด
Return
Status
```
RETURNED
```
ผู้สร้าง
สามารถ
Edit
แล้ว
Submit ใหม่
---
# Reject
Status
```
REJECTED
```
หาก Reject
ไม่สามารถ Publish ได้
จนกว่าจะถูกแก้ไขและ Submit ใหม่
---
# Phase 5 — Edit Rules
## Draft
Staff
แก้ไขได้
---
## Pending Review
Staff
แก้ไขไม่ได้
จนกว่า
Manager
จะ
Return
---
## Returned
Staff
แก้ไขได้
แล้ว
Submit ใหม่
---
## Approved
Manager
แก้ไขได้
IT
แก้ไขได้
---
## Published
แก้ไขได้เฉพาะ
Manager
IT
Super Admin
หากระบบรองรับ Versioning
ให้ใช้ Version เดิม
หากไม่มี
ให้ใช้ Current Version
---
# Phase 6 — UI
Badge
```
Draft
Pending Review
Approved
Published
Returned
Rejected
```
ใช้สีตาม Design System เดิม
---
Action Menu
แสดงตาม Permission
ตัวอย่าง
Staff
```
Edit
Delete
Submit
```
Manager
```
Approve
Return
Reject
Publish
```
---
# Phase 7 — Notification
เมื่อ
Submit
แจ้ง
Manager
IT
---
Approve
แจ้ง
Author
---
Publish
แจ้ง
Author
---
Return
แจ้ง
Author
พร้อม Comment
---
Reject
แจ้ง
Author
พร้อมเหตุผล
---
หากระบบมี
Email
In-App
Notification
ให้ Reuse
---
# Phase 8 — Comment
Manager
ต้องสามารถ
ใส่ Comment
ตอน
Approve
Return
Reject
Comment
ต้องถูกเก็บใน Database
พร้อม
User
Time
---
# Phase 9 — Audit Log
สร้าง Audit
เช่น
```
ONLINE_LESSON_SUBMITTED
ONLINE_LESSON_APPROVED
ONLINE_LESSON_RETURNED
ONLINE_LESSON_REJECTED
ONLINE_LESSON_PUBLISHED
```
Announcement
เช่น
```
ANNOUNCEMENT_SUBMITTED
ANNOUNCEMENT_APPROVED
ANNOUNCEMENT_RETURNED
ANNOUNCEMENT_REJECTED
ANNOUNCEMENT_PUBLISHED
```
Audit
ต้องเก็บ
- User
- Action
- Status Before
- Status After
- Comment
- Timestamp
---
# Phase 10 — Announcement
Workflow
เหมือน
Online Lesson
ทุกประการ
ห้าม Duplicate Logic
ต้องสร้าง
Shared Workflow
หากเป็นไปได้
---
# Phase 11 — Validation
ตรวจสอบ
- Permission
- Status Transition
- Invalid Transition
- Unauthorized Action
เช่น
Draft
Publish
ต้องห้าม
---
Pending Review
Publish
ต้องห้าม
---
Approve
Approve
ต้องห้าม
---
Published
Submit
ต้องห้าม
---
# Phase 12 — Regression Testing
ตรวจสอบ
## Staff
- Save Draft
- Edit Draft
- Delete Draft
- Submit
- ไม่เห็น Approve
- ไม่เห็น Publish
---
## Manager
- เห็น Pending
- Approve
- Return
- Reject
- Publish
---
## IT
ทำได้ทุกอย่าง
---
## Notification
ส่งครบ
---
## Audit
บันทึกครบ
---
## Permission
ไม่มี Role ไหน
ทำ Action ที่ไม่ควรได้
---
## UI
Badge
Button
Action
ถูกต้องตาม Status
---
# Documentation
สร้างรายงาน
```
docs/content-approval-workflow-implementation-report.md
```
---
รายงานต้องมี
```md
# Content Approval Workflow Report
## Executive Summary
## Current Architecture
## Workflow Design
## Permission Matrix
## Status Transition
## UI Changes
## Backend Changes
## Notification
## Audit Log
## Files Modified
## Testing Result
## Regression Result
## Risks
## Recommendations
## Future Improvements
```
---
# Future Improvements
เสนอแนวทางเพิ่มเติม
เช่น
- Scheduled Publish
- Workflow Configuration
- Multiple Reviewer
- Approval History Timeline
- Versioning
- Escalation
- SLA
- Email Template
- Dashboard Pending Review
---
# Constraints
ห้าม
- Hardcode Role
- Hardcode Status
- Duplicate Workflow
- Duplicate Logic
- เพิ่ม Library ใหม่
- ใช้ any
- เปลี่ยน Business Logic อื่น
ต้อง
- ใช้ Shared Workflow
- ใช้ Shared Permission
- ใช้ Shared Status Component
- ใช้ Shared Notification
- ใช้ Shared Audit
- รักษา Type Safety
- รักษา Coding Standard
- รองรับการขยายไปยัง Module อื่นในอนาคต
---
# Final Response
เมื่อดำเนินการเสร็จ
ให้สรุปเป็นภาษาไทย
1. Architecture ที่ตรวจพบ
2. Workflow ที่สร้าง
3. Status ที่รองรับ
4. Permission Matrix
5. Notification Flow
6. Audit Log
7. ไฟล์ที่แก้ไข
8. ผลการทดสอบ
9. ความเสี่ยงที่เหลือ
10. Path ของรายงาน
```
docs/content-approval-workflow-implementation-report.md
```