Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/Elsa.Persistence.EFCore.Common/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public async Task SaveManyAsync(
}

// When doing a custom SQL query (Bulk Upsert), none of the installed query filters will be applied. Hence, we are assigning the current tenant ID explicitly.
var tenantId = serviceProvider.GetRequiredService<ITenantAccessor>().Tenant?.Id;
var tenantId = serviceProvider.GetRequiredService<ITenantAccessor>().TenantId;
foreach (var entity in entityList)
{
if (entity is Entity entityWithTenant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public async Task<TDbContext> CreateDbContextAsync(CancellationToken cancellatio
private void SetTenantId(TDbContext context)
{
if (context is ElsaDbContextBase elsaContext)
elsaContext.TenantId = tenantAccessor.Tenant?.Id;
elsaContext.TenantId = tenantAccessor.TenantId;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Elsa.Common.Multitenancy;
using Elsa.Workflows.Management.Materializers;
using Elsa.Workflows.Runtime.Features;
using Elsa.Workflows.Runtime.Options;
Expand All @@ -10,7 +11,7 @@ namespace Elsa.Workflows.Runtime.Providers;
/// Provides workflows to the system that are registered with <see cref="WorkflowRuntimeFeature"/>
/// </summary>
[UsedImplicitly]
public class ClrWorkflowsProvider(
public class (
IOptions<RuntimeOptions> options,
IWorkflowBuilderFactory workflowBuilderFactory,
IServiceProvider serviceProvider) : IWorkflowsProvider
Expand Down Expand Up @@ -41,7 +42,7 @@ private async Task<MaterializedWorkflow> BuildWorkflowAsync(Func<IServiceProvide
{
Id = id,
DefinitionId = definitionId,
TenantId = workflow.Identity.TenantId
TenantId = workflow.Identity.TenantId ?? Tenant.AgnosticTenantId
};

var materializerContext = new ClrWorkflowMaterializerContext(workflowBuilder.GetType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<IEnumerable<WorkflowDefinition>> PopulateStoreAsync(bool index
{
var providers = _workflowDefinitionProviders();
var workflowDefinitions = new List<WorkflowDefinition>();
var currentTenantId = (_tenantAccessor.Tenant?.Id).NormalizeTenantId();
var currentTenantId = _tenantAccessor.TenantId;

foreach (var provider in providers)
{
Expand All @@ -69,7 +69,7 @@ public async Task<IEnumerable<WorkflowDefinition>> PopulateStoreAsync(bool index
foreach (var result in results)
{
// Normalize tenant IDs for comparison (null becomes empty string)
var definitionTenantId = result.Workflow.Identity.TenantId.NormalizeTenantId();
var definitionTenantId = result.Workflow.Identity.TenantId ?? _tenantAccessor.TenantId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RalfvandenBurg

Heads up: this change seems incorrect. What will happen now is that if a workflow without a tenant ID (e.g. a code-first workflow) will receive the ID of the current tenant, which is problematic given that this populator is executed for all tenants in the system. This means that the last tenant being iterated will be the owner of the code-first workflows.

for that reason, I will revert this part - but I also don't want to break your stuff, so if you let me know why this change was necessary in your scenarios, please let me know and we can find a better fix.


// Only import workflows belonging to the current tenant or tenant-agnostic workflows (TenantId = "*").
if (definitionTenantId != currentTenantId && definitionTenantId != Tenant.AgnosticTenantId)
Expand Down Expand Up @@ -191,8 +191,8 @@ private async Task<WorkflowDefinition> AddOrUpdateCoreAsync(MaterializedWorkflow
await UpdateIsPublished();

// Determine the tenant ID for the workflow definition
// If the workflow has no tenant ID, use the current tenant (normalized to handle null -> "")
var workflowTenantId = workflow.Identity.TenantId ?? (_tenantAccessor.Tenant?.Id).NormalizeTenantId();
// If the workflow has no tenant ID, use the current tenant (normalized to handle null -> "*")
var workflowTenantId = workflow.Identity.TenantId ?? _tenantAccessor.TenantId;

var workflowDefinition = existingDefinitionVersion ?? new WorkflowDefinition
{
Expand Down