From 227dd83e77b094fc02edcc644e7b357a2908a6cd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:00:09 -0800 Subject: [PATCH 1/5] [release/2.1] Fix site handing after enabling user time zone feature (#17077) --------- Co-authored-by: Hisham Bin Ateya Co-authored-by: Mike Alhayek --- .../Drivers/UserDisplayDriver.cs | 4 +-- .../TimeZone/Handlers/UserEventHandler.cs | 35 +++++++++++++++++++ .../TimeZone/Services/UserTimeZoneService.cs | 22 +++--------- .../OrchardCore.Users/TimeZone/Startup.cs | 6 ++-- 4 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/UserEventHandler.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserDisplayDriver.cs index ad0064b3699..11d0ac851d7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserDisplayDriver.cs @@ -126,7 +126,7 @@ public override async Task UpdateAsync(User user, UpdateEditorCo var userContext = new UserContext(user); // TODO This handler should be invoked through the create or update methods. // otherwise it will not be invoked when a workflow, or other operation, changes this value. - await _userEventHandlers.InvokeAsync((handler, context) => handler.DisabledAsync(userContext), userContext, _logger); + await _userEventHandlers.InvokeAsync((handler, context) => handler.DisabledAsync(context), userContext, _logger); } } else if (!isEditingDisabled && model.IsEnabled && !user.IsEnabled) @@ -135,7 +135,7 @@ public override async Task UpdateAsync(User user, UpdateEditorCo var userContext = new UserContext(user); // TODO This handler should be invoked through the create or update methods. // otherwise it will not be invoked when a workflow, or other operation, changes this value. - await _userEventHandlers.InvokeAsync((handler, context) => handler.EnabledAsync(userContext), userContext, _logger); + await _userEventHandlers.InvokeAsync((handler, context) => handler.EnabledAsync(context), userContext, _logger); } if (context.Updater.ModelState.IsValid) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/UserEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/UserEventHandler.cs new file mode 100644 index 00000000000..46a4cb0f059 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/UserEventHandler.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Caching.Distributed; +using OrchardCore.Users.Handlers; + +namespace OrchardCore.Users.TimeZone.Handlers; + +public class UserEventHandler : UserEventHandlerBase +{ + private const string CacheKey = "UserTimeZone/"; + + private readonly IDistributedCache _distributedCache; + + public UserEventHandler(IDistributedCache distributedCache) + { + _distributedCache = distributedCache; + } + + public override Task DeletedAsync(UserDeleteContext context) + => ForgetCacheAsync(context.User.UserName); + + public override Task UpdatedAsync(UserUpdateContext context) + => ForgetCacheAsync(context.User.UserName); + + public override Task DisabledAsync(UserContext context) + => ForgetCacheAsync(context.User.UserName); + + private Task ForgetCacheAsync(string userName) + { + var key = GetCacheKey(userName); + + return _distributedCache.RemoveAsync(key); + } + + internal static string GetCacheKey(string userName) + => CacheKey + userName; +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Services/UserTimeZoneService.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Services/UserTimeZoneService.cs index 4077e66d1db..e351ff8c5a6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Services/UserTimeZoneService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Services/UserTimeZoneService.cs @@ -2,15 +2,14 @@ using Microsoft.Extensions.Caching.Distributed; using OrchardCore.Entities; using OrchardCore.Modules; -using OrchardCore.Users.Handlers; using OrchardCore.Users.Models; +using OrchardCore.Users.TimeZone.Handlers; using OrchardCore.Users.TimeZone.Models; namespace OrchardCore.Users.TimeZone.Services; -public class UserTimeZoneService : UserEventHandlerBase, IUserTimeZoneService +public class UserTimeZoneService : IUserTimeZoneService { - private const string CacheKey = "UserTimeZone/"; private const string EmptyTimeZone = "NoTimeZoneFound"; private static readonly DistributedCacheEntryOptions _slidingExpiration = new() @@ -47,7 +46,6 @@ public async ValueTask GetAsync(string userName) return _clock.GetTimeZone(currentTimeZoneId); } - /// public ValueTask GetAsync(IUser user) => GetAsync(user?.UserName); @@ -59,7 +57,7 @@ public async ValueTask UpdateAsync(IUser user) /// private async ValueTask GetTimeZoneIdAsync(string userName) { - var key = GetCacheKey(userName); + var key = UserEventHandler.GetCacheKey(userName); var timeZoneId = await _distributedCache.GetStringAsync(key); @@ -95,22 +93,10 @@ private async ValueTask GetTimeZoneIdAsync(string userName) return timeZoneId; } - public override Task DeletedAsync(UserDeleteContext context) - => ForgetCacheAsync(context.User.UserName); - - public override Task UpdatedAsync(UserUpdateContext context) - => ForgetCacheAsync(context.User.UserName); - - public override Task DisabledAsync(UserContext context) - => ForgetCacheAsync(context.User.UserName); - private Task ForgetCacheAsync(string userName) { - var key = GetCacheKey(userName); + var key = UserEventHandler.GetCacheKey(userName); return _distributedCache.RemoveAsync(key); } - - private static string GetCacheKey(string userName) - => CacheKey + userName; } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs index b43ff481c09..983456a04d4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs @@ -4,6 +4,7 @@ using OrchardCore.Users.Handlers; using OrchardCore.Users.Models; using OrchardCore.Users.TimeZone.Drivers; +using OrchardCore.Users.TimeZone.Handlers; using OrchardCore.Users.TimeZone.Services; namespace OrchardCore.Users.TimeZone; @@ -13,10 +14,9 @@ public sealed class Startup : StartupBase { public override void ConfigureServices(IServiceCollection services) { + services.AddScoped(); + services.AddScoped(); services.AddScoped(); - services.AddScoped(); - services.AddScoped(sp => sp.GetRequiredService()); - services.AddScoped(sp => sp.GetRequiredService()); services.AddDisplayDriver(); } } From bb7359e31b035ff1b3e049cf568206106592a24e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:01:20 -0800 Subject: [PATCH 2/5] Fix sitemap disposed stream (#17078) Co-authored-by: Mike Alhayek --- .../OrchardCore.Sitemaps/Controllers/SitemapController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapController.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapController.cs index fb2b84d8bc2..bd00efea6f4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapController.cs @@ -86,7 +86,7 @@ public async Task Index(string sitemapId, CancellationToken cance document.Declaration = new XDeclaration("1.0", "utf-8", null); - using var stream = MemoryStreamFactory.GetStream(); + var stream = MemoryStreamFactory.GetStream(); await document.SaveAsync(stream, SaveOptions.None, cancellationToken); if (stream.Length >= ErrorLength) From 1682bdb58b6031cff43502dc0f650d00a3c0c311 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 27 Nov 2024 20:50:25 -0800 Subject: [PATCH 3/5] Obsolete SiteOwner claim and fix OpenId (#17089) --- .../Services/RoleClaimsProvider.cs | 14 ++++++++------ .../OrchardCore.Settings.csproj | 1 + .../Services/SuperUserHandler.cs | 9 +++++++-- .../OrchardCore.Settings/Startup.cs | 5 ++++- .../OrchardCore.Users/Liquid/UserFilters.cs | 7 ++++--- .../Security/StandardClaims.cs | 3 ++- .../ServiceCollectionExtensions.cs | 5 ++++- 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Roles/Services/RoleClaimsProvider.cs b/src/OrchardCore.Modules/OrchardCore.Roles/Services/RoleClaimsProvider.cs index d22c754b1c9..ec876106a96 100644 --- a/src/OrchardCore.Modules/OrchardCore.Roles/Services/RoleClaimsProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Roles/Services/RoleClaimsProvider.cs @@ -33,17 +33,19 @@ public async Task GenerateAsync(IUser user, ClaimsIdentity claims) return; } + var roleNames = await _userManager.GetRolesAsync(user); + var isAdministrator = false; - if (await _userManager.IsInRoleAsync(user, await _systemRoleNameProvider.GetAdminRoleAsync())) + foreach (var roleName in roleNames) { - claims.AddClaim(StandardClaims.SiteOwner); - - isAdministrator = true; + if (await _systemRoleNameProvider.IsAdminRoleAsync(roleName)) + { + isAdministrator = true; + break; + } } - var roleNames = await _userManager.GetRolesAsync(user); - foreach (var roleName in roleNames) { claims.AddClaim(new Claim(_identityOptions.ClaimsIdentity.RoleClaimType, roleName)); diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/OrchardCore.Settings.csproj b/src/OrchardCore.Modules/OrchardCore.Settings/OrchardCore.Settings.csproj index 852763a82ec..badc81bec68 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/OrchardCore.Settings.csproj +++ b/src/OrchardCore.Modules/OrchardCore.Settings/OrchardCore.Settings.csproj @@ -23,6 +23,7 @@ + diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/Services/SuperUserHandler.cs b/src/OrchardCore.Modules/OrchardCore.Settings/Services/SuperUserHandler.cs index 75b75bc03da..f6c9c37c67b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/Services/SuperUserHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/Services/SuperUserHandler.cs @@ -1,5 +1,6 @@ using System.Security.Claims; using Microsoft.AspNetCore.Authorization; +using OrchardCore.Roles; using OrchardCore.Security; namespace OrchardCore.Settings.Services; @@ -10,10 +11,14 @@ namespace OrchardCore.Settings.Services; public class SuperUserHandler : IAuthorizationHandler { private readonly ISiteService _siteService; + private readonly ISystemRoleNameProvider _systemRoleNameProvider; - public SuperUserHandler(ISiteService siteService) + public SuperUserHandler( + ISiteService siteService, + ISystemRoleNameProvider systemRoleNameProvider) { _siteService = siteService; + _systemRoleNameProvider = systemRoleNameProvider; } public async Task HandleAsync(AuthorizationHandlerContext context) @@ -25,7 +30,7 @@ public async Task HandleAsync(AuthorizationHandlerContext context) return; } - if (user.HasClaim(StandardClaims.SiteOwner.Type, StandardClaims.SiteOwner.Value)) + if (user.IsInRole(await _systemRoleNameProvider.GetAdminRoleAsync())) { SucceedAllRequirements(context); diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Settings/Startup.cs index 297c05eb43f..720fe1b163e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/Startup.cs @@ -11,6 +11,7 @@ using OrchardCore.Recipes; using OrchardCore.Recipes.Services; using OrchardCore.ResourceManagement; +using OrchardCore.Roles; using OrchardCore.Security.Permissions; using OrchardCore.Settings.Deployment; using OrchardCore.Settings.Drivers; @@ -65,7 +66,9 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddPermissionProvider(); - services.AddScoped(); + + services.AddRolesCoreServices() + .AddScoped(); services.AddRecipeExecutionStep(); services.AddSingleton(); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Liquid/UserFilters.cs b/src/OrchardCore.Modules/OrchardCore.Users/Liquid/UserFilters.cs index b8ce03755cd..bfda40a6209 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Liquid/UserFilters.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Liquid/UserFilters.cs @@ -5,19 +5,20 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using OrchardCore.Liquid; -using OrchardCore.Security; +using OrchardCore.Roles; using OrchardCore.Security.Permissions; namespace OrchardCore.Users.Liquid; public static class UserFilters { - public static ValueTask HasClaim(FluidValue input, FilterArguments arguments, TemplateContext ctx) + public static async ValueTask HasClaim(FluidValue input, FilterArguments arguments, TemplateContext ctx) { if (input.ToObjectValue() is LiquidUserAccessor) { var context = (LiquidTemplateContext)ctx; var httpContextAccessor = context.Services.GetRequiredService(); + var systemRoleNameProvider = context.Services.GetRequiredService(); var user = httpContextAccessor.HttpContext?.User; if (user != null) @@ -45,7 +46,7 @@ public static ValueTask HasClaim(FluidValue input, FilterArguments a // {% assign isAuthorized = User | has_permission: "AccessAdminPanel" %} // ``` if (string.Equals(claimType, Permission.ClaimType, StringComparison.OrdinalIgnoreCase) && - user.HasClaim(StandardClaims.SiteOwner.Type, StandardClaims.SiteOwner.Value)) + user.IsInRole(await systemRoleNameProvider.GetAdminRoleAsync())) { var logger = context.Services.GetRequiredService>(); diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Security/StandardClaims.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Security/StandardClaims.cs index 4f87abf054b..dd6fbfcfa44 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Security/StandardClaims.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Security/StandardClaims.cs @@ -1,4 +1,4 @@ -using System.Security.Claims; +using System.Security.Claims; namespace OrchardCore.Security; @@ -7,5 +7,6 @@ public static class StandardClaims /// /// This claim is assigned by the system during the login process if the user belongs to the Administrator role. /// + [Obsolete("This claim is obsolete and will be removed in the next major version.")] public static readonly Claim SiteOwner = new("SiteOwner", "true"); } diff --git a/src/OrchardCore/OrchardCore.Roles.Core/ServiceCollectionExtensions.cs b/src/OrchardCore/OrchardCore.Roles.Core/ServiceCollectionExtensions.cs index 2cc52cc7edd..f27ce780e99 100644 --- a/src/OrchardCore/OrchardCore.Roles.Core/ServiceCollectionExtensions.cs +++ b/src/OrchardCore/OrchardCore.Roles.Core/ServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; namespace OrchardCore.Roles; @@ -6,6 +7,8 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddRolesCoreServices(this IServiceCollection services) { - return services.AddSingleton(); + services.TryAddSingleton(); + + return services; } } From f748833fb416c079d9ad5d927834e9ac6e15ae66 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 27 Nov 2024 20:51:13 -0800 Subject: [PATCH 4/5] Release 2.1.2 (#17079) --- README.md | 2 +- mkdocs.yml | 1 + src/docs/README.md | 2 +- src/docs/getting-started/templates/README.md | 8 ++++---- src/docs/guides/add-admin-menu/README.md | 6 +++--- src/docs/guides/create-blazor-cms/README.md | 2 +- src/docs/guides/create-cms-application/README.md | 2 +- src/docs/guides/create-modular-application-mvc/README.md | 2 +- src/docs/guides/decoupled-cms/README.md | 2 +- src/docs/releases/2.1.1.md | 2 +- src/docs/releases/2.1.2.md | 5 +++++ 11 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 src/docs/releases/2.1.2.md diff --git a/README.md b/README.md index a7fff729360..40e9009b0da 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Nightly (`main`): [![Build status](https://github.com/OrchardCMS/OrchardCore/actions/workflows/preview_ci.yml/badge.svg)](https://github.com/OrchardCMS/OrchardCore/actions?query=workflow%3A%22Preview+-+CI%22) [![Cloudsmith](https://api-prd.cloudsmith.io/badges/version/orchardcore/preview/nuget/OrchardCore.Application.Cms.Targets/latest/x/?render=true&badge_token=gAAAAABey9hKFD_C-ZIpLvayS3HDsIjIorQluDs53KjIdlxoDz6Ntt1TzvMNJp7a_UWvQbsfN5nS7_0IbxCyqHZsjhmZP6cBkKforo-NqwrH5-E6QCrJ3D8%3D)](https://cloudsmith.io/~orchardcore/repos/preview/packages/detail/nuget/OrchardCore.Application.Cms.Targets/latest/) -## Project Status: v2.1.1 +## Project Status: v2.1.2 The software is production-ready, and capable of serving large mission-critical applications as well, and we're not aware of any fundamental bugs or missing features we deem crucial. Orchard Core continues to evolve, with each version bringing new improvements, and keeping up with the cutting-edge of .NET. diff --git a/mkdocs.yml b/mkdocs.yml index a6f5ab6f7c0..6c76174cdbd 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -273,6 +273,7 @@ nav: - Owners: resources/owners/README.md - Workshops: resources/workshops/README.md - Releases: + - 2.1.2: releases/2.1.2.md - 2.1.1: releases/2.1.1.md - 2.1.0: releases/2.1.0.md - 2.0.2: releases/2.0.2.md diff --git a/src/docs/README.md b/src/docs/README.md index bc6b84d5ec8..510a0d5d7a8 100644 --- a/src/docs/README.md +++ b/src/docs/README.md @@ -58,7 +58,7 @@ Orchard Core CMS supports all major site building strategies: ## Status -The latest released version of Orchard Core is `2.1.1`. The release notes can be found under [Releases](releases/2.1.1.md). +The latest released version of Orchard Core is `2.1.2`. The release notes can be found under [Releases](releases/2.1.2.md). ## Getting Started diff --git a/src/docs/getting-started/templates/README.md b/src/docs/getting-started/templates/README.md index 7e4bbc485f6..e4fab2dd70a 100644 --- a/src/docs/getting-started/templates/README.md +++ b/src/docs/getting-started/templates/README.md @@ -9,13 +9,13 @@ More information about `dotnet new` can be found at - + ``` diff --git a/src/docs/releases/2.1.1.md b/src/docs/releases/2.1.1.md index 174f7ad47bc..1d673e91fdc 100644 --- a/src/docs/releases/2.1.1.md +++ b/src/docs/releases/2.1.1.md @@ -1,5 +1,5 @@ # Orchard Core 2.1.1 -Release date: November 15, 2024 +Release date: November 25, 2024 This release includes critical bug fixes related to security vulnerabilities. diff --git a/src/docs/releases/2.1.2.md b/src/docs/releases/2.1.2.md new file mode 100644 index 00000000000..873cc93da7a --- /dev/null +++ b/src/docs/releases/2.1.2.md @@ -0,0 +1,5 @@ +# Orchard Core 2.1.2 + +Release date: November 27, 2024 + +This release includes critical bug fixes related to stability. From d016259d41e77a7ee9a946e1dc5bee23ef5254cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Wed, 27 Nov 2024 21:43:40 -0800 Subject: [PATCH 5/5] Replace unnecesary calls to SaveChangesAsync by FlushAsync (#17084) --- .editorconfig | 1 + src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs | 2 +- .../OrchardCore.Title/Migrations.cs | 2 +- .../YesSql/Stores/OpenIdApplicationStore.cs | 4 ++-- .../YesSql/Stores/OpenIdAuthorizationStore.cs | 8 ++++---- .../YesSql/Stores/OpenIdScopeStore.cs | 6 +++--- .../YesSql/Stores/OpenIdTokenStore.cs | 10 +++++----- .../OrchardCore.Users.Core/Services/UserStore.cs | 7 +++---- .../Apis/GraphQL/ContentItemsFieldTypeTests.cs | 2 -- .../Decriptors/DefaultShapeTableManagerTests.cs | 2 -- 10 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.editorconfig b/.editorconfig index bbb5af24d58..1948bc0d730 100644 --- a/.editorconfig +++ b/.editorconfig @@ -83,6 +83,7 @@ dotnet_diagnostic.IDE0130.severity = silent # Na dotnet_style_prefer_conditional_expression_over_assignment = silent # Remove redundant equality, e.g. Disabled == false dotnet_diagnostic.CA2263.severity = warning # Prefer generic overload when type is known +dotnet_diagnostic.CA1816.severity = none # Dispose methods should call SuppressFinalize # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true diff --git a/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs index bcd352f7416..7513f0f12b9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs @@ -91,7 +91,7 @@ public async Task UpdateFrom3Async() lastDocumentId = contentItemVersion.Id; } - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } static bool UpdateBody(JsonNode content) diff --git a/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs index 2d5e1b73d57..e2cbf1b5e6b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs @@ -68,7 +68,7 @@ public async Task UpdateFrom1() lastDocumentId = contentItemVersion.Id; } - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } static bool UpdateTitle(JsonNode content) diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdApplicationStore.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdApplicationStore.cs index f1dabda01ad..02ab4d0e5c2 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdApplicationStore.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdApplicationStore.cs @@ -50,7 +50,7 @@ public virtual async ValueTask CreateAsync(TApplication application, Cancellatio cancellationToken.ThrowIfCancellationRequested(); await _session.SaveAsync(application, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -61,7 +61,7 @@ public virtual async ValueTask DeleteAsync(TApplication application, Cancellatio cancellationToken.ThrowIfCancellationRequested(); _session.Delete(application, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdAuthorizationStore.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdAuthorizationStore.cs index d48974c4f7d..040915ef6be 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdAuthorizationStore.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdAuthorizationStore.cs @@ -44,7 +44,7 @@ public virtual async ValueTask CreateAsync(TAuthorization authorization, Cancell cancellationToken.ThrowIfCancellationRequested(); await _session.SaveAsync(authorization, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -55,7 +55,7 @@ public virtual async ValueTask DeleteAsync(TAuthorization authorization, Cancell cancellationToken.ThrowIfCancellationRequested(); _session.Delete(authorization, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -319,7 +319,7 @@ public virtual async ValueTask PruneAsync(DateTimeOffset threshold, Cancel try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (Exception exception) { @@ -440,7 +440,7 @@ public virtual async ValueTask UpdateAsync(TAuthorization authorization, Cancell try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (ConcurrencyException exception) { diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdScopeStore.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdScopeStore.cs index 2173cf8f254..02893d1e8de 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdScopeStore.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdScopeStore.cs @@ -43,7 +43,7 @@ public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cance cancellationToken.ThrowIfCancellationRequested(); await _session.SaveAsync(scope, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -54,7 +54,7 @@ public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cance cancellationToken.ThrowIfCancellationRequested(); _session.Delete(scope, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -326,7 +326,7 @@ public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cance try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (ConcurrencyException exception) { diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs index eaa3c46165d..8c09a9b6db4 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs @@ -44,7 +44,7 @@ public virtual async ValueTask CreateAsync(TToken token, CancellationToken cance cancellationToken.ThrowIfCancellationRequested(); await _session.SaveAsync(token, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -55,7 +55,7 @@ public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cance cancellationToken.ThrowIfCancellationRequested(); _session.Delete(token, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -354,7 +354,7 @@ public virtual async ValueTask PruneAsync(DateTimeOffset threshold, Cancel try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (Exception exception) { @@ -399,7 +399,7 @@ public virtual async ValueTask RevokeByAuthorizationIdAsync(string identif await _session.SaveAsync(token, checkConcurrency: false, collection: OpenIdCollection); } - await _session.SaveChangesAsync(); + await _session.FlushAsync(); return tokens.Count; } @@ -546,7 +546,7 @@ public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cance try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (ConcurrencyException exception) { diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs index 741ca54072a..5ed624343ce 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs @@ -58,7 +58,6 @@ public UserStore(ISession session, public void Dispose() { - GC.SuppressFinalize(this); } public string NormalizeKey(string key) @@ -111,7 +110,7 @@ public async Task CreateAsync(IUser user, CancellationToken canc } await _session.SaveAsync(user); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); await Handlers.InvokeAsync((handler, context) => handler.CreatedAsync(context), context, _logger); } catch (Exception e) @@ -139,7 +138,7 @@ public async Task DeleteAsync(IUser user, CancellationToken canc } _session.Delete(user); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); await Handlers.InvokeAsync((handler, context) => handler.DeletedAsync(context), context, _logger); } catch (Exception e) @@ -232,7 +231,7 @@ public async Task UpdateAsync(IUser user, CancellationToken canc } await _session.SaveAsync(user); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); await Handlers.InvokeAsync((handler, context) => handler.UpdatedAsync(context), context, _logger); } catch (Exception e) diff --git a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs index a0da2bb775d..141aa7400a3 100644 --- a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs +++ b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs @@ -648,9 +648,7 @@ public void Build() _inner = _services.BuildServiceProvider(); } -#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize public void Dispose() -#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize { (_inner as IDisposable)?.Dispose(); } diff --git a/test/OrchardCore.Tests/DisplayManagement/Decriptors/DefaultShapeTableManagerTests.cs b/test/OrchardCore.Tests/DisplayManagement/Decriptors/DefaultShapeTableManagerTests.cs index 2d4e5a20cfa..68f881118c3 100644 --- a/test/OrchardCore.Tests/DisplayManagement/Decriptors/DefaultShapeTableManagerTests.cs +++ b/test/OrchardCore.Tests/DisplayManagement/Decriptors/DefaultShapeTableManagerTests.cs @@ -495,9 +495,7 @@ public async Task DerivedThemesCanOverrideBaseThemeShapeBindings() Assert.Equal("DerivedTheme", table.Descriptors["OverriddenShape"].BindingSource); } -#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize public void Dispose() -#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize { (_serviceProvider as IDisposable)?.Dispose(); }