feat(oa): add initiator system field to condition branches

Allow __initiator__ contains matching in publish validation and the
flow designer candidate list, excluding it from form useInCondition locks.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-07-30 13:07:44 +08:00
1 parent 3d88f52e2e
commit 22be6d8b36
7 files changed
+103 -23

No files matched your search

+6 -1
View File
@@ -1431,7 +1431,12 @@ def _eval_condition_rules(
if op == "contains":
if field == INITIATOR_CONDITION_FIELD:
uid = (initiator_user_id or "").strip()
allowed = {str(x or "").strip() for x in (val or [])}
if isinstance(val, list):
allowed = {str(x or "").strip() for x in val if str(x or "").strip()}
elif isinstance(val, str) and val.strip():
allowed = {val.strip()}
else:
allowed = set()
if not uid or uid not in allowed:
return False
continue
+18 -3
View File
@@ -68,6 +68,9 @@ VALID_ASSIGNEE_TYPES = frozenset(
VALID_NODE_TYPES = frozenset({"start", "approval", "cc", "condition", "end"})
# 系统条件伪字段(非表单控件)
INITIATOR_CONDITION_FIELD = "__initiator__"
# 发布允许的控件 type(未知 type 拒绝)
ALLOWED_CONTROL_TYPES = FILLABLE_TYPES | LAYOUT_TYPES
@@ -295,7 +298,7 @@ def validate_flow_tree(flow_tree: Any) -> List[str]:
def validate_condition_rules_against_form(form_schema: Any, flow_tree: Any) -> List[str]:
indexed = index_condition_fields(form_schema)
errors: List[str] = []
seen: Set[str] = set()
seen_form: Set[str] = set()
def collect_fields(node: Optional[Dict[str, Any]]) -> None:
if not node or not isinstance(node, dict):
@@ -308,9 +311,21 @@ def validate_condition_rules_against_form(form_schema: Any, flow_tree: Any) -> L
if not isinstance(r, dict):
continue
field = (r.get("field") or "").strip()
if not field or field in seen:
if not field:
continue
seen.add(field)
if field == INITIATOR_CONDITION_FIELD:
op = (r.get("op") or "").strip()
val = r.get("value")
if op != "contains":
errors.append("发起人条件仅支持「包含」")
elif not isinstance(val, list) or not any(
str(x).strip() for x in val
):
errors.append("发起人包含条件须选择至少一名用户")
continue
if field in seen_form:
continue
seen_form.add(field)
if field not in indexed:
errors.append(f"条件引用了无效字段:{field}")
child = g.get("child")