From e869f4d435f91366dbe9ea57ca301fd5b4670a8e Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 19 Mar 2026 11:14:49 +0800 Subject: [PATCH 1/2] feat: Add my time zone settings --- .../ITimeZoneSettingsAppService.cs | 6 ++++ .../IUserTimeZoneSettingsAppService.cs | 9 ++++++ .../TimeZoneSettingsAppService.cs | 32 ++++++++++++++++--- .../TimeZoneSettingsController.cs | 19 +++++++++-- 4 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/ITimeZoneSettingsAppService.cs create mode 100644 aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/IUserTimeZoneSettingsAppService.cs diff --git a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/ITimeZoneSettingsAppService.cs b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/ITimeZoneSettingsAppService.cs new file mode 100644 index 000000000..246e6774e --- /dev/null +++ b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/ITimeZoneSettingsAppService.cs @@ -0,0 +1,6 @@ +using IVoloTimeZoneSettingsAppService = Volo.Abp.SettingManagement.ITimeZoneSettingsAppService; + +namespace LINGYUN.Abp.SettingManagement; +public interface ITimeZoneSettingsAppService : IVoloTimeZoneSettingsAppService, IUserTimeZoneSettingsAppService +{ +} diff --git a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/IUserTimeZoneSettingsAppService.cs b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/IUserTimeZoneSettingsAppService.cs new file mode 100644 index 000000000..0890937c0 --- /dev/null +++ b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/IUserTimeZoneSettingsAppService.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace LINGYUN.Abp.SettingManagement; +public interface IUserTimeZoneSettingsAppService +{ + Task GetMyTimezoneAsync(); + + Task SetMyTimezoneAsync(string timezone); +} diff --git a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs index c2ed056b5..b33d06646 100644 --- a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs +++ b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs @@ -3,19 +3,25 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp; +using Volo.Abp.DependencyInjection; using Volo.Abp.MultiTenancy; using Volo.Abp.SettingManagement; using Volo.Abp.Timing; +using IVoloTimeZoneSettingsAppService = Volo.Abp.SettingManagement.ITimeZoneSettingsAppService; namespace LINGYUN.Abp.SettingManagement; -[Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)] +[Authorize] +[ExposeServices( + typeof(ITimeZoneSettingsAppService), + typeof(IUserTimeZoneSettingsAppService), + typeof(IVoloTimeZoneSettingsAppService))] public class TimeZoneSettingsAppService : SettingManagementAppServiceBase, ITimeZoneSettingsAppService { protected ISettingManager SettingManager { get; } protected ITimezoneProvider TimezoneProvider { get; } - private const string UnspecifiedTimeZone = "Unspecified"; + internal const string UnspecifiedTimeZone = "Unspecified"; public TimeZoneSettingsAppService(ISettingManager settingManager, ITimezoneProvider timezoneProvider) { @@ -23,7 +29,24 @@ public class TimeZoneSettingsAppService : SettingManagementAppServiceBase, ITime TimezoneProvider = timezoneProvider; } - public virtual async Task GetAsync() + public async virtual Task GetMyTimezoneAsync() + { + return await SettingManager.GetOrNullForCurrentUserAsync(TimingSettingNames.TimeZone) + ?? UnspecifiedTimeZone; + } + + public async virtual Task SetMyTimezoneAsync(string timezone) + { + if (timezone.Equals(UnspecifiedTimeZone, StringComparison.OrdinalIgnoreCase)) + { + timezone = null; + } + + await SettingManager.SetForCurrentUserAsync(TimingSettingNames.TimeZone, timezone); + } + + [Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)] + public async virtual Task GetAsync() { var timezone = CurrentTenant.GetMultiTenancySide() == MultiTenancySides.Host ? await SettingManager.GetOrNullGlobalAsync(TimingSettingNames.TimeZone) @@ -48,7 +71,8 @@ public class TimeZoneSettingsAppService : SettingManagementAppServiceBase, ITime return Task.FromResult(timezones); } - public virtual async Task UpdateAsync(string timezone) + [Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)] + public async virtual Task UpdateAsync(string timezone) { if (timezone.Equals(UnspecifiedTimeZone, StringComparison.OrdinalIgnoreCase)) { diff --git a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.HttpApi/LINGYUN/Abp/SettingManagement/TimeZoneSettingsController.cs b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.HttpApi/LINGYUN/Abp/SettingManagement/TimeZoneSettingsController.cs index 724563df9..db261f6b6 100644 --- a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.HttpApi/LINGYUN/Abp/SettingManagement/TimeZoneSettingsController.cs +++ b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.HttpApi/LINGYUN/Abp/SettingManagement/TimeZoneSettingsController.cs @@ -4,14 +4,13 @@ using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.SettingManagement; namespace LINGYUN.Abp.SettingManagement; [RemoteService(Name = AbpSettingManagementRemoteServiceConsts.RemoteServiceName)] [Area(AbpSettingManagementRemoteServiceConsts.ModuleName)] [Route("api/setting-management/timezone")] -[Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)] +[Authorize] public class TimeZoneSettingsController : AbpControllerBase, ITimeZoneSettingsAppService { private readonly ITimeZoneSettingsAppService _service; @@ -22,11 +21,19 @@ public class TimeZoneSettingsController : AbpControllerBase, ITimeZoneSettingsAp } [HttpGet] + [Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)] public virtual Task GetAsync() { return _service.GetAsync(); } + [HttpGet] + [Route("my-timezone")] + public virtual Task GetMyTimezoneAsync() + { + return _service.GetMyTimezoneAsync(); + } + [HttpGet] [Route("timezones")] public virtual Task> GetTimezonesAsync() @@ -35,6 +42,14 @@ public class TimeZoneSettingsController : AbpControllerBase, ITimeZoneSettingsAp } [HttpPost] + [Route("my-timezone")] + public virtual Task SetMyTimezoneAsync(string timezone) + { + return _service.SetMyTimezoneAsync(timezone); + } + + [HttpPost] + [Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)] public virtual Task UpdateAsync(string timezone) { return _service.UpdateAsync(timezone); From f49060bdff467674737477d3738bea55f3c89f01 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 19 Mar 2026 11:16:08 +0800 Subject: [PATCH 2/2] feat: Modify the visibility of private constants --- .../LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs index b33d06646..e2ce4dbc4 100644 --- a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs +++ b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs @@ -21,7 +21,7 @@ public class TimeZoneSettingsAppService : SettingManagementAppServiceBase, ITime protected ISettingManager SettingManager { get; } protected ITimezoneProvider TimezoneProvider { get; } - internal const string UnspecifiedTimeZone = "Unspecified"; + private const string UnspecifiedTimeZone = "Unspecified"; public TimeZoneSettingsAppService(ISettingManager settingManager, ITimezoneProvider timezoneProvider) {