From 577abdf0aef355ed2e8dd415e20e8af83e20e9f9 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 7 May 2025 09:00:25 +0200 Subject: [PATCH 1/5] Update Elsa.Studio package versions to 3.4.0-preview.991 Upgraded Elsa.Studio and related packages to the latest preview version (3.4.0-preview.991) from 3.4.0-preview.918. This ensures compatibility with the latest updates and fixes in the Elsa.Studio ecosystem. --- Directory.Packages.props | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 755302ec6..db79c749e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -31,10 +31,10 @@ - - - - + + + + From 2aa05faa85d2692a289603b4c14683c8acd2f364 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 7 May 2025 10:46:44 +0200 Subject: [PATCH 2/5] Update Elsa Studio to version 3.4.0-rc2 Upgraded Elsa Studio and related packages from preview.991 to rc2 in both `Directory.Build.props` and `Directory.Packages.props`. This ensures usage of the latest release candidate version across the project. --- Directory.Build.props | 2 +- Directory.Packages.props | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 7476459c8..585bd0c9d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -37,6 +37,6 @@ $(NoWarn);IL2026;IL2046;IL2057;IL2067;IL2070;IL2072;IL2075;IL2087;IL2091 - 3.4.0-rc1 + 3.4.0-rc2 \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index db79c749e..b578adfce 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -31,10 +31,10 @@ - - - - + + + + From d254ba33857c98f83f8b03539147c3c6cbf3f3bc Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 7 May 2025 10:48:05 +0200 Subject: [PATCH 3/5] Update GitHub workflows to trigger on rc/3.4.0 branch Changed workflow triggers from the main branch to rc/3.4.0 for elsa-studio, elsa-server, and elsa-server-and-studio. This ensures workflows are aligned with the release candidate branch for version 3.4.0. --- .github/workflows/elsa-server-and-studio.yml | 2 +- .github/workflows/elsa-server.yml | 2 +- .github/workflows/elsa-studio.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/elsa-server-and-studio.yml b/.github/workflows/elsa-server-and-studio.yml index 9c23cc7c9..85fa17cdf 100644 --- a/.github/workflows/elsa-server-and-studio.yml +++ b/.github/workflows/elsa-server-and-studio.yml @@ -3,7 +3,7 @@ on: workflow_dispatch: push: branches: - - main + - rc/3.4.0 jobs: push_to_registry: diff --git a/.github/workflows/elsa-server.yml b/.github/workflows/elsa-server.yml index 289332ba4..291680c68 100644 --- a/.github/workflows/elsa-server.yml +++ b/.github/workflows/elsa-server.yml @@ -3,7 +3,7 @@ on: workflow_dispatch: push: branches: - - main + - rc/3.4.0 jobs: push_to_registry: diff --git a/.github/workflows/elsa-studio.yml b/.github/workflows/elsa-studio.yml index f2fe2bff2..86bb55c67 100644 --- a/.github/workflows/elsa-studio.yml +++ b/.github/workflows/elsa-studio.yml @@ -3,7 +3,7 @@ on: workflow_dispatch: push: branches: - - main + - rc/3.4.0 jobs: push_to_registry: From 237b22bf0ff72a13164044a918afb35be0875aeb Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 16 May 2025 21:57:49 +0200 Subject: [PATCH 4/5] Fix tenant ID handling and query filtering logic. Replaced direct query filter setup with a dedicated method for cleaner and more readable tenant ID filtering logic. Removed unnecessary dependencies and improved code consistency by aligning naming conventions and simplifying expressions. --- .../ElsaDbContextBase.cs | 16 ++++----- .../EntityHandlers/SetTenantIdFilter.cs | 33 ++++++++++++++----- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/modules/Elsa.EntityFrameworkCore.Common/ElsaDbContextBase.cs b/src/modules/Elsa.EntityFrameworkCore.Common/ElsaDbContextBase.cs index 2a22f2a7d..a1f9dcb35 100644 --- a/src/modules/Elsa.EntityFrameworkCore.Common/ElsaDbContextBase.cs +++ b/src/modules/Elsa.EntityFrameworkCore.Common/ElsaDbContextBase.cs @@ -19,7 +19,7 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema }; protected IServiceProvider ServiceProvider { get; } - private readonly ElsaDbContextOptions? _elsaDbContextOptions; + private readonly ElsaDbContextOptions? elsaDbContextOptions; public string? TenantId { get; set; } /// @@ -41,10 +41,10 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema protected ElsaDbContextBase(DbContextOptions options, IServiceProvider serviceProvider) : base(options) { ServiceProvider = serviceProvider; - _elsaDbContextOptions = options.FindExtension()?.Options; - + elsaDbContextOptions = options.FindExtension()?.Options; + // ReSharper disable once VirtualMemberCallInConstructor - Schema = !string.IsNullOrWhiteSpace(_elsaDbContextOptions?.SchemaName) ? _elsaDbContextOptions.SchemaName : ElsaSchema; + Schema = !string.IsNullOrWhiteSpace(elsaDbContextOptions?.SchemaName) ? elsaDbContextOptions.SchemaName : ElsaSchema; var tenantAccessor = serviceProvider.GetService(); var tenantId = tenantAccessor?.Tenant?.Id; @@ -63,11 +63,11 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema /// protected override void OnModelCreating(ModelBuilder modelBuilder) { - if (!string.IsNullOrWhiteSpace(Schema)) + if (!string.IsNullOrWhiteSpace(Schema)) modelBuilder.HasDefaultSchema(Schema); - var additionalConfigurations = _elsaDbContextOptions?.GetModelConfigurations(this); - + var additionalConfigurations = elsaDbContextOptions?.GetModelConfigurations(this); + additionalConfigurations?.Invoke(modelBuilder); using var scope = ServiceProvider.CreateScope(); @@ -75,7 +75,7 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema foreach (var entityType in modelBuilder.Model.GetEntityTypes().ToList()) { - foreach (var handler in entityTypeHandlers) + foreach (var handler in entityTypeHandlers) handler.Handle(this, modelBuilder, entityType); } } diff --git a/src/modules/Elsa.EntityFrameworkCore.Common/EntityHandlers/SetTenantIdFilter.cs b/src/modules/Elsa.EntityFrameworkCore.Common/EntityHandlers/SetTenantIdFilter.cs index 0e5bb9d9d..f4522d7d4 100644 --- a/src/modules/Elsa.EntityFrameworkCore.Common/EntityHandlers/SetTenantIdFilter.cs +++ b/src/modules/Elsa.EntityFrameworkCore.Common/EntityHandlers/SetTenantIdFilter.cs @@ -1,9 +1,7 @@ using System.Linq.Expressions; using Elsa.Common.Entities; -using Elsa.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Query; namespace Elsa.EntityFrameworkCore.EntityHandlers; @@ -15,15 +13,32 @@ public class SetTenantIdFilter : IEntityModelCreatingHandler /// public void Handle(ElsaDbContextBase dbContext, ModelBuilder modelBuilder, IMutableEntityType entityType) { - if (!entityType.ClrType.IsAssignableTo(typeof(Entity))) + if (!typeof(Entity).IsAssignableFrom(entityType.ClrType)) return; - var tenantId = dbContext.TenantId.NullIfEmpty(); - var parameter = Expression.Parameter(entityType.ClrType); - Expression> filterExpr = entity => entity.TenantId == tenantId; - var body = ReplacingExpressionVisitor.Replace(filterExpr.Parameters[0], parameter, filterExpr.Body); - var lambdaExpression = Expression.Lambda(body, parameter); + modelBuilder + .Entity(entityType.ClrType) + .HasQueryFilter(CreateTenantFilterExpression(dbContext, entityType.ClrType)); + } - entityType.SetQueryFilter(lambdaExpression); + private LambdaExpression CreateTenantFilterExpression(ElsaDbContextBase dbContext, Type clrType) + { + var parameter = Expression.Parameter(clrType, "e"); + + // e => EF.Property(e, "TenantId") == this.TenantId + var tenantIdProperty = Expression.Call( + typeof(EF), + nameof(EF.Property), + [typeof(string)], + parameter, + Expression.Constant("TenantId")); + + var tenantIdOnContext = Expression.Property( + Expression.Constant(dbContext), + nameof(ElsaDbContextBase.TenantId)); + + var body = Expression.Equal(tenantIdProperty, tenantIdOnContext); + + return Expression.Lambda(body, parameter); } } \ No newline at end of file From 0769b6ded2ad494eb234071fe78946f516db90fe Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 16 May 2025 22:16:36 +0200 Subject: [PATCH 5/5] Update ElsaStudio package version to 3.4.0-preview.1025 Changed the ElsaStudioVersion to a new preview version and referenced it consistently in package definitions. This ensures centralized management of the version and supports the updated preview release. --- Directory.Build.props | 2 +- Directory.Packages.props | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 585bd0c9d..fddc11126 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -37,6 +37,6 @@ $(NoWarn);IL2026;IL2046;IL2057;IL2067;IL2070;IL2072;IL2075;IL2087;IL2091 - 3.4.0-rc2 + 3.4.0-preview.1025 \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index b578adfce..21873199a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -31,10 +31,10 @@ - - - - + + + +