xiangning 3d45aed822 fix(workflow): 修复 WorkflowInstance.InitiatorId 系统性空值
全系统 InitiatorId 始终为 Guid.Empty,导致撤回鉴权与发起人通知失效。
自下而上修复:
- StartWorkflowInstanceCommand 加 InitiatorId 参数,Handler 写入实例
- StartWorkflowByNameCommandHandler 透传发起人(原为死参数)
- StartWorkflowInstanceEndpoint 取当前认证用户作为发起人
- IAiBotHandler.AnswerAsync 加 initiatorId 参数,AI 触发流程用真实发起人
- SendMessageCommandHandler 传 request.SenderId 给 AI 问答
- 补充测试断言验证 InitiatorId 正确赋值
2026-07-09 12:52:13 +08:00

39 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using MediatR;
using Workflow.Application.Features.WorkflowInstances.Commands;
using BuildFlow.Shared.Domain.Common;
using BuildFlow.Host.Services.Users;
namespace BuildFlow.Host.Endpoints.Workflow.WorkflowInstance;
/// <summary>
/// 发起流程实例端点。POST /workflow-instances,按定义创建实例并产生首个 token。
/// </summary>
public class StartWorkflowInstanceEndpoint(
IMediator mediator,
ICurrentUserContext currentUserContext) : Endpoint<StartWorkflowInstanceRequest, Guid>
{
public override void Configure()
{
Post("/workflow-instances");
Permissions("workflow-instance:start");
Summary(s =>
{
s.Summary = "Start a new workflow instance";
});
}
public override async Task HandleAsync(StartWorkflowInstanceRequest req, CancellationToken ct)
{
// 发起人取自当前认证用户,写入 WorkflowInstance.InitiatorId,供撤回鉴权与发起人通知使用。
var command = new StartWorkflowInstanceCommand(
req.DefinitionCode,
req.Title,
req.Variables,
req.FormDataJson,
currentUserContext.GetUserIdGuid());
var result = await mediator.Send(command, ct);
await Send.OkAsync(result, ct);
}
}