Skip to content

Commit

Permalink
Merge pull request #105 from EasyAbp/hide-default-group
Browse files Browse the repository at this point in the history
Add an option to allow hiding the default group
  • Loading branch information
gdlcf88 authored Jan 19, 2024
2 parents 1f933a9 + 2ac4027 commit 93c4e0e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/EasyAbp.Abp.SettingUi.Application/SettingUiAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +25,7 @@ namespace EasyAbp.Abp.SettingUi
{
public class SettingUiAppService : ApplicationService, ISettingUiAppService
{
private readonly AbpSettingUiOptions _options;
private readonly IStringLocalizer<SettingUiResource> _localizer;
private readonly IStringLocalizerFactory _factory;
private readonly IVirtualFileProvider _fileProvider;
Expand All @@ -31,14 +34,17 @@ public class SettingUiAppService : ApplicationService, ISettingUiAppService
private readonly ISettingManager _settingManager;
private readonly IPermissionDefinitionManager _permissionDefinitionManager;

public SettingUiAppService(IStringLocalizer<SettingUiResource> localizer,
public SettingUiAppService(
IOptions<AbpSettingUiOptions> options,
IStringLocalizer<SettingUiResource> localizer,
IStringLocalizerFactory factory,
IVirtualFileProvider fileProvider,
IJsonSerializer jsonSerializer,
ISettingDefinitionManager settingDefinitionManager,
ISettingManager settingManager,
IPermissionDefinitionManager permissionDefinitionManager)
{
_options = options.Value;
_localizer = localizer;
_factory = factory;
_fileProvider = fileProvider;
Expand Down Expand Up @@ -107,6 +113,16 @@ public virtual async Task<List<SettingGroup>> 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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace EasyAbp.Abp.SettingUi.Options;

public class AbpSettingUiOptions
{
/// <summary>
/// If true, the default "Others" setting group (group1) will be unavailable, only grouped items can be used.
/// </summary>
public bool DisableDefaultGroup { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +20,9 @@ public class SettingDefinitionGroupAppService_Tests : SettingUiApplicationTestBa
private readonly ITestOutputHelper _output;
private readonly ISettingUiAppService _service;
private ISettingManager _settingManager;
private IOptions<AbpSettingUiOptions> _options;

private readonly AbpSettingUiOptions _optionsValue = new();

public SettingDefinitionGroupAppService_Tests(ITestOutputHelper output)
{
Expand Down Expand Up @@ -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<AbpSettingUiOptions>
_options = Substitute.For<IOptions<AbpSettingUiOptions>>();
_options.Value.Returns(_optionsValue);
services.AddSingleton(_options);
}

[Fact]
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 93c4e0e

Please sign in to comment.