diff --git a/src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs b/src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs index fb4c853..fe6673f 100644 --- a/src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs +++ b/src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs @@ -176,8 +176,9 @@ protected virtual Task SetSettingAsync(SettingDefinition setting, [CanBeNull] st return _settingManager.SetGlobalAsync(setting.Name, value); } - //Default - return _settingManager.SetForCurrentTenantAsync(setting.Name, value); + return ShouldManageAsGlobal(setting) + ? _settingManager.SetGlobalAsync(setting.Name, value) + : _settingManager.SetForCurrentTenantAsync(setting.Name, value); } protected virtual IDictionary> GetMergedSettingPropertiesAsync() @@ -277,10 +278,7 @@ protected virtual async Task CreateSettingInfoAsync(SettingDefiniti description = settingDefinition.Description.Localize(_factory); } - /* Hide default/global value for tenants if the setting item is encrypted. */ - var value = settingDefinition.IsEncrypted && CurrentTenant.IsAvailable - ? await _settingManager.GetOrNullForCurrentTenantAsync(name, false) - : await SettingProvider.GetOrNullAsync(name); + var value = await GetSettingValueAsync(settingDefinition); var si = new SettingInfo { @@ -299,5 +297,26 @@ protected virtual async Task CreateSettingInfoAsync(SettingDefiniti return si; } + + protected virtual async Task GetSettingValueAsync(SettingDefinition settingDefinition) + { + /* Hide default/global value for tenants if the setting item is encrypted. */ + if (settingDefinition.IsEncrypted && CurrentTenant.IsAvailable) + { + return await _settingManager.GetOrNullForCurrentTenantAsync(settingDefinition.Name, false); + } + + return ShouldManageAsGlobal(settingDefinition) + ? await _settingManager.GetOrNullGlobalAsync(settingDefinition.Name) + : await SettingProvider.GetOrNullAsync(settingDefinition.Name); + } + + protected virtual bool ShouldManageAsGlobal(SettingDefinition settingDefinition) + { + // todo: settingDefinition.Providers.Count != 0 can be improved. + return !CurrentTenant.IsAvailable && + _options.ManageGlobalSettingsOnHostSide && + settingDefinition.Providers.Count == 0; + } } } \ No newline at end of file diff --git a/src/EasyAbp.Abp.SettingUi.Domain/Options/AbpSettingUiOptions.cs b/src/EasyAbp.Abp.SettingUi.Domain/Options/AbpSettingUiOptions.cs index 4b1fd07..4b9643c 100644 --- a/src/EasyAbp.Abp.SettingUi.Domain/Options/AbpSettingUiOptions.cs +++ b/src/EasyAbp.Abp.SettingUi.Domain/Options/AbpSettingUiOptions.cs @@ -6,4 +6,11 @@ public class AbpSettingUiOptions /// If true, the default "Others" setting group (group1) will be unavailable, only grouped items can be used. /// public bool DisableDefaultGroup { get; set; } + + /// + /// If true: + /// 1. On the host side, global setting values will replace host-side setting values for management. + /// 2. If the host setting value is different from the global setting value, it shows and manages the global one. + /// + public bool ManageGlobalSettingsOnHostSide { get; set; } } \ No newline at end of file diff --git a/test/EasyAbp.Abp.SettingUi.Application.Tests/SettingUi/SettingDefinitionGroupAppService_Tests.cs b/test/EasyAbp.Abp.SettingUi.Application.Tests/SettingUi/SettingDefinitionGroupAppService_Tests.cs index 3bb2092..444a597 100644 --- a/test/EasyAbp.Abp.SettingUi.Application.Tests/SettingUi/SettingDefinitionGroupAppService_Tests.cs +++ b/test/EasyAbp.Abp.SettingUi.Application.Tests/SettingUi/SettingDefinitionGroupAppService_Tests.cs @@ -132,6 +132,15 @@ public async Task SettingValues_Should_Be_Set() await _settingManager.Received().SetForCurrentTenantAsync("Test.Setting1", "value1"); await _settingManager.Received().SetForCurrentTenantAsync("Test.Setting2", "value2"); await _settingManager.DidNotReceive().SetForCurrentTenantAsync("RequestToken", "value3"); + + // Act + _optionsValue.ManageGlobalSettingsOnHostSide = true; + await _service.SetSettingValuesAsync(settingValues); + + // Assert + await _settingManager.Received().SetGlobalAsync("Test.Setting1", "value1"); + await _settingManager.Received().SetGlobalAsync("Test.Setting2", "value2"); + await _settingManager.DidNotReceive().SetGlobalAsync("RequestToken", "value3"); } [Fact]