diff --git a/src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs b/src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs index e7caee3..cd2f0ec 100644 --- a/src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs +++ b/src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs @@ -6,9 +6,11 @@ using EasyAbp.Abp.SettingUi.Dto; using EasyAbp.Abp.SettingUi.Extensions; using EasyAbp.Abp.SettingUi.Localization; +using EasyAbp.Abp.SettingUi.Options; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using Volo.Abp.Application.Services; using Volo.Abp.Authorization; using Volo.Abp.Authorization.Permissions; @@ -23,6 +25,7 @@ namespace EasyAbp.Abp.SettingUi { public class SettingUiAppService : ApplicationService, ISettingUiAppService { + private readonly AbpSettingUiOptions _options; private readonly IStringLocalizer _localizer; private readonly IStringLocalizerFactory _factory; private readonly IVirtualFileProvider _fileProvider; @@ -31,7 +34,9 @@ public class SettingUiAppService : ApplicationService, ISettingUiAppService private readonly ISettingManager _settingManager; private readonly IPermissionDefinitionManager _permissionDefinitionManager; - public SettingUiAppService(IStringLocalizer localizer, + public SettingUiAppService( + IOptions options, + IStringLocalizer localizer, IStringLocalizerFactory factory, IVirtualFileProvider fileProvider, IJsonSerializer jsonSerializer, @@ -39,6 +44,7 @@ public SettingUiAppService(IStringLocalizer localizer, ISettingManager settingManager, IPermissionDefinitionManager permissionDefinitionManager) { + _options = options.Value; _localizer = localizer; _factory = factory; _fileProvider = fileProvider; @@ -107,6 +113,16 @@ public virtual async Task> GroupSettingDefinitionsAsync() } } + if (_options.DisableDefaultGroup) + { + // remove the default group + var defaultGroup = groups.Find(x => x.GroupName == SettingUiConst.DefaultGroup); + if (defaultGroup is not null) + { + groups.Remove(defaultGroup); + } + } + return groups; } diff --git a/src/EasyAbp.Abp.SettingUi.Domain/Options/AbpSettingUiOptions.cs b/src/EasyAbp.Abp.SettingUi.Domain/Options/AbpSettingUiOptions.cs new file mode 100644 index 0000000..4b1fd07 --- /dev/null +++ b/src/EasyAbp.Abp.SettingUi.Domain/Options/AbpSettingUiOptions.cs @@ -0,0 +1,9 @@ +namespace EasyAbp.Abp.SettingUi.Options; + +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; } +} \ 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 175d859..3bb2092 100644 --- a/test/EasyAbp.Abp.SettingUi.Application.Tests/SettingUi/SettingDefinitionGroupAppService_Tests.cs +++ b/test/EasyAbp.Abp.SettingUi.Application.Tests/SettingUi/SettingDefinitionGroupAppService_Tests.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using EasyAbp.Abp.SettingUi.Options; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using NSubstitute; using Shouldly; using Volo.Abp.MultiTenancy; @@ -18,6 +20,9 @@ public class SettingDefinitionGroupAppService_Tests : SettingUiApplicationTestBa private readonly ITestOutputHelper _output; private readonly ISettingUiAppService _service; private ISettingManager _settingManager; + private IOptions _options; + + private readonly AbpSettingUiOptions _optionsValue = new(); public SettingDefinitionGroupAppService_Tests(ITestOutputHelper output) { @@ -58,6 +63,11 @@ protected override void AfterAddApplication(IServiceCollection services) settingProvider.GetOrNullAsync("Test.Setting2").Returns(Task.FromResult("2")); settingProvider.GetOrNullAsync("Test.Setting3").Returns(Task.FromResult("3")); services.AddSingleton(settingProvider); + + // Mock IOptions + _options = Substitute.For>(); + _options.Value.Returns(_optionsValue); + services.AddSingleton(_options); } [Fact] @@ -145,5 +155,19 @@ public async Task Should_Hide_Encrypted_Default_Value_For_Tenants() setting3.Value.ShouldBeNullOrEmpty(); } + + [Fact] + public async Task Should_Remove_Ungrouped_Items() + { + var result = await _service.GroupSettingDefinitionsAsync(); + + result.ShouldContain(x => x.GroupName == SettingUiConst.DefaultGroup); + + _optionsValue.DisableDefaultGroup = true; + + result = await _service.GroupSettingDefinitionsAsync(); + + result.ShouldNotContain(x => x.GroupName == SettingUiConst.DefaultGroup); + } } } \ No newline at end of file