From 03ca16624f15d5fc5a9feee4fa1136ad9674484a Mon Sep 17 00:00:00 2001 From: Keith Raven Date: Wed, 17 Apr 2024 22:09:47 +0100 Subject: [PATCH 1/5] Clear user time zone cache entry on update or delete --- .../Handlers/TimeZoneUserEventHandler.cs | 27 +++++++++++++++++++ .../OrchardCore.Users/TimeZone/Startup.cs | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs new file mode 100644 index 00000000000..252ff4419be --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; +using OrchardCore.Users.Handlers; +using OrchardCore.Users.TimeZone.Services; + +namespace OrchardCore.Users.TimeZone.Handlers; +internal class TimeZoneUserEventHandler : UserEventHandlerBase +{ + private readonly UserTimeZoneService _userTimeZoneService; + + public TimeZoneUserEventHandler(UserTimeZoneService userTimeZoneService) => _userTimeZoneService = userTimeZoneService; + + public override async Task DeletedAsync(UserDeleteContext context) + { + await _userTimeZoneService.UpdateUserTimeZoneAsync(context.User); + } + + public override async Task UpdatedAsync(UserUpdateContext context) + { + await _userTimeZoneService.UpdateUserTimeZoneAsync(context.User); + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs index 4f518d3700d..925a4a0fc24 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs @@ -1,8 +1,10 @@ using Microsoft.Extensions.DependencyInjection; using OrchardCore.DisplayManagement.Handlers; using OrchardCore.Modules; +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 @@ -15,6 +17,7 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddSingleton(); services.AddScoped, UserTimeZoneDisplayDriver>(); + services.AddScoped(); } } } From 42887581b2ad729ab451bc18ac029f0a891f2ece Mon Sep 17 00:00:00 2001 From: Keith Raven Date: Thu, 18 Apr 2024 22:59:20 +0100 Subject: [PATCH 2/5] Remove line now covered by handler --- .../TimeZone/Drivers/UserTimeZoneDisplayDriver.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs index f4a0436697c..d5f99d8bc02 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs @@ -43,9 +43,6 @@ BuildEditorContext context if (await context.Updater.TryUpdateModelAsync(model, Prefix)) { userTimeZone.TimeZoneId = model.TimeZoneId; - - // Remove the cache entry, don't update it, as the form might still fail validation for other reasons. - await _userTimeZoneService.UpdateUserTimeZoneAsync(user); } return await EditAsync(userTimeZone, context); From 1d3b6f013d648081808d1e3e1fe43cc83ccb3ea5 Mon Sep 17 00:00:00 2001 From: Keith Raven Date: Sat, 20 Apr 2024 08:52:02 +0100 Subject: [PATCH 3/5] remove redundant cache clear --- .../TimeZone/Drivers/UserTimeZoneDisplayDriver.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs index c89d5d592dd..c1295275809 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs @@ -43,9 +43,6 @@ UpdateEditorContext context await context.Updater.TryUpdateModelAsync(model, Prefix); userTimeZone.TimeZoneId = model.TimeZoneId; - // Remove the cache entry, don't update it, as the form might still fail validation for other reasons. - await _userTimeZoneService.UpdateUserTimeZoneAsync(user); - return await EditAsync(userTimeZone, context); } } From 613511b4b702dcc2eb4c489e30f42975076f01b9 Mon Sep 17 00:00:00 2001 From: Keith Raven Date: Sat, 20 Apr 2024 09:10:52 +0100 Subject: [PATCH 4/5] change to public --- .../TimeZone/Handlers/TimeZoneUserEventHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs index 252ff4419be..d5cb978d7c5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs @@ -9,7 +9,7 @@ using OrchardCore.Users.TimeZone.Services; namespace OrchardCore.Users.TimeZone.Handlers; -internal class TimeZoneUserEventHandler : UserEventHandlerBase +public class TimeZoneUserEventHandler : UserEventHandlerBase { private readonly UserTimeZoneService _userTimeZoneService; From 403ea828aff15d16dd908f246dee40a92a944599 Mon Sep 17 00:00:00 2001 From: Keith Raven Date: Sat, 20 Apr 2024 09:11:26 +0100 Subject: [PATCH 5/5] changed format --- .../TimeZone/Handlers/TimeZoneUserEventHandler.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs index d5cb978d7c5..81d44bf8040 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs @@ -15,13 +15,7 @@ public class TimeZoneUserEventHandler : UserEventHandlerBase public TimeZoneUserEventHandler(UserTimeZoneService userTimeZoneService) => _userTimeZoneService = userTimeZoneService; - public override async Task DeletedAsync(UserDeleteContext context) - { - await _userTimeZoneService.UpdateUserTimeZoneAsync(context.User); - } + public override async Task DeletedAsync(UserDeleteContext context) => await _userTimeZoneService.UpdateUserTimeZoneAsync(context.User); - public override async Task UpdatedAsync(UserUpdateContext context) - { - await _userTimeZoneService.UpdateUserTimeZoneAsync(context.User); - } + public override async Task UpdatedAsync(UserUpdateContext context) => await _userTimeZoneService.UpdateUserTimeZoneAsync(context.User); }