在 abp 框架中隐藏自定义设置菜单

问题描述 投票:0回答:1

我在设置下有一个自己创建的菜单项,只有在用户有权限的情况下才会显示。 screenshot

在 SettingComponentContributor 中,我有以下代码:

public async Task<bool> CheckPermissionsAsync(SettingComponentCreationContext context)
 {
            var auth = context.ServiceProvider.GetRequiredService<IAuthorizationService>();            
            return await auth.IsGrantedAsync(Permissions.CustomSettings);
 }
public Task ConfigureAsync(SettingComponentCreationContext context)
{
            var l = context.ServiceProvider.GetService<IStringLocalizer<...Resource>>();

            context.Groups.Add(new SettingComponentGroup("Settings", l["Settings"], typeof(CustomSettingComponent)));
            return Task.CompletedTask;
}
webassembly abp
1个回答
0
投票

您应该使用

CheckPermissionsAsync
方法进行权限检查,然后添加您的设置菜单项:

因此,您可以按如下方式更新

ConfigureAsync
方法:

public Task ConfigureAsync(SettingComponentCreationContext context)
{
    if (!await CheckPermissionsAsync(context))
    {
      return;
    }

    var l = context.ServiceProvider.GetService<IStringLocalizer<...Resource>>();

    context.Groups.Add(new SettingComponentGroup("Settings", l["Settings"], typeof(CustomSettingComponent)));
    return Task.CompletedTask;
}

查看示例用法:https://github.com/abpframework/abp/blob/dev/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Settings/FeatureSettingManagementComponentContributor.cs#L13-L28

© www.soinside.com 2019 - 2024. All rights reserved.