diff --git a/src/modules/Elsa.Workflows.Core/Services/WorkflowStateExtractor.cs b/src/modules/Elsa.Workflows.Core/Services/WorkflowStateExtractor.cs index 433c66e008..910cc485e4 100644 --- a/src/modules/Elsa.Workflows.Core/Services/WorkflowStateExtractor.cs +++ b/src/modules/Elsa.Workflows.Core/Services/WorkflowStateExtractor.cs @@ -14,6 +14,7 @@ public WorkflowState Extract(WorkflowExecutionContext workflowExecutionContext) var state = new WorkflowState { Id = workflowExecutionContext.Id, + TenantId = workflowExecutionContext.Workflow?.Identity?.TenantId, DefinitionId = workflowExecutionContext.Workflow.Identity.DefinitionId, DefinitionVersionId = workflowExecutionContext.Workflow.Identity.Id, DefinitionVersion = workflowExecutionContext.Workflow.Identity.Version, diff --git a/src/modules/Elsa.Workflows.Core/State/WorkflowState.cs b/src/modules/Elsa.Workflows.Core/State/WorkflowState.cs index 0ab6fc50d6..747170b2a1 100644 --- a/src/modules/Elsa.Workflows.Core/State/WorkflowState.cs +++ b/src/modules/Elsa.Workflows.Core/State/WorkflowState.cs @@ -13,6 +13,11 @@ public class WorkflowState /// public string Id { get; set; } = null!; + /// + /// Gets or sets the TenantId. + /// + public string TenantId { get; set; } = null!; + /// /// The workflow definition ID. /// diff --git a/src/modules/Elsa.Workflows.Management/Mappers/WorkflowStateMapper.cs b/src/modules/Elsa.Workflows.Management/Mappers/WorkflowStateMapper.cs index deccb8170b..7638f60fe2 100644 --- a/src/modules/Elsa.Workflows.Management/Mappers/WorkflowStateMapper.cs +++ b/src/modules/Elsa.Workflows.Management/Mappers/WorkflowStateMapper.cs @@ -35,6 +35,7 @@ public class WorkflowStateMapper public void Apply(WorkflowState source, WorkflowInstance target) { target.Id = source.Id; + target.TenantId = source.TenantId; target.CreatedAt = source.CreatedAt; target.DefinitionId = source.DefinitionId; target.DefinitionVersionId = source.DefinitionVersionId; @@ -66,6 +67,7 @@ public void Apply(WorkflowState source, WorkflowInstance target) var workflowState = source.WorkflowState; workflowState.Id = source.Id; + workflowState.TenantId = source.TenantId; workflowState.CreatedAt = source.CreatedAt; workflowState.DefinitionId = source.DefinitionId; workflowState.DefinitionVersionId = source.DefinitionVersionId; diff --git a/src/modules/Elsa.Workflows.Runtime/Services/DefaultActivityExecutionMapper.cs b/src/modules/Elsa.Workflows.Runtime/Services/DefaultActivityExecutionMapper.cs index e862e6be83..3a90a83303 100644 --- a/src/modules/Elsa.Workflows.Runtime/Services/DefaultActivityExecutionMapper.cs +++ b/src/modules/Elsa.Workflows.Runtime/Services/DefaultActivityExecutionMapper.cs @@ -20,6 +20,7 @@ public ActivityExecutionRecord Map(ActivityExecutionContext source) return new() { Id = source.Id, + TenantId = source.WorkflowExecutionContext.Workflow?.Identity?.TenantId, ActivityId = source.Activity.Id, ActivityNodeId = source.NodeId, WorkflowInstanceId = source.WorkflowExecutionContext.Id, diff --git a/src/modules/Elsa.Workflows.Runtime/Services/WorkflowHost.cs b/src/modules/Elsa.Workflows.Runtime/Services/WorkflowHost.cs index 01e816184f..15b85db050 100644 --- a/src/modules/Elsa.Workflows.Runtime/Services/WorkflowHost.cs +++ b/src/modules/Elsa.Workflows.Runtime/Services/WorkflowHost.cs @@ -93,6 +93,7 @@ public async Task RunWorkflowAsync(RunWorkflowOptions? @param var workflowResult = await workflowRunner.RunAsync(WorkflowGraph, WorkflowState, runOptions, linkedCancellationToken); WorkflowState = workflowResult.WorkflowState; + WorkflowState.TenantId = WorkflowGraph.Workflow.Identity?.TenantId; await PersistStateAsync(scope, cancellationToken); _linkedTokenSource.Dispose();