Skip to content

fix(#301): 身份改为请求头传递,修复流程列表 500 - #302

Merged
xlorne merged 1 commit into
devfrom
feature/issue-301-identity-header
Dec 3, 2026
Merged

xlorne merged 1 commit into
devfrom
feature/issue-301-identity-header

Conversation

@xlorne

@xlorne xlorne commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

关联 issue

Closes #301

问题

前端把当前身份以 query 参数 operatorIdentity 注入所有 /api/ 请求(issue #288 引入),而流程列表接口用 SearchRequest 接收请求:

@GetMapping("/list")
public MultiResponse<WorkflowEntity> list(SearchRequest searchRequest) {
    return MultiResponse.of(workflowEntityRepository.searchRequest(searchRequest));
}

SearchRequest#toPageRequest 会把所有 query 参数当作实体过滤字段解析,operatorIdentity 不是 WorkflowEntity 的字段,直接抛:

java.lang.IllegalArgumentException: Field operatorIdentity not found in class hierarchy.

流程列表页因此 500。

修复

身份是请求上下文,不应混进查询条件:

  • OperatorIdentity 新增 X-Operator-Identity / X-Identity-Scope / X-Lock-Identity 请求头常量,以及 pick(header, parameter, parameterPresent)(请求头优先,区分「未携带」与「显式空串」);
  • FlowRecordController、FlowRecordQueryController 的身份解析改为请求头优先,保留 query 读取以兼容旧调用方与 curl 直连;
  • 查询身份范围(identityScope / lockIdentity)同步支持请求头;
  • 文档 operator-identity.md 补请求头说明与 curl 示例,并标注 query 方式的坑。

验证

./mvnw -o -pl flow-engine-framework test:485 用例,0 失败 0 错误(新增 OperatorIdentityHeaderResolveTest 5 例,覆盖优先级、空串语义、非法值拒绝)。

启动示例应用(8091)后实测:

场景 结果
GET /api/query/workflow/list?operatorIdentity=department1 {"success":false,"errMessage":"Field operatorIdentity not found in class hierarchy."}(复现原问题)
GET /api/query/workflow/list + X-Operator-Identity: department1 {"success":true,"data":{"total":1,"list":[]}}
GET /api/query/record/todo + X-Operator-Identity: department1 + X-Identity-Scope: LOCKED {"success":true,"data":{"total":0,"list":[]}}

说明:当前实际报错点只有 /api/query/workflow/list(其余 list 接口用手工 PageRequest,未触发 toPageRequest 的过滤解析)。但这些接口同样把 query 参数绑进 SearchRequest,改用请求头可一并消除隐患。

合并顺序

先本 PR,再 codingapi/flow-frontend#88(前端改为请求头注入)。后端保留 query 兼容,所以旧前端在合并后仍能用(除流程列表外)。

身份原先前端以 query 参数 operatorIdentity 注入所有 /api/ 请求,而引擎的
/api/query/workflow/list 用 SearchRequest 接收请求,会把 query 参数当作实体
过滤字段解析,直接抛 Field operatorIdentity not found in class hierarchy。

- OperatorIdentity 新增 X-Operator-Identity / X-Identity-Scope / X-Lock-Identity
  请求头常量与 pick()(请求头优先、区分「未携带」与「显式空串」)
- FlowRecordController、FlowRecordQueryController 身份解析改为请求头优先,
  保留 query 读取以兼容旧调用方
- 查询身份范围(identityScope / lockIdentity)同步支持请求头
- 更新 operator-identity 文档与 curl 示例
- 新增 OperatorIdentityHeaderResolveTest 覆盖优先级与非法值拒绝

Closes #301
@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.17%. Comparing base (9736e92) to head (99346c7).

Files with missing lines Patch % Lines
...gapi/flow/api/controller/FlowRecordController.java 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                dev     #302      +/-   ##
============================================
- Coverage     76.19%   76.17%   -0.03%     
- Complexity     2124     2127       +3     
============================================
  Files           282      282              
  Lines          8651     8658       +7     
  Branches       1028     1029       +1     
============================================
+ Hits           6592     6595       +3     
- Misses         1550     1554       +4     
  Partials        509      509              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xlorne
xlorne merged commit e007aa5 into dev Dec 3, 2026
1 of 3 checks passed
@xlorne
xlorne deleted the feature/issue-301-identity-header branch December 3, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant