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..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 @@ -3,13 +3,19 @@ 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; } @@ -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);