狀態:v1.0 shipped 發版日期:2026-05-15 取代:sub-spec design.md(spec 1 / 2 / 3 / 4)— 仍保留作 detail reference,但對外溝通以本檔為主
本檔是 v1.0 single source of truth。需要看「為什麼這樣做」見各 sub-spec design.md 的
Reconciliation段;需要看「實作步驟」見對應 implementation-plan.md。
把 AP(稽核計畫,Assessment Plan)的生命週期從寫死的 6 階段流程,改成 BPMN 流程引擎驅動。使用者可建立 / 複製 / 自訂流程範本,AP 套用範本後依範本定義的階段順序推進(含「審核」階段、退回機制與方向性驗證)。
| 情境 | 範本 | 階段組合 |
|---|---|---|
| A:正式稽核導入 | builtin-full-audit |
Start → planning → task_execution → audit → (Gateway) → poam → audit /(無缺失)End |
| A+:含審核 | builtin-full-audit-with-review |
Start → planning → task_execution → review → audit → (Gateway) → poam → audit /(無缺失)End |
| B:內部自查 | builtin-internal-check |
Start → planning → task_execution → End |
| C:自我評估 | builtin-self-assessment |
Start → planning → task_execution → audit → End |
allowed_predecessors / allowed_successors 規則;發布前 / 草稿編輯時 inline 警告flow_template_manage capability 控制可見public.system_logs(event_code 6050-6054),方便追溯誰在何時做了什麼compliance.stage_objects| 欄位 | 型別 | 說明 |
|---|---|---|
id |
serial PK | |
uid |
uuid | external identifier |
code |
text unique | 例:planning / task_execution / review / audit / poam |
name_i18n |
jsonb | {"zh_Hant_TW": "規劃", "en": "Planning"} |
kind |
text | routed(綁頁面)/ stateful(無專屬頁面) |
route_pattern |
text | 僅 routed 有(如 /project/projects/:projectUID/settings) |
complete_button_label_i18n |
jsonb | Banner「完成此階段」按鈕文字 |
entry_button_label_i18n |
jsonb | Banner「進入下一階段」按鈕文字(v1 衍生新增) |
complete_handler_key |
text | BE registry key(如 activate_project) |
precondition_key |
text | BE registry key(如 all_tasks_closed) |
default_main_roles |
jsonb | 預設能 complete 此 stage 的角色(["manager"]) |
can_start |
bool | 此 stage 是否可作為 BPMN start 後的第一個 UserTask |
can_end |
bool | 此 stage 是否可直接連 EndEvent |
allowed_predecessors |
jsonb | 允許作為前驅的 stage code list(空陣列=不限制) |
allowed_successors |
jsonb | 允許作為後繼的 stage code list(空陣列=不限制) |
is_builtin |
bool | v1 全部 true |
sort |
int | 列表排序 |
| code | sort | can_start | can_end | allowed_predecessors | allowed_successors |
|---|---|---|---|---|---|
planning |
10 | ✅ | ❌ | [] |
["task_execution"] |
task_execution |
20 | ❌ | ✅ | ["planning", "review"] |
["review", "audit"] |
review |
25 | ❌ | ❌ | ["task_execution", "review"] |
["task_execution", "review", "audit"] |
audit |
30 | ❌ | ✅ | ["task_execution", "review", "poam"] |
["poam"] |
poam |
40 | ❌ | ✅ | ["audit"] |
["audit"] |
compliance.flow_templates| 欄位 | 型別 | 說明 |
|---|---|---|
id |
serial PK | |
uid |
uuid | |
tenant_id |
int | RLS(NULL = system-wide builtin) |
name |
text | |
description |
text | |
bpmn_xml |
text | BPMN 2.0 XML(含 stage_object_code / main_role extension properties) |
is_builtin |
bool | 內建範本(不可編輯,只能複製) |
status |
text | draft / published(v1 衍生狀態機) |
is_active |
bool | 軟刪除 flag |
created_user / created_at / updated_user / updated_at |
審計欄位 |
status='published')| name | 用途 |
|---|---|
builtin-full-audit |
完整稽核流程(無 review) |
builtin-full-audit-with-review |
完整稽核流程 + reviewer 審核 |
builtin-internal-check |
內部自查 |
builtin-self-assessment |
自我評估稽核 |
compliance.assessment_plan_extensions每個 AP 一筆,存 main workflow 的 snapshot 引用 + flow_template 來源 uid。
| 欄位 | 說明 |
|---|---|
assessment_plan_id |
FK → oscal.assessment_plans |
flow_template_uid |
snapshot 來源 |
workflow_execution_uid |
snapshot 後的 main workflow execution 引用 |
flow_template (master, 系統層)
↓ clone (建 AP 時)
workflow_template_snapshot (per-AP 凍結)
↓ instantiate
workflow_execution (runtime instance)
| Method | Path | 說明 |
|---|---|---|
| GET | /flow-engine/flow-templates |
列表(分頁、search、tenant filter) |
| GET | /flow-engine/flow-templates/<uid> |
取單筆(含 BPMN XML) |
| POST | /flow-engine/flow-templates |
建立(status=draft) |
| PUT | /flow-engine/flow-templates/<uid> |
更新(含 BPMN XML 重寫) |
| DELETE | /flow-engine/flow-templates/<uid> |
軟刪除 |
| POST | /flow-engine/flow-templates/<uid>/duplicate |
複製(builtin → 自訂) |
| POST | /flow-engine/flow-templates/<uid>/publish |
draft → published |
| PUT | /flow-engine/flow-templates/<uid>/unpublish |
published → draft |
| POST | /flow-engine/flow-templates/validate |
純驗證(不存檔),回 violations 陣列 |
| Method | Path | 說明 |
|---|---|---|
| GET | /project/<uid>/ap/<ap_uid>/stage/info |
Banner 顯示用(當前 stage / progress / 按鈕 label / precondition) |
| POST | /project/<uid>/ap/<ap_uid>/stage/advance |
推進 / 退回(含 decision / comment) |
建 AP(POST /oscal/projects/start)時 flow_template_uid 必填。launch_new_round 自動沿用前一輪的 flow_template_uid。
GRC_STAGE_NO_NEXT_NODEGRC_STAGE_OBJECT_NOT_BOUNDGRC_STAGE_OBJECT_NOT_FOUNDGRC_STAGE_REVIEW_DECISION_INVALIDGRC_STAGE_REVIEW_REJECT_REQUIRES_COMMENTmain_roles → 否則 403 GRC_STAGE_ROLE_FORBIDDENGRC_STAGE_PRECONDITION_FAILEDterminal_close handlerstage_object.complete_handler_keyGRC_STAGE_HANDLER_NOT_REGISTERED完成後 BPMN engine 推進到下一個 UserTask(reject 走 reverse flow 回上一階段)。
13 處 logger 統一前綴 [AUDIT:STAGE_ADVANCE],含 event_code 寫進 public.system_logs:
| Event | Code | Level | 觸發 |
|---|---|---|---|
| requested | 6050 | INFO | 進入 API |
| success (forward) | 6051 | INFO | 推進成功 |
| success (rejected) | 6052 | INFO | 退回成功 |
| halted | 6053 | INFO | handler warning 中止 |
| denied | 6054 | WARN/ERROR | 各種拒絕(reason 看 message) |
-- 某 user 今天所有推進事件
SELECT act_time, event_code, level, LEFT(message, 120)
FROM public.system_logs
WHERE user_uid = '<uid>'
AND act_time >= CURRENT_DATE
AND event_code LIKE '605%'
ORDER BY act_time;
-- 某 AP 推進歷程
SELECT act_time, user_name, event_code, message
FROM public.system_logs
WHERE message LIKE '%ap_uid=<uid>%'
AND event_code LIKE '605%'
ORDER BY act_time;reason_i18n_key)按下後依 stage 不同行為:
| stage | 行為 |
|---|---|
planning |
呼叫既有 POST /grc/.../activate(搬到 ActivateProjectHandler) |
task_execution |
呼叫既有 POST /grc/.../launch-audit(搬到 LaunchAuditHandler,未強制完成有 warning) |
review |
dispatch ReviewDecisionHandler(approve / reject) |
audit |
呼叫既有 POST /grc/.../confirm-audit |
poam |
呼叫既有 POST /grc/.../close-round |
| terminal | dispatch terminal_close handler |
flow_template_manage控制左側選單「流程管理」可見 + 範本 CRUD route 存取(resource_type='ui_route', url='/flow-template-manage')。
stage_object.default_main_roles 決定哪些 role 能完成此 stage;FE Banner 推進按鈕的可見性 = user role 是否在 main_roles 內。
role_capabilities v1 沿用既有 4 role(manager / reviewer / auditor / viewer)。
StartEvent → planning → task_execution → review → audit → Gateway
↑ (default) ├── (default, 無缺失) → EndEvent
└── (reject) └── (has_findings) → poam → audit
${decision == 'reject'})StartEvent → planning → task_execution → audit → Gateway
├── EndEvent
└── poam → audit
簡單線性流程,無 review、無 POAM 迴圈。
can_start=truestage_object_codeallowed_predecessors / allowed_successorscan_end=true${var == 'reject'} 嚴格 regex 或 extension property reverse=truePOST /flow-engine/flow-templates/validate 純驗證回 200 + {valid, violations}PUT .../<uid>/publish 違規 → 400 GRC_FLOW_TOPOLOGY_INVALID data 帶 violationsstart_stage_not_allowed 用節點 BPMN @name 顯示 + user_task_id 紅框)| Code | 中文 | 場景 |
|---|---|---|
| GRC_403040 | 內建範本不可編輯或刪除 | builtin guard |
| GRC_403041 | 無流程範本管理權限 | flow-template-manage cap 缺 |
| GRC_403050 | 使用者不具備此階段推進權限 | role_forbidden |
| GRC_409xxx | 範本名稱重複 / 範本未發布 | publish flow |
| GRC_412xxx | precondition / handler / stage 相關 | 推進 7 步檢查 |
完整列表見 common/code/grc_error_code.py。
| Spec | Phase | 完成日 |
|---|---|---|
| 1 — 流程管理 | Phase A–E | 2026-05-12 |
| 2 — 階段抽象整合 | Phase A–E | 2026-05-13 |
| 3 — AP 套用流程 | M0–M12 + follow-up | 2026-05-13 |
| 4 — review stage + topology validator | M0–M11 | 2026-05-14 |
| flow-template draft/published 狀態機 | — | 2026-05-15 |
| banner 動態化(progress dots / button label) | — | 2026-05-15 |
| audit log + event_code | — | 2026-05-15 |
start_stage_not_allowed 訊息修補 + 紅框 |
— | 2026-05-15 |
OSCAL project PUT/DELETE 加 Owner/Manager 權限 |
— | 2026-05-15 |
執行:
psql -h <host> -p <port> -U cmmgr -d <db_name> \
-v ON_ERROR_STOP=1 \
-f scripts/sql/2026-05-15-bpmn-integration-v1.0-upgrade.sql入口 SQL 是 2026-05-15-bpmn-integration-v1.0-upgrade.sql,內含全套 7 個 migration(idempotent,重跑安全):
跑完會自動 print verify SELECT。
builtin-full-audit-with-review → Banner 顯示 planning 階段[AUDIT:STAGE_ADVANCE] + public.system_logs.event_code='6051')| 議題 | 優先級 |
|---|---|
| 階段物件 CRUD UI(admin 可加 stage) | high |
| 範本 import / export | medium |
| 範本 version history(每次 publish snapshot) | medium |
| Stage handler / precondition plugin 機制 | low(架構保留,code 未開放) |
| 跨 AP workflow merge / split | low |
| Audit log retention policy(system_logs 累積大) | ops |
01-flow-template-management/design.md — Spec 1 流程管理(含 reconciliation §9)02-stage-integration/design.md — Spec 2 階段抽象整合(含 reconciliation §10)03-ap-binding/design.md — Spec 3 AP 套用流程(含 reconciliation §16)04-review-stage-and-flow-validation/design.md — Spec 4 review + topology(含 reconciliation §16)03-ap-binding/handoff-v1.md ~ handoff-v3.md04-review-stage-and-flow-validation/handoff-v1.md ~ handoff-v3.md2026-05-15-tweak-multi-review-stage-support.md2026-05-15-fix-reviewer-role-blocked-from-launch-audit.md2026-05-15-fix-stage-object-topology-rules-too-restrictive.md2026-05-15-tweak-flow-engine-banner-dynamic-button-label.md2026-05-15-fix-flow-template-validator-start-stage-msg-and-marker.md2026-05-15-tweak-stage-advance-audit-log.md2026-05-15-tweak-stage-advance-audit-event-code.md| 位置 | 用途 |
|---|---|
app/flow_engine/service/flow_template_app_service.py |
範本 CRUD + publish/unpublish + validate |
app/flow_engine/service/stage_advance_service.py |
Stage 推進 / 退回 service(含 audit log) |
app/flow_engine/util/bpmn_topology_validator.py |
拓撲驗證器(7 條 rule,pure function) |
app/flow_engine/handler/ |
各 stage 的 on_complete handler |
domain/flow_engine/entity/stage_object_entity.py |
stage_object domain entity |
infra/flow_engine/model/ |
flow_templates / stage_objects ORM model |
api/flow_engine/routes/ |
flow-template / stage-advance routes |
compliance-manager-fe/src/views/flow-template/FlowTemplateEditorView.vue |
BPMN editor + 拓撲警告 |
compliance-manager-fe/src/components/grc/ProjectFlowBanner.vue |
Banner UI |